Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // dart2js specific test to make sure hashCode on intercepted types behaves as | 7 // dart2js specific test to make sure hashCode on intercepted types behaves as |
| 8 // intended. | 8 // intended. |
| 9 | 9 |
| 10 | 10 |
| 11 class Hasher { | 11 class Hasher { |
| 12 confuse(x) => [1, 'x', true, null, x].last; | 12 confuse(x) => [1, 'x', true, null, x].last; |
| 13 hash(x) => confuse(x).hashCode; | 13 hash(x) => confuse(x).hashCode; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // Hashing via [hash] should be forced to use the general interceptor, but the | 16 // Hashing via [hash] should be forced to use the general interceptor, but the |
| 17 // local x.hashCode calls might be optimized. | 17 // local x.hashCode calls might be optimized. |
| 18 var hash = new Hasher().hash; | 18 var hash = new Hasher().hash; |
| 19 | 19 |
| 20 check(value1, value2) { | 20 check(value1, value2) { |
| 21 var h1 = hash(value1); | 21 var h1 = hash(value1); |
| 22 var h2 = hash(value2); | 22 var h2 = hash(value2); |
| 23 | 23 |
| 24 Expect.isTrue(h1 is int); | 24 Expect.isTrue(h1 is int); |
| 25 Expect.isTrue(h2 is int); | 25 Expect.isTrue(h2 is int); |
| 26 Expect.isFalse(h1 == h2); | 26 Expect.isFalse(h1 == h2); |
| 27 | 27 |
| 28 // We expect that the hash function is reasonable quality - there are some | 28 // We expect that the hash function is reasonable quality - there are some |
| 29 // difference in the low bits. | 29 // difference in the low bits. |
| 30 Expect.isFalse((h1 & 0xf) == (h2 & 0xf)); | 30 Expect.isFalse((h1 & 0xf) == (h2 & 0xf)); |
|
ahe
2013/06/04 06:02:46
I think this test is flaky.
| |
| 31 | 31 |
| 32 // Quality check - the values should be SMIs for efficient arithmetic. | 32 // Quality check - the values should be SMIs for efficient arithmetic. |
| 33 Expect.equals((h1 & 0x1fffffff), h1); | 33 Expect.equals((h1 & 0x3fffffff), h1); |
| 34 Expect.equals((h2 & 0x1fffffff), h2); | 34 Expect.equals((h2 & 0x3fffffff), h2); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bools() { | 37 bools() { |
| 38 check(true, false); | 38 check(true, false); |
| 39 | 39 |
| 40 Expect.equals(true.hashCode, hash(true)); // First can be optimized. | 40 Expect.equals(true.hashCode, hash(true)); // First can be optimized. |
| 41 Expect.equals(false.hashCode, hash(false)); | 41 Expect.equals(false.hashCode, hash(false)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ints() { | 44 ints() { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 74 Expect.equals(0x0DB819B, 'b'.hashCode); | 74 Expect.equals(0x0DB819B, 'b'.hashCode); |
| 75 Expect.equals(0xEBA5D59, 'c'.hashCode); | 75 Expect.equals(0xEBA5D59, 'c'.hashCode); |
| 76 } | 76 } |
| 77 | 77 |
| 78 main() { | 78 main() { |
| 79 bools(); | 79 bools(); |
| 80 ints(); | 80 ints(); |
| 81 lists(); | 81 lists(); |
| 82 strings(); | 82 strings(); |
| 83 } | 83 } |
| OLD | NEW |