import 'mocha' ; import * as assert from 'assert' ; import MathUtils from './../../../../core/common/detector/MathUtils' ; describe ( "MathUtilsTestCase" , ( ) => { const EPSILON = 1.0E-8 ; it ( "testRound" , ( ) => { assert . strictEqual ( MathUtils . round ( - 1.0 ) , - 1 ) ; assert . strictEqual ( MathUtils . round ( 0.0 ) , 0 ) ; assert . strictEqual ( MathUtils . round ( 1.0 ) , 1 ) ; assert . strictEqual ( MathUtils . round ( 1.9 ) , 2 ) ; assert . strictEqual ( MathUtils . round ( 2.1 ) , 2 ) ; assert . strictEqual ( MathUtils . round ( 2.5 ) , 3 ) ; assert . strictEqual ( MathUtils . round ( - 1.9 ) , - 2 ) ; assert . strictEqual ( MathUtils . round ( - 2.1 ) , - 2 ) ; assert . strictEqual ( MathUtils . round ( - 2.5 ) , - 3 ) ; assert . strictEqual ( MathUtils . round ( Number . MAX_SAFE_INTEGER ) , Number . MAX_SAFE_INTEGER ) ; assert . strictEqual ( MathUtils . round ( Number . MIN_SAFE_INTEGER ) , Number . MIN_SAFE_INTEGER ) ; assert . strictEqual ( MathUtils . round ( Number . POSITIVE_INFINITY ) , Number . MAX_SAFE_INTEGER ) ; assert . strictEqual ( MathUtils . round ( Number . NEGATIVE_INFINITY ) , Number . MIN_SAFE_INTEGER ) ; assert . strictEqual ( MathUtils . round ( NaN ) , 0 ) ; } ) ; it ( "testDistance" , ( ) => { assert . strictEqual ( Math . abs ( MathUtils . distance ( 1.0 , 2.0 , 3.0 , 4.0 ) - Math . sqrt ( 8.0 ) ) < EPSILON , true ) ; assert . strictEqual ( Math . abs ( MathUtils . distance ( 1.0 , 2.0 , 1.0 , 2.0 ) - 0.0 ) < EPSILON , true ) ; assert . strictEqual ( Math . abs ( MathUtils . distance ( 1 , 2 , 3 , 4 ) - Math . sqrt ( 8.0 ) ) < EPSILON , true ) ; assert . strictEqual ( Math . abs ( MathUtils . distance ( 1 , 2 , 1 , 2 ) - 0.0 ) < EPSILON , true ) ; } ) ; it ( "testSum" , ( ) => { assert . strictEqual ( MathUtils . sum ( Int32Array . from ( [ ] ) ) , 0 ) ; assert . strictEqual ( MathUtils . sum ( Int32Array . from ( [ 1 ] ) ) , 1 ) ; assert . strictEqual ( MathUtils . sum ( Int32Array . from ( [ 1 , 3 ] ) ) , 4 ) ; assert . strictEqual ( MathUtils . sum ( Int32Array . from ( [ - 1 , 1 ] ) ) , 0 ) ; } ) ; } ) ;