| OLD | NEW |
| 1 library TestUtils; | 1 library TestUtils; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 | 3 |
| 4 /** | 4 /** |
| 5 * Verifies that [actual] has the same graph structure as [expected]. | 5 * Verifies that [actual] has the same graph structure as [expected]. |
| 6 * Detects cycles and DAG structure in Maps and Lists. | 6 * Detects cycles and DAG structure in Maps and Lists. |
| 7 */ | 7 */ |
| 8 verifyGraph(expected, actual) { | 8 verifyGraph(expected, actual) { |
| 9 var eItems = []; | 9 var eItems = []; |
| 10 var aItems = []; | 10 var aItems = []; |
| 11 | 11 |
| 12 message(path, reason) => path == '' | 12 message(path, reason) => path == '' |
| 13 ? reason | 13 ? reason |
| 14 : reason == null ? "path: $path" : "path: $path, $reason"; | 14 : reason == null ? "path: $path" : "path: $path, $reason"; |
| 15 | 15 |
| 16 walk(path, expected, actual) { | 16 walk(path, expected, actual) { |
| 17 if (expected is String || expected is num || expected == null) { | 17 if (expected is String || expected is num || expected == null) { |
| 18 expect(actual, equals(expected), reason: message(path, 'not equal')); | 18 expect(actual, equals(expected), reason: message(path, 'not equal')); |
| 19 return; | 19 return; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // Cycle or DAG? | 22 // Cycle or DAG? |
| 23 for (int i = 0; i < eItems.length; i++) { | 23 for (int i = 0; i < eItems.length; i++) { |
| 24 if (expected === eItems[i]) { | 24 if (identical(expected, eItems[i])) { |
| 25 expect(actual, same(aItems[i]), | 25 expect(actual, same(aItems[i]), |
| 26 reason: message(path, 'missing back or side edge')); | 26 reason: message(path, 'missing back or side edge')); |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 for (int i = 0; i < aItems.length; i++) { | 30 for (int i = 0; i < aItems.length; i++) { |
| 31 if (actual === aItems[i]) { | 31 if (identical(actual, aItems[i])) { |
| 32 expect(expected, same(eItems[i]), | 32 expect(expected, same(eItems[i]), |
| 33 reason: message(path, 'extra back or side edge')); | 33 reason: message(path, 'extra back or side edge')); |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 eItems.add(expected); | 37 eItems.add(expected); |
| 38 aItems.add(actual); | 38 aItems.add(actual); |
| 39 | 39 |
| 40 if (expected is List) { | 40 if (expected is List) { |
| 41 expect(actual, isList, reason: message(path, '$actual is List')); | 41 expect(actual, isList, reason: message(path, '$actual is List')); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 | 65 |
| 66 expect(false, isTrue, reason: 'Unhandled type: $expected'); | 66 expect(false, isTrue, reason: 'Unhandled type: $expected'); |
| 67 } | 67 } |
| 68 | 68 |
| 69 walk('', expected, actual); | 69 walk('', expected, actual); |
| 70 } | 70 } |
| OLD | NEW |