import * as assert from 'assert' ; import { QRCodeDecoderErrorCorrectionLevel } from '@zxing/library' ; import { QRCodeDecoderFormatInformation } from '@zxing/library' ; author Sean Owen
  describe ( 'QRCodeDecoderFormatInformation' , ( ) => { const MASKED_TEST_FORMAT_INFO = 0x2BED ; const UNMASKED_TEST_FORMAT_INFO = MASKED_TEST_FORMAT_INFO ^ 0x5412 ; it ( 'testBitsDiffering' , ( ) => { assert . strictEqual ( QRCodeDecoderFormatInformation . numBitsDiffering ( 1 , 1 ) , 0 ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . numBitsDiffering ( 0 , 2 ) , 1 ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . numBitsDiffering ( 1 , 2 ) , 2 ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . numBitsDiffering ( - 1 , 0 ) , 32 ) ; } ) ; it ( 'testDecode' , ( ) => { const expected = QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO , MASKED_TEST_FORMAT_INFO ) ; assert . strictEqual ( null !== expected , true ) ; assert . strictEqual ( expected . getDataMask ( ) , 0x07 ) ; assert . strictEqual ( QRCodeDecoderErrorCorrectionLevel . Q . equals ( expected . getErrorCorrectionLevel ( ) ) , true ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . decodeFormatInformation ( UNMASKED_TEST_FORMAT_INFO , MASKED_TEST_FORMAT_INFO ) . equals ( expected ) , true ) ; } ) ; it ( 'testDecodeWithBitDifference' , ( ) => { const expected = QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO , MASKED_TEST_FORMAT_INFO ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO ^ 0x01 , MASKED_TEST_FORMAT_INFO ^ 0x01 ) . equals ( expected ) , true ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO ^ 0x03 , MASKED_TEST_FORMAT_INFO ^ 0x03 ) . equals ( expected ) , true ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO ^ 0x07 , MASKED_TEST_FORMAT_INFO ^ 0x07 ) . equals ( expected ) , true ) ; assert . strictEqual ( null === QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO ^ 0x0F , MASKED_TEST_FORMAT_INFO ^ 0x0F ) , true ) ; } ) ; it ( 'testDecodeWithMisread' , ( ) => { const expected = QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO , MASKED_TEST_FORMAT_INFO ) ; assert . strictEqual ( QRCodeDecoderFormatInformation . decodeFormatInformation ( MASKED_TEST_FORMAT_INFO ^ 0x03 , MASKED_TEST_FORMAT_INFO ^ 0x0F ) . equals ( expected ) , true ) ; } ) ; } ) ;