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
+
1
6
module . exports = {
2
7
3
8
// toBeCloseTo... but for arrays
@@ -7,7 +12,7 @@ module.exports = {
7
12
precision = coercePosition ( precision ) ;
8
13
9
14
var tested = actual . map ( function ( element , i ) {
10
- return Math . abs ( expected [ i ] - element ) < precision ;
15
+ return isClose ( element , expected [ i ] , precision ) ;
11
16
} ) ;
12
17
13
18
var passed = (
@@ -44,9 +49,7 @@ module.exports = {
44
49
}
45
50
46
51
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 ) ) {
50
53
passed = false ;
51
54
break ;
52
55
}
@@ -71,6 +74,14 @@ module.exports = {
71
74
}
72
75
} ;
73
76
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
+
74
85
function coercePosition ( precision ) {
75
86
if ( precision !== 0 ) {
76
87
precision = Math . pow ( 10 , - precision ) / 2 || 0.005 ;
You can’t perform that action at this time.
0 commit comments