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

Side by Side Diff: tests/corelib/hash_set_test.dart

Issue 24104003: Reapply "Convert HashSet, LinkedHashSet to factory methods and custom implementations." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Punctuation and whitespace. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/list.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Tests of hash set behavior, with focus in iteration and concurrent 5 // Tests of hash set behavior, with focus in iteration and concurrent
6 // modification errors. 6 // modification errors.
7 7
8 library hash_map2_test; 8 library hash_map2_test;
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 import 'dart:collection'; 10 import 'dart:collection';
11 11
12 testSet(Set newSet(), Set newSetFrom(Set from)) { 12 testSet(Set newSet(), Set newSetFrom(Set from)) {
13
13 Set gen(int from, int to) => 14 Set gen(int from, int to) =>
14 new Set.from(new Iterable.generate(to - from, (n) => n + from)); 15 new Set.from(new Iterable.generate(to - from, (n) => n + from));
15 16
16 bool odd(int n) => (n & 1) == 1; 17 bool odd(int n) => (n & 1) == 1;
17 bool even(int n) => (n & 1) == 0; 18 bool even(int n) => (n & 1) == 0;
18 19
19 { // Test growing to largish capacity. 20 { // Test growing to largish capacity.
20 Set set = newSet(); 21 Set set = newSet();
21 22
22 for (int i = 0; i < 256; i++) { 23 for (int i = 0; i < 256; i++) {
23 set.add(i); 24 set.add(i);
24 } 25 }
26
25 set.addAll(gen(256, 512)); 27 set.addAll(gen(256, 512));
26 set.addAll(newSetFrom(gen(512, 1000))); 28 set.addAll(newSetFrom(gen(512, 1000)));
27 Expect.equals(1000, set.length); 29 Expect.equals(1000, set.length);
28 30
29 // Remove half. 31 // Remove half.
30 for (int i = 0; i < 1000; i += 2) set.remove(i); 32 for (int i = 0; i < 1000; i += 2) set.remove(i);
31 Expect.equals(500, set.length); 33 Expect.equals(500, set.length);
32 Expect.isFalse(set.any(even)); 34 Expect.isFalse(set.any(even));
33 Expect.isTrue(set.every(odd)); 35 Expect.isTrue(set.every(odd));
34 36
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 228
227 class BadHashCode { 229 class BadHashCode {
228 static int idCounter = 0; 230 static int idCounter = 0;
229 final int id; 231 final int id;
230 BadHashCode() : id = idCounter++; 232 BadHashCode() : id = idCounter++;
231 int get hashCode => 42; 233 int get hashCode => 42;
232 // operator == is identity. 234 // operator == is identity.
233 // Can't make a bad compareTo that isn't invalid. 235 // Can't make a bad compareTo that isn't invalid.
234 int compareTo(BadHashCode other) => id - other.id; 236 int compareTo(BadHashCode other) => id - other.id;
235 } 237 }
OLDNEW
« no previous file with comments | « sdk/lib/core/list.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698