File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var isNumeric = require ( 'fast-isnumeric' ) ;
4+
5+
16module . exports = {
27
38 // toBeCloseTo... but for arrays
@@ -7,7 +12,7 @@ module.exports = {
712 precision = coercePosition ( precision ) ;
813
914 var tested = actual . map ( function ( element , i ) {
10- return Math . abs ( expected [ i ] - element ) < precision ;
15+ return isClose ( element , expected [ i ] , precision ) ;
1116 } ) ;
1217
1318 var passed = (
@@ -44,9 +49,7 @@ module.exports = {
4449 }
4550
4651 for ( var j = 0 ; j < expected [ i ] . length ; ++ j ) {
47- var isClose = Math . abs ( expected [ i ] [ j ] - actual [ i ] [ j ] ) < precision ;
48-
49- if ( ! isClose ) {
52+ if ( ! isClose ( actual [ i ] [ j ] , expected [ i ] [ j ] , precision ) ) {
5053 passed = false ;
5154 break ;
5255 }
@@ -71,6 +74,14 @@ module.exports = {
7174 }
7275} ;
7376
77+ function isClose ( actual , expected , precision ) {
78+ if ( isNumeric ( actual ) && isNumeric ( expected ) ) {
79+ return Math . abs ( actual - expected ) < precision ;
80+ }
81+
82+ return actual === expected ;
83+ }
84+
7485function coercePosition ( precision ) {
7586 if ( precision !== 0 ) {
7687 precision = Math . pow ( 10 , - precision ) / 2 || 0.005 ;
You can’t perform that action at this time.
0 commit comments