OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 library set_test; | 5 library set_test; |
6 | 6 |
7 | 7 |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 import "dart:collection"; | 9 import "dart:collection"; |
10 | 10 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 String toString() => "CE($id)"; | 369 String toString() => "CE($id)"; |
370 } | 370 } |
371 | 371 |
372 typedef int CECompare(CE e1, CE e2); | 372 typedef int CECompare(CE e1, CE e2); |
373 // Equality of Id objects based on id modulo value. | 373 // Equality of Id objects based on id modulo value. |
374 Function customEq(int mod) => (CE e1, CE e2) => ((e1.id - e2.id) % mod) == 0; | 374 Function customEq(int mod) => (CE e1, CE e2) => ((e1.id - e2.id) % mod) == 0; |
375 Function customHash(int mod) => (CE e) => e.id % mod; | 375 Function customHash(int mod) => (CE e) => e.id % mod; |
376 CECompare customCompare(int mod) => (CE e1, CE e2) => | 376 CECompare customCompare(int mod) => (CE e1, CE e2) => |
377 (e1.id % mod) - (e2.id % mod); | 377 (e1.id % mod) - (e2.id % mod); |
378 bool validKey(Object o) => o is CE; | 378 bool validKey(Object o) => o is CE; |
379 final customId = new Map.identity(); | 379 final customId = new Map<dynamic, dynamic>.identity(); |
380 int counter = 0; | 380 int counter = 0; |
381 int identityCompare(e1, e2) { | 381 int identityCompare(e1, e2) { |
382 if (identical(e1, e2)) return 0; | 382 if (identical(e1, e2)) return 0; |
383 int i1 = customId.putIfAbsent(e1, () => ++counter); | 383 int i1 = customId.putIfAbsent(e1, () => ++counter); |
384 int i2 = customId.putIfAbsent(e2, () => ++counter); | 384 int i2 = customId.putIfAbsent(e2, () => ++counter); |
385 return i1 - i2; | 385 return i1 - i2; |
386 } | 386 } |
387 | 387 |
388 void testIdentity(Set create()) { | 388 void testIdentity(Set create()) { |
389 Set set = create(); | 389 Set set = create(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, | 520 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, |
521 customCompare(20), validKey)); | 521 customCompare(20), validKey)); |
522 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); | 522 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); |
523 | 523 |
524 testASetFrom((x) => new Set<A>.from(x)); | 524 testASetFrom((x) => new Set<A>.from(x)); |
525 testASetFrom((x) => new HashSet<A>.from(x)); | 525 testASetFrom((x) => new HashSet<A>.from(x)); |
526 testASetFrom((x) => new LinkedHashSet<A>.from(x)); | 526 testASetFrom((x) => new LinkedHashSet<A>.from(x)); |
527 testASetFrom((x) => new SplayTreeSet<A>.from(x, identityCompare)); | 527 testASetFrom((x) => new SplayTreeSet<A>.from(x, identityCompare)); |
528 } | 528 } |
OLD | NEW |