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

Unified Diff: tools/compare-table-gen.js

Issue 1078073002: Add more exhaustive tests for Math.min and Math.max. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 | « test/mjsunit/result-table-min.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/compare-table-gen.js
diff --git a/tools/compare-table-gen.js b/tools/compare-table-gen.js
index 151be81517d6ad6dbf1c9ce858f5e8f125bc51b7..e0c870daa578a302567ce9e7342bb88f92439d30 100644
--- a/tools/compare-table-gen.js
+++ b/tools/compare-table-gen.js
@@ -1,5 +1,9 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
// Generates a comparison table test case.
-// Usage: d8 compare-table-gen.js -- lt|lteq|gt|gteq|eq|ne|eq|sne
+// Usage: d8 compare-table-gen.js -- lt|lteq|gt|gteq|eq|ne|eq|sne|min|max
var strings = ["true", "false", "null", "void 0", "0", "0.0", "-0", "\"\"", "-1", "-1.25", "1", "1.25", "-2147483648", "2147483648", "Infinity", "-Infinity", "NaN"];
var values = new Array(strings.length);
@@ -27,7 +31,16 @@ function test() {
}
}
-function gen(name, cmp) {
+function expr(infix, a, cmp, b) {
+ return infix ? a + " " + cmp + " " + b : cmp + "(" + a + ", " + b + ")";
+}
+
+function SpecialToString(x) {
+ if ((1 / x) == -Infinity) return "-0";
+ return "" + x;
+}
+
+function gen(name, cmp, infix) {
print("// Copyright 2015 the V8 project authors. All rights reserved.");
print("// Use of this source code is governed by a BSD-style license that can be");
@@ -35,7 +48,7 @@ function gen(name, cmp) {
print();
print("var values = [" + strings + "];");
- var body = "(function " + name + "(a,b) { return a " + cmp + " b; })";
+ var body = "(function " + name + "(a,b) { return " + expr(infix, "a", cmp, "b") + "; })";
var func = eval(body);
print("var expected = [");
@@ -44,7 +57,7 @@ function gen(name, cmp) {
var line = " [";
for (var j = 0; j < values.length; j++) {
if (j > 0) line += ",";
- line += func(values[i], values[j]) ? "true " : "false";
+ line += SpecialToString(func(values[i], values[j]));
}
line += "]";
if (i < (values.length - 1)) line += ",";
@@ -57,7 +70,7 @@ function gen(name, cmp) {
for (var i = 0; i < values.length; i++) {
var value = strings[i];
- var body = "(function " + name + "_L" + i + "(b) { return " + value + " " + cmp + " b; })";
+ var body = "(function " + name + "_L" + i + "(b) { return " + expr(infix, value, cmp, "b") + "; })";
var end = i < (values.length - 1) ? "," : "";
print(" " + body + end);
}
@@ -66,7 +79,7 @@ function gen(name, cmp) {
print("var right_funcs = [");
for (var i = 0; i < values.length; i++) {
var value = strings[i];
- var body = "(function " + name + "_R" + i + "(a) { return a " + cmp + " " + value + "; })";
+ var body = "(function " + name + "_R" + i + "(a) { return " + expr(infix, "a", cmp, value) + "; })";
var end = i < (values.length - 1) ? "," : "";
print(" " + body + end);
}
@@ -78,7 +91,7 @@ function gen(name, cmp) {
var line = " [";
for (var j = 0; j < values.length; j++) {
if (j > 0) line += ",";
- line += strings[i] + " " + cmp + " " + strings[j];
+ line += expr(infix, strings[i], cmp, strings[j]);
}
line += "]";
if (i < (values.length - 1)) line += ",";
@@ -91,18 +104,17 @@ function gen(name, cmp) {
print(test.toString());
print("test();");
print("test();");
-
- print();
- print();
}
switch (arguments[0]) {
- case "lt": gen("lt", "<"); break;
- case "lteq": gen("lteq", "<="); break;
- case "gt": gen("gt", ">"); break;
- case "gteq": gen("gteq", ">="); break;
- case "eq": gen("eq", "=="); break;
- case "ne": gen("ne", "!="); break;
- case "seq": gen("seq", "==="); break;
- case "sne": gen("sne", "!=="); break;
+ case "lt": gen("lt", "<", true); break;
+ case "lteq": gen("lteq", "<=", true); break;
+ case "gt": gen("gt", ">", true); break;
+ case "gteq": gen("gteq", ">=", true); break;
+ case "eq": gen("eq", "==", true); break;
+ case "ne": gen("ne", "!=", true); break;
+ case "seq": gen("seq", "===", true); break;
+ case "sne": gen("sne", "!==", true); break;
+ case "min": gen("min", "Math.min", false); break;
+ case "max": gen("max", "Math.max", false); break;
}
« no previous file with comments | « test/mjsunit/result-table-min.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698