import * as assert from 'assert' ; import { QRCodeDecoderErrorCorrectionLevel } from '@zxing/library' ; import { QRCodeMode } from '@zxing/library' ; import { QRCodeVersion } from '@zxing/library' ; import { QRCodeEncoderQRCode } from '@zxing/library' ; import { QRCodeByteMatrix } from '@zxing/library' ; author satorux google author mysen google describe ( 'QRCodeEncoderQRCode' , ( ) => { it ( 'test' , ( ) => { const qrCode = new QRCodeEncoderQRCode ( ) ; qrCode . setMode ( QRCodeMode . BYTE ) ; qrCode . setECLevel ( QRCodeDecoderErrorCorrectionLevel . H ) ; qrCode . setVersion ( QRCodeVersion . getVersionForNumber ( 7 ) ) ; qrCode . setMaskPattern ( 3 ) ; assert . strictEqual ( QRCodeMode . BYTE . equals ( qrCode . getMode ( ) ) , true ) ; assert . strictEqual ( QRCodeDecoderErrorCorrectionLevel . H . equals ( qrCode . getECLevel ( ) ) , true ) ; assert . strictEqual ( qrCode . getVersion ( ) . getVersionNumber ( ) , 7 ) ; assert . strictEqual ( qrCode . getMaskPattern ( ) , 3 ) ; const matrix = new QRCodeByteMatrix ( 45 , 45 ) ; for ( let y = 0 ; y < 45 ; ++ y ) { for ( let x = 0 ; x < 45 ; ++ x ) { matrix . setNumber ( x , y , ( y + x ) % 2 ) ; } } qrCode . setMatrix ( matrix ) ; assert . strictEqual ( matrix . equals ( qrCode . getMatrix ( ) ) , true ) ; } ) ; it ( 'testToString1' , ( ) => { const qrCode = new QRCodeEncoderQRCode ( ) ; const expected = '<<\n' + ' mode: null\n' + ' ecLevel: null\n' + ' version: null\n' + ' maskPattern: -1\n' + ' matrix: null\n' + '>>\n' ; assert . strictEqual ( qrCode . toString ( ) , expected ) ; } ) ; it ( 'testToString2' , ( ) => { const qrCode = new QRCodeEncoderQRCode ( ) ; qrCode . setMode ( QRCodeMode . BYTE ) ; qrCode . setECLevel ( QRCodeDecoderErrorCorrectionLevel . H ) ; qrCode . setVersion ( QRCodeVersion . getVersionForNumber ( 1 ) ) ; qrCode . setMaskPattern ( 3 ) ; const matrix = new QRCodeByteMatrix ( 21 , 21 ) ; for ( let y = 0 ; y < 21 ; ++ y ) { for ( let x = 0 ; x < 21 ; ++ x ) { matrix . setNumber ( x , y , ( y + x ) % 2 ) ; } } qrCode . setMatrix ( matrix ) ; const expected = '<<\n' + ' mode: BYTE\n' + ' ecLevel: H\n' + ' version: 1\n' + ' maskPattern: 3\n' + ' matrix:\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + ' 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n' + ' 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n' + '>>\n' ; assert . strictEqual ( qrCode . toString ( ) , expected ) ; } ) ; it ( 'testIsValidMaskPattern' , ( ) => { assert . strictEqual ( QRCodeEncoderQRCode . isValidMaskPattern ( - 1 ) , false ) ; assert . strictEqual ( QRCodeEncoderQRCode . isValidMaskPattern ( 0 ) , true ) ; assert . strictEqual ( QRCodeEncoderQRCode . isValidMaskPattern ( 7 ) , true ) ; assert . strictEqual ( QRCodeEncoderQRCode . isValidMaskPattern ( 8 ) , false ) ; } ) ; } ) ;