Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: pkg/smoke/lib/src/common.dart

Issue 370493002: Fix utility function in smoke, add tests for it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/smoke/test/common_utils_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/smoke/lib/src/common.dart
diff --git a/pkg/smoke/lib/src/common.dart b/pkg/smoke/lib/src/common.dart
index 1d73e4ff836ceb04cd921ac62177cbc9305d8311..71a72f0badf004ca3548637eb6520994b8234035 100644
--- a/pkg/smoke/lib/src/common.dart
+++ b/pkg/smoke/lib/src/common.dart
@@ -84,10 +84,22 @@ bool compareLists(List a, List b, {bool unordered: false}) {
if (a != null && b == null) return false;
if (a.length != b.length) return false;
if (unordered) {
- var bSet = new Set()..addAll(b);
- for (int i = 0; i < a.length; i++) {
- if (!bSet.contains(a[i])) return false;
+ var countMap = {};
+ for (var x in b) {
+ var count = countMap[x];
+ if (count == null) count = 0;
+ countMap[x] = count + 1;
+ }
+ for (var x in a) {
+ var count = countMap[x];
+ if (count == null) return false;
+ if (count == 1) {
+ countMap.remove(x);
+ } else {
+ countMap[x] = count - 1;
+ }
}
+ return countMap.isEmpty;
} else {
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) return false;
« no previous file with comments | « no previous file | pkg/smoke/test/common_utils_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698