| OLD | NEW |
| 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 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--use_compact_hash=false | 6 // VMOptions=--use_compact_hash=false |
| 7 | 7 |
| 8 // Tests of hash set behavior, with focus in iteration and concurrent | 8 // Tests of hash set behavior, with focus in iteration and concurrent |
| 9 // modification errors. | 9 // modification errors. |
| 10 | 10 |
| 11 library hash_map2_test; | 11 library hash_map2_test; |
| 12 import "package:expect/expect.dart"; | 12 import "package:expect/expect.dart"; |
| 13 import 'dart:collection'; | 13 import 'dart:collection'; |
| 14 import 'dart:math' as math; |
| 14 | 15 |
| 15 testSet(Set newSet(), Set newSetFrom(Iterable from)) { | 16 testSet(Set newSet(), Set newSetFrom(Iterable from)) { |
| 16 | 17 |
| 17 Set gen(int from, int to) => | 18 Set gen(int from, int to) => |
| 18 new Set.from(new Iterable.generate(to - from, (n) => n + from)); | 19 new Set.from(new Iterable.generate(to - from, (n) => n + from)); |
| 19 | 20 |
| 20 bool odd(int n) => (n & 1) == 1; | 21 bool odd(int n) => (n & 1) == 1; |
| 21 bool even(int n) => (n & 1) == 0; | 22 bool even(int n) => (n & 1) == 0; |
| 22 | 23 |
| 23 { // Test growing to largish capacity. | 24 { // Test growing to largish capacity. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 Expect.identical(1, set.lookup(1.0)); | 254 Expect.identical(1, set.lookup(1.0)); |
| 254 set.add(-0.0); | 255 set.add(-0.0); |
| 255 Expect.identical(-0.0, set.lookup(0.0)); | 256 Expect.identical(-0.0, set.lookup(0.0)); |
| 256 } | 257 } |
| 257 | 258 |
| 258 { // Test special hash codes | 259 { // Test special hash codes |
| 259 Set set = newSet(); | 260 Set set = newSet(); |
| 260 List keys = []; | 261 List keys = []; |
| 261 // Powers of two | 262 // Powers of two |
| 262 for (int i = 65; i >= 2; --i) { | 263 for (int i = 65; i >= 2; --i) { |
| 263 keys.add(new Mutable(1 << i)); | 264 keys.add(new Mutable(math.pow(2, i))); |
| 264 } | 265 } |
| 265 for (var key in keys) { | 266 for (var key in keys) { |
| 266 Expect.isTrue(set.add(key)); | 267 Expect.isTrue(set.add(key)); |
| 267 } | 268 } |
| 268 for (var key in keys) { | 269 for (var key in keys) { |
| 269 Expect.isTrue(set.contains(key)); | 270 Expect.isTrue(set.contains(key)); |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 | 274 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Can't make a bad compareTo that isn't invalid. | 341 // Can't make a bad compareTo that isn't invalid. |
| 341 int compareTo(BadHashCode other) => id - other.id; | 342 int compareTo(BadHashCode other) => id - other.id; |
| 342 } | 343 } |
| 343 | 344 |
| 344 class Mutable { | 345 class Mutable { |
| 345 int id; | 346 int id; |
| 346 Mutable(this.id); | 347 Mutable(this.id); |
| 347 int get hashCode => id; | 348 int get hashCode => id; |
| 348 bool operator==(other) => other is Mutable && id == other.id; | 349 bool operator==(other) => other is Mutable && id == other.id; |
| 349 } | 350 } |
| OLD | NEW |