import 'mocha' ; import * as assert from 'assert' ; import ErrorCorrectionLevel from './../../../../core/qrcode/decoder/ErrorCorrectionLevel' ; import Version from './../../../../core/qrcode/decoder/Version' ; author Sean Owen
  describe ( "VersionTestCase" , ( ) => { it ( "testVersionForNumber" , ( ) => { try { Version . getVersionForNumber ( 0 ) ; assert . ok ( false , "Should have thrown an exception" ) ; } catch ( iae ) { } for ( let i = 1 ; i <= 40 ; i ++ ) { checkVersion ( Version . getVersionForNumber ( i ) , i , 4 * i + 17 ) ; } } ) ; function checkVersion ( version , number , dimension ) { assert . strictEqual ( null !== version , true ) ; assert . strictEqual ( version . getVersionNumber ( ) , number ) ; assert . strictEqual ( null !== version . getAlignmentPatternCenters ( ) , true ) ; if ( number > 1 ) { assert . strictEqual ( version . getAlignmentPatternCenters ( ) . length > 0 , true ) ; } assert . strictEqual ( version . getDimensionForVersion ( ) , dimension ) ; assert . strictEqual ( null !== version . getECBlocksForLevel ( ErrorCorrectionLevel . H ) , true ) ; assert . strictEqual ( null !== version . getECBlocksForLevel ( ErrorCorrectionLevel . L ) , true ) ; assert . strictEqual ( null !== version . getECBlocksForLevel ( ErrorCorrectionLevel . M ) , true ) ; assert . strictEqual ( null !== version . getECBlocksForLevel ( ErrorCorrectionLevel . Q ) , true ) ; assert . strictEqual ( null !== version . buildFunctionPattern ( ) , true ) ; } it ( "testGetProvisionalVersionForDimension" , ( ) => { for ( let i = 1 ; i <= 40 ; i ++ ) { assert . strictEqual ( Version . getProvisionalVersionForDimension ( 4 * i + 17 ) . getVersionNumber ( ) , i ) ; } } ) ; it ( "testDecodeVersionInformation" , ( ) => { doTestVersion ( 7 , 0x07C94 ) ; doTestVersion ( 12 , 0x0C762 ) ; doTestVersion ( 17 , 0x1145D ) ; doTestVersion ( 22 , 0x168C9 ) ; doTestVersion ( 27 , 0x1B08E ) ; doTestVersion ( 32 , 0x209D5 ) ; } ) ; function doTestVersion ( expectedVersion , mask ) { const version = Version . decodeVersionInformation ( mask ) ; assert . strictEqual ( null !== version , true ) ; assert . strictEqual ( version . getVersionNumber ( ) , expectedVersion ) ; } } ) ;