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

Unified Diff: tests/language/arithmetic_canonicalization_test.dart

Issue 11773040: Canonicalize away simple arithmetic equivalences. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test, address comments Created 7 years, 11 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 | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/arithmetic_canonicalization_test.dart
diff --git a/tests/language/arithmetic_canonicalization_test.dart b/tests/language/arithmetic_canonicalization_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cf87e9e68eb9f7ac488a0f35b9f8b5c582888de3
--- /dev/null
+++ b/tests/language/arithmetic_canonicalization_test.dart
@@ -0,0 +1,36 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// Test canonicalization of simple arithmetic equivalences.
+
+main() {
+ for (var i = 0; i < 5000; i++) {
+ Expect.isTrue(mul1double(i) is double);
+ Expect.equals(i.toDouble(), mul1double(i));
+ Expect.equals(0.0, mul0double(i));
+ Expect.equals(i.toDouble(), add0double(i));
+
+ Expect.equals(i, mul1int(i));
+ Expect.equals(i, add0int(i));
+ Expect.equals(0, mul0int(i));
+ Expect.equals(0, and0(i));
+ Expect.equals(i, and1(i));
+ Expect.equals(i, or0(i));
+ Expect.equals(i, xor0(i));
+ }
+
+ Expect.isTrue(mul0double(double.NAN).isNaN);
+ Expect.isFalse(add0double(-0.0).isNegative);
+}
+
+mul1double(x) => 1.0 * x;
+mul0double(x) => 0.0 * x;
+add0double(x) => 0.0 + x;
+
+mul1int(x) => 1 * x;
+mul0int(x) => 0 * x;
+add0int(x) => 0 + x;
+and0(x) => 0 & x;
+or0(x) => 0 | x;
+xor0(x) => 0 ^ x;
+and1(x) => (-1) & x;
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698