@@ -41,10 +41,33 @@ export function eavsToComparables(eavs, entities, index = {}) {
41
41
return results ;
42
42
}
43
43
44
- export function isSetEqual ( as , bs ) {
44
+ // Tests if the elements of `as` are in `bs` by comparing keys in a list. In
45
+ // the case of floating points, we want the comparison to be looser, to account
46
+ // for floating point rounding errors, which can vary by platform.
47
+
48
+ export function isSetEqual ( as , bs , assert ) {
45
49
if ( as . length !== bs . length ) return false ;
46
50
for ( let a of as ) {
47
- if ( bs . indexOf ( a ) === - 1 ) return false ;
51
+ let avA = a . split ( ", " ) ;
52
+ let attributeA = avA [ 0 ] ;
53
+ let valueA = avA [ 1 ] ;
54
+ // If the attribute is called "floatTest" we know to compare
55
+ // the values to within some delta. Otherwise, we can
56
+ // do a straight lookup of the key
57
+ let delta = 0.00000000001 ;
58
+ if ( attributeA === "floatTest" ) {
59
+ for ( let b of bs ) {
60
+ let avB = b . split ( ", " ) ;
61
+ let attributeB = avB [ 0 ] ;
62
+ let valueB = avB [ 1 ] ;
63
+ if ( attributeB === "floatTest" && Math . abs ( valueB - valueA ) < delta ) {
64
+ return true ;
65
+ }
66
+ }
67
+ return false ;
68
+ } else {
69
+ if ( bs . indexOf ( a ) === - 1 ) return false ;
70
+ }
48
71
}
49
72
return true ;
50
73
}
@@ -92,7 +115,7 @@ export function resolveActualExpected(assert, actuals, expecteds, entities) {
92
115
let expectedIx = 0 ;
93
116
for ( let expected of expecteds ) {
94
117
let listEqual , linkEqual ;
95
- if ( isSetEqual ( expected . list , actual . list ) ) {
118
+ if ( isSetEqual ( expected . list , actual . list , assert ) ) {
96
119
listEqual = true ;
97
120
} else {
98
121
found = false ;
@@ -120,7 +143,7 @@ export function resolveActualExpected(assert, actuals, expecteds, entities) {
120
143
expectedIx ++ ;
121
144
}
122
145
if ( found === false ) {
123
- assert . true ( false , "No matching add found for object : " + JSON . stringify ( actual . list ) )
146
+ assert . true ( false , "No matching add found for actual record : " + JSON . stringify ( actual . list ) )
124
147
}
125
148
}
126
149
}
@@ -164,26 +187,31 @@ export function evaluate(assert, expected, code, session = new Database()) {
164
187
return next ;
165
188
}
166
189
167
- export function testSingleExpressionByList ( list :any [ ] ) {
190
+ export interface valueTest {
191
+ expression : string ;
192
+ expectedValue : number ;
193
+ } ;
194
+
195
+ export function testSingleExpressionByList ( list : valueTest [ ] ) {
168
196
list . forEach ( ( list_item , index ) => {
169
- test ( `Is ${ list_item . Expression } returning ${ list_item . Value } ?` , ( assert ) => {
197
+ test ( `Is ${ list_item . expression } returning ${ list_item . expectedValue } ?` , ( assert ) => {
170
198
let expected = {
171
199
insert : [
172
- [ "a" , "result " , list_item . Value ] ,
200
+ [ "a" , "floatTest " , list_item . expectedValue ] ,
173
201
] ,
174
202
remove : [ ] ,
175
203
} ;
176
204
177
205
evaluate ( assert , expected , `
178
206
~~~
179
207
search
180
- x = ${ list_item . Expression }
208
+ x = ${ list_item . expression }
181
209
182
210
bind
183
- [result : x]
211
+ [floatTest : x]
184
212
~~~
185
213
` ) ;
186
214
assert . end ( ) ;
187
215
} ) ;
188
216
} ) ;
189
- }
217
+ }
0 commit comments