@@ -253,7 +253,7 @@ class SlicingDiceTester {
253253 * @param (array) test - the data expected
254254 * @param (array) result - the data received from Slicing Dice API
255255 */
256- compareResult ( test , result ) {
256+ compareResult ( test , result ) {
257257 let expected = this . _translateFieldNames ( test [ 'expected' ] ) ;
258258 let dataExpected = test [ 'expected' ] ;
259259
@@ -263,7 +263,7 @@ class SlicingDiceTester {
263263 continue ;
264264 }
265265
266- if ( JSON . stringify ( expected [ key ] ) != JSON . stringify ( result [ key ] ) ) {
266+ if ( ! this . compareJson ( expected [ key ] , result [ key ] ) ) {
267267 this . numFails += 1 ;
268268 this . failedTests . push ( test [ 'name' ] ) ;
269269
@@ -281,6 +281,77 @@ class SlicingDiceTester {
281281 }
282282 }
283283
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 ( var 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+ var i = expected . length ;
336+
337+ while ( i -- ) {
338+ var j = result . length ;
339+ var 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+
284355 // Write a file testResult.tmp with the result of the tests
285356 updateResult ( ) {
286357 if ( process . platform == "win32" ) {
0 commit comments