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

Unified Diff: tests/compiler/dart2js_extra/hash_code_test.dart

Issue 16093021: Fix hash code tests to be non-flaky. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js_extra/hash_code_test.dart
diff --git a/tests/compiler/dart2js_extra/hash_code_test.dart b/tests/compiler/dart2js_extra/hash_code_test.dart
index bf7aed523dd0f6e14d9239e8cf023769c95f25e9..0c5c4b3a911a5219687bcebc13819cb38ec3077e 100644
--- a/tests/compiler/dart2js_extra/hash_code_test.dart
+++ b/tests/compiler/dart2js_extra/hash_code_test.dart
@@ -17,25 +17,28 @@ class Hasher {
// local x.hashCode calls might be optimized.
var hash = new Hasher().hash;
-check(value1, value2) {
+check(value1, value2, {identityHashCode}) {
ahe 2013/06/04 13:19:49 bool identityHashCode: false
var h1 = hash(value1);
var h2 = hash(value2);
-
Expect.isTrue(h1 is int);
Expect.isTrue(h2 is int);
- Expect.isFalse(h1 == h2);
-
- // We expect that the hash function is reasonable quality - there are some
- // difference in the low bits.
- Expect.isFalse((h1 & 0xf) == (h2 & 0xf));
// Quality check - the values should be SMIs for efficient arithmetic.
Expect.equals((h1 & 0x3fffffff), h1);
Expect.equals((h2 & 0x3fffffff), h2);
+
+ // If we're checking the (randomized) identity hash code function,
+ // we cannot guarantee anything about the actual hash code values.
+ if (identityHashCode) return;
ahe 2013/06/04 13:19:49 Otherwise this will fail in checked mode.
+
+ // We expect that the hash function is reasonable quality - there
+ // are some difference in the low bits.
+ Expect.isFalse(h1 == h2);
+ Expect.isFalse((h1 & 0xf) == (h2 & 0xf));
}
bools() {
- check(true, false);
+ check(true, false, identityHashCode: false);
Expect.equals(true.hashCode, hash(true)); // First can be optimized.
Expect.equals(false.hashCode, hash(false));
@@ -44,7 +47,7 @@ bools() {
ints() {
var i1 = 100;
var i2 = 101;
- check(i1, i2);
+ check(i1, i2, identityHashCode: false);
Expect.equals(i1.hashCode, hash(i1));
Expect.equals(i2.hashCode, hash(i2));
}
@@ -52,7 +55,7 @@ ints() {
lists() {
var list1 = [];
var list2 = [];
- check(list1, list2);
+ check(list1, list2, identityHashCode: true);
Expect.equals(list1.hashCode, hash(list1));
Expect.equals(list2.hashCode, hash(list2));
@@ -62,9 +65,9 @@ strings() {
var str1 = 'a';
var str2 = 'b';
var str3 = 'c';
- check(str1, str2);
- check(str1, str3);
- check(str2, str3);
+ check(str1, str2, identityHashCode: false);
+ check(str1, str3, identityHashCode: false);
+ check(str2, str3, identityHashCode: false);
Expect.equals(str1.hashCode, hash(str1));
Expect.equals(str2.hashCode, hash(str2));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698