Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Some common utilities used by other libraries in this package. | 5 /// Some common utilities used by other libraries in this package. |
| 6 library smoke.src.common; | 6 library smoke.src.common; |
| 7 | 7 |
| 8 import 'package:smoke/smoke.dart' as smoke show isSubclassOf; | 8 import 'package:smoke/smoke.dart' as smoke show isSubclassOf; |
| 9 | 9 |
| 10 /// Returns [input] adjusted to be within [min] and [max] length. Truncating it | 10 /// Returns [input] adjusted to be within [min] and [max] length. Truncating it |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 /// Shallow comparison of two lists. | 81 /// Shallow comparison of two lists. |
| 82 bool compareLists(List a, List b, {bool unordered: false}) { | 82 bool compareLists(List a, List b, {bool unordered: false}) { |
| 83 if (a == null && b != null) return false; | 83 if (a == null && b != null) return false; |
| 84 if (a != null && b == null) return false; | 84 if (a != null && b == null) return false; |
| 85 if (a.length != b.length) return false; | 85 if (a.length != b.length) return false; |
| 86 if (unordered) { | 86 if (unordered) { |
| 87 var bSet = new Set()..addAll(b); | 87 var bSet = new Set()..addAll(b); |
| 88 for (int i = 0; i < a.length; i++) { | 88 for (int i = 0; i < a.length; i++) { |
| 89 if (!bSet.contains(a[i])) return false; | 89 if (!bSet.contains(a[i])) return false; |
| 90 } | 90 } |
| 91 | |
| 92 var aSet = new Set()..addAll(a); | |
| 93 for (int i = 0; i < b.length; i++) { | |
| 94 if (!aSet.contains(b[i])) return false; | |
| 95 } | |
|
vicb
2014/07/13 09:55:02
I think that the code is still not right.
[1 1 2
justinfagnani
2014/07/14 17:20:19
A Set is not going to work here, you need two maps
Siggi Cherem (dart-lang)
2014/07/14 19:48:57
<facepalm> ... Ok I updated this again, hopefully
| |
| 91 } else { | 96 } else { |
| 92 for (int i = 0; i < a.length; i++) { | 97 for (int i = 0; i < a.length; i++) { |
| 93 if (a[i] != b[i]) return false; | 98 if (a[i] != b[i]) return false; |
| 94 } | 99 } |
| 95 } | 100 } |
| 96 return true; | 101 return true; |
| 97 } | 102 } |
| 98 | 103 |
| 99 /// Shallow comparison of two maps. | 104 /// Shallow comparison of two maps. |
| 100 bool compareMaps(Map a, Map b) { | 105 bool compareMaps(Map a, Map b) { |
| 101 if (a == null && b != null) return false; | 106 if (a == null && b != null) return false; |
| 102 if (a != null && b == null) return false; | 107 if (a != null && b == null) return false; |
| 103 if (a.length != b.length) return false; | 108 if (a.length != b.length) return false; |
| 104 for (var k in a.keys) { | 109 for (var k in a.keys) { |
| 105 if (!b.containsKey(k) || a[k] != b[k]) return false; | 110 if (!b.containsKey(k) || a[k] != b[k]) return false; |
| 106 } | 111 } |
| 107 return true; | 112 return true; |
| 108 } | 113 } |
| OLD | NEW |