import 'mocha' ; import * as assert from 'assert' ; import BitMatrix from './../../../../core/common/BitMatrix' ; import DataMask from './../../../../core/qrcode/decoder/DataMask' ; interface MaskCondition { isMasked ( i , j ) : boolean ; } author Sean Owen
  describe ( "DataMaskTestCase" , ( ) => { it ( "testMask0" , ( ) => { testMaskAcrossDimensions ( 0 , { isMasked ( i , j ) { return ( i + j ) % 2 === 0 ; } } ) ; } ) ; it ( "testMask1" , ( ) => { testMaskAcrossDimensions ( 1 , { isMasked ( i , j ) { return i % 2 === 0 ; } } ) ; } ) ; it ( "testMask2" , ( ) => { testMaskAcrossDimensions ( 2 , { isMasked ( i , j ) { return j % 3 === 0 ; } } ) ; } ) ; it ( "testMask3" , ( ) => { testMaskAcrossDimensions ( 3 , { isMasked ( i , j ) { return ( i + j ) % 3 === 0 ; } } ) ; } ) ; it ( "testMask4" , ( ) => { testMaskAcrossDimensions ( 4 , { isMasked ( i , j ) { return ( Math . floor ( i / 2 ) + Math . floor ( j / 3 ) ) % 2 === 0 ; } } ) ; } ) ; it ( "testMask5" , ( ) => { testMaskAcrossDimensions ( 5 , { isMasked ( i , j ) { return ( i * j ) % 2 + ( i * j ) % 3 === 0 ; } } ) ; } ) ; it ( "testMask6" , ( ) => { testMaskAcrossDimensions ( 6 , { isMasked ( i , j ) { return ( ( i * j ) % 2 + ( i * j ) % 3 ) % 2 === 0 ; } } ) ; } ) ; it ( "testMask7" , ( ) => { testMaskAcrossDimensions ( 7 , { isMasked ( i , j ) { return ( ( i + j ) % 2 + ( i * j ) % 3 ) % 2 === 0 ; } } ) ; } ) ; function testMaskAcrossDimensions ( reference , condition ) { const mask = DataMask . values . get ( reference ) ; for ( let version = 1 ; version <= 40 ; version ++ ) { const dimension = 17 + 4 * version ; testMask ( mask , dimension , condition ) ; } } function testMask ( mask , dimension , condition ) { const bits = new BitMatrix ( dimension ) ; mask . unmaskBitMatrix ( bits , dimension ) ; for ( let i = 0 ; i < dimension ; i ++ ) { for ( let j = 0 ; j < dimension ; j ++ ) { assert . strictEqual ( bits . get ( j , i ) , condition . isMasked ( i , j ) , "(" + i + ',' + j + ')' ) ; } } } } ) ;