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 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 set.remove(m1a); | 247 set.remove(m1a); |
248 set.add(m1b); | 248 set.add(m1b); |
249 Expect.identical(m1b, set.lookup(m1a)); | 249 Expect.identical(m1b, set.lookup(m1a)); |
250 Expect.identical(m1b, set.lookup(m1b)); | 250 Expect.identical(m1b, set.lookup(m1b)); |
251 | 251 |
252 set.add(1); | 252 set.add(1); |
253 Expect.identical(1, set.lookup(1.0)); | 253 Expect.identical(1, set.lookup(1.0)); |
254 set.add(-0.0); | 254 set.add(-0.0); |
255 Expect.identical(-0.0, set.lookup(0.0)); | 255 Expect.identical(-0.0, set.lookup(0.0)); |
256 } | 256 } |
| 257 |
| 258 { // Test special hash codes |
| 259 Set set = newSet(); |
| 260 List keys = []; |
| 261 // Powers of two |
| 262 for (int i = 65; i >= 2; --i) { |
| 263 keys.add(new Mutable(1 << i)); |
| 264 } |
| 265 for (var key in keys) { |
| 266 Expect.isTrue(set.add(key)); |
| 267 } |
| 268 for (var key in keys) { |
| 269 Expect.isTrue(set.contains(key)); |
| 270 } |
| 271 } |
257 } | 272 } |
258 | 273 |
259 | 274 |
260 void testIdentitySet(Set create()) { | 275 void testIdentitySet(Set create()) { |
261 Set set = create(); | 276 Set set = create(); |
262 set.add(1); | 277 set.add(1); |
263 set.add(2); | 278 set.add(2); |
264 set.add(1); // Integers are identical if equal. | 279 set.add(1); // Integers are identical if equal. |
265 Expect.equals(2, set.length); | 280 Expect.equals(2, set.length); |
266 var complex = 4; | 281 var complex = 4; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // Can't make a bad compareTo that isn't invalid. | 340 // Can't make a bad compareTo that isn't invalid. |
326 int compareTo(BadHashCode other) => id - other.id; | 341 int compareTo(BadHashCode other) => id - other.id; |
327 } | 342 } |
328 | 343 |
329 class Mutable { | 344 class Mutable { |
330 int id; | 345 int id; |
331 Mutable(this.id); | 346 Mutable(this.id); |
332 int get hashCode => id; | 347 int get hashCode => id; |
333 bool operator==(other) => other is Mutable && id == other.id; | 348 bool operator==(other) => other is Mutable && id == other.id; |
334 } | 349 } |
OLD | NEW |