MCPcopy
hub / github.com/zxing-js/library / testEncodeDecode

Function testEncodeDecode

src/test/core/aztec/encoder/EncoderTest.spec.ts:639–678  ·  view source on GitHub ↗
(data: string, compact: boolean, layers: number)

Source from the content-addressed store, hash-verified

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,

Callers 1

Calls 14

assertEqualsFunction · 0.90
getLayersMethod · 0.80
getCodeWordsMethod · 0.80
nextIntMethod · 0.80
getPseudoRandomFunction · 0.70
encodeMethod · 0.65
decodeMethod · 0.65
getBytesMethod · 0.45
isCompactMethod · 0.45
getMatrixMethod · 0.45
getTextMethod · 0.45
flipMethod · 0.45

Tested by

no test coverage detected