(data: string, compact: boolean, layers: number)
| 637 | } |
| 638 | |
| 639 | function testEncodeDecode(data: string, compact: boolean, layers: number) { |
| 640 | const aztec = AztecEncoder.encode( |
| 641 | StringUtils.getBytes(data, ZXingStandardCharsets.ISO_8859_1), |
| 642 | 25, |
| 643 | AztecEncoder.DEFAULT_AZTEC_LAYERS |
| 644 | ); |
| 645 | assertEquals(compact, aztec.isCompact()); |
| 646 | assertEquals(layers, aztec.getLayers()); |
| 647 | const matrix = aztec.getMatrix(); |
| 648 | let r: AztecDetectorResult = new AztecDetectorResult( |
| 649 | matrix, |
| 650 | NO_POINTS, |
| 651 | aztec.isCompact(), |
| 652 | aztec.getCodeWords(), |
| 653 | aztec.getLayers() |
| 654 | ); |
| 655 | let res: DecoderResult = new AztecDecoder().decode(r); |
| 656 | assertEquals(data, res.getText()); |
| 657 | // Check error correction by introducing a few minor errors |
| 658 | const random = getPseudoRandom(); |
| 659 | matrix.flip(random.nextInt(matrix.getWidth()), random.nextInt(2)); |
| 660 | matrix.flip( |
| 661 | random.nextInt(matrix.getWidth()), |
| 662 | matrix.getHeight() - 2 + random.nextInt(2) |
| 663 | ); |
| 664 | matrix.flip(random.nextInt(2), random.nextInt(matrix.getHeight())); |
| 665 | matrix.flip( |
| 666 | matrix.getWidth() - 2 + random.nextInt(2), |
| 667 | random.nextInt(matrix.getHeight()) |
| 668 | ); |
| 669 | r = new AztecDetectorResult( |
| 670 | matrix, |
| 671 | NO_POINTS, |
| 672 | aztec.isCompact(), |
| 673 | aztec.getCodeWords(), |
| 674 | aztec.getLayers() |
| 675 | ); |
| 676 | res = new AztecDecoder().decode(r); |
| 677 | assertEquals(data, res.getText()); |
| 678 | } |
| 679 | |
| 680 | function testWriter( |
| 681 | data: string, |
no test coverage detected