@@ -253,7 +253,7 @@ class SlicingDiceTester {
253
253
* @param (array) test - the data expected
254
254
* @param (array) result - the data received from Slicing Dice API
255
255
*/
256
- compareResult ( test , result ) {
256
+ compareResult ( test , result ) {
257
257
let expected = this . _translateFieldNames ( test [ 'expected' ] ) ;
258
258
let dataExpected = test [ 'expected' ] ;
259
259
@@ -263,7 +263,7 @@ class SlicingDiceTester {
263
263
continue ;
264
264
}
265
265
266
- if ( JSON . stringify ( expected [ key ] ) != JSON . stringify ( result [ key ] ) ) {
266
+ if ( ! this . compareJson ( expected [ key ] , result [ key ] ) ) {
267
267
this . numFails += 1 ;
268
268
this . failedTests . push ( test [ 'name' ] ) ;
269
269
@@ -281,6 +281,77 @@ class SlicingDiceTester {
281
281
}
282
282
}
283
283
284
+ /* Compare two JSON's
285
+ *
286
+ * @param (object) expected - the data expected
287
+ * @param (object) result - the data received from Slicing Dice API
288
+ */
289
+ compareJson ( expected , result ) {
290
+ if ( typeof expected !== typeof result ) return false ;
291
+ if ( expected . constructor !== result . constructor ) return false ;
292
+
293
+ if ( expected instanceof Array ) {
294
+ return this . compareJsonValue ( expected , result ) ;
295
+ }
296
+
297
+ if ( typeof expected === "object" ) {
298
+ return this . arrayEqual ( expected , result ) ;
299
+ }
300
+
301
+ return expected === result ;
302
+ }
303
+
304
+ /* Compare two JSON's values
305
+ *
306
+ * @param (object) expected - the data expected
307
+ * @param (object) result - the data received from Slicing Dice API
308
+ */
309
+ compareJsonValue ( expected , result ) {
310
+ for ( let key in expected ) {
311
+ if ( expected . hasOwnProperty ( key ) ) {
312
+ if ( ! result . hasOwnProperty ( key ) ) {
313
+ return false ;
314
+ }
315
+
316
+ if ( ! this . compareJson ( expected [ key ] , result [ key ] ) ) {
317
+ return false ;
318
+ }
319
+ }
320
+ }
321
+
322
+ return true ;
323
+ }
324
+
325
+ /* Compare two JSON's arrays
326
+ *
327
+ * @param (array) expected - the data expected
328
+ * @param (array) result - the data received from Slicing Dice API
329
+ */
330
+ arrayEqual ( expected , result ) {
331
+ if ( expected . length !== result . length ) {
332
+ return false ;
333
+ }
334
+
335
+ let i = expected . length ;
336
+
337
+ while ( i -- ) {
338
+ let j = result . length ;
339
+ let found = false ;
340
+
341
+ while ( ! found && j -- ) {
342
+ if ( this . compareJson ( expected [ i ] , result [ j ] ) ) {
343
+ found = true ;
344
+ }
345
+ }
346
+
347
+ if ( ! found ) {
348
+ return false ;
349
+ }
350
+ }
351
+
352
+ return true ;
353
+ }
354
+
284
355
// Write a file testResult.tmp with the result of the tests
285
356
updateResult ( ) {
286
357
if ( process . platform == "win32" ) {
@@ -290,7 +361,7 @@ class SlicingDiceTester {
290
361
let failedTestsStr = "" ;
291
362
292
363
if ( this . failedTests . length > 0 ) {
293
- for ( var item in this . failedTests ) {
364
+ for ( let item in this . failedTests ) {
294
365
failedTestsStr += " - {0}\n" . format ( this . failedTests [ item ] ) ;
295
366
}
296
367
}
0 commit comments