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

Side by Side Diff: tests/corelib_strong/set_test.dart

Issue 2683893002: Make corelib_strong tests strong-mode compliant (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Objects that are equal based on data. 362 // Objects that are equal based on data.
363 class CE implements Comparable<CE> { 363 class CE implements Comparable<CE> {
364 final int id; 364 final int id;
365 const CE(this.id); 365 const CE(this.id);
366 int get hashCode => id; 366 int get hashCode => id;
367 bool operator==(Object other) => other is CE && id == (other as CE).id; 367 bool operator==(Object other) => other is CE && id == (other as CE).id;
368 int compareTo(CE other) => id - other.id; 368 int compareTo(CE other) => id - other.id;
369 String toString() => "CE($id)"; 369 String toString() => "CE($id)";
370 } 370 }
371 371
372 typedef int CECompare(CE e1, CE e2);
372 // Equality of Id objects based on id modulo value. 373 // Equality of Id objects based on id modulo value.
373 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;
374 Function customHash(int mod) => (CE e) => e.id % mod; 375 Function customHash(int mod) => (CE e) => e.id % mod;
375 Function customCompare(int mod) => (CE e1, CE e2) => 376 CECompare customCompare(int mod) => (CE e1, CE e2) =>
376 (e1.id % mod) - (e2.id % mod); 377 (e1.id % mod) - (e2.id % mod);
377 bool validKey(Object o) => o is CE; 378 bool validKey(Object o) => o is CE;
378 final customId = new Map.identity(); 379 final customId = new Map.identity();
379 int counter = 0; 380 int counter = 0;
380 int identityCompare(e1, e2) { 381 int identityCompare(e1, e2) {
381 if (identical(e1, e2)) return 0; 382 if (identical(e1, e2)) return 0;
382 int i1 = customId.putIfAbsent(e1, () => ++counter); 383 int i1 = customId.putIfAbsent(e1, () => ++counter);
383 int i2 = customId.putIfAbsent(e2, () => ++counter); 384 int i2 = customId.putIfAbsent(e2, () => ++counter);
384 return i1 - i2; 385 return i1 - i2;
385 } 386 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 519
519 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, 520 testCESetFrom((x) => new SplayTreeSet<CE>.from(x,
520 customCompare(20), validKey)); 521 customCompare(20), validKey));
521 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); 522 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare));
522 523
523 testASetFrom((x) => new Set<A>.from(x)); 524 testASetFrom((x) => new Set<A>.from(x));
524 testASetFrom((x) => new HashSet<A>.from(x)); 525 testASetFrom((x) => new HashSet<A>.from(x));
525 testASetFrom((x) => new LinkedHashSet<A>.from(x)); 526 testASetFrom((x) => new LinkedHashSet<A>.from(x));
526 testASetFrom((x) => new SplayTreeSet<A>.from(x, identityCompare)); 527 testASetFrom((x) => new SplayTreeSet<A>.from(x, identityCompare));
527 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698