Commit 0c6fbad8 authored by lrn@chromium.org's avatar lrn@chromium.org

Add more tests to mul-exhaustive for constant left/right operands.

Make MJSUnit able to distinguish 0 and -0.

Review URL: http://codereview.chromium.org/6688062

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7368 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 94c1058b
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
function test(expected_sqrt, value) { function test(expected_sqrt, value) {
assertEquals(expected_sqrt, Math.sqrt(value)); assertEquals(expected_sqrt, Math.sqrt(value));
if (isFinite(value)) { if (isFinite(value)) {
if ((1 / value) != -Infinity) {
// Math.pow(-0, 0.5) must be zero, but Math.sqrt(-0) is -0.
expected_sqrt = 0;
}
assertEquals(expected_sqrt, Math.pow(value, 0.5)); assertEquals(expected_sqrt, Math.pow(value, 0.5));
} }
} }
......
...@@ -41,15 +41,62 @@ MjsUnitAssertionError.prototype.toString = function () { ...@@ -41,15 +41,62 @@ MjsUnitAssertionError.prototype.toString = function () {
* the f-word and ignore all other lines. * the f-word and ignore all other lines.
*/ */
function MjsUnitToString(value) {
switch (typeof value) {
case "string":
return JSON.stringify(value);
case "number":
if (value === 0 && (1 / value) < 0) return "-0";
case "boolean":
case "null":
case "undefined":
case "function":
return String(value);
case "object":
if (value === null) return "null";
var clazz = Object.prototype.toString.call(value);
clazz = clazz.substring(8, clazz.length - 1);
switch (clazz) {
case "Number":
case "String":
case "Boolean":
case "Date":
return clazz + "(" + MjsUnitToString(value.valueOf()) + ")";
case "RegExp":
return value.toString();
case "Array":
return "[" + value.map(MjsUnitArrayElementToString).join(",") + "]";
case "Object":
break;
default:
return clazz + "()";
}
// [[Class]] is "Object".
var constructor = value.constructor.name;
if (name) return name + "()";
return "Object()";
default:
return "-- unknown value --";
}
}
function MjsUnitArrayElementToString(value, index, array) {
if (value === undefined && !(index in array)) return "";
return MjsUnitToString(value);
}
function fail(expected, found, name_opt) { function fail(expected, found, name_opt) {
var start; var message = "Fail" + "ure";
if (name_opt) { if (name_opt) {
// Fix this when we ditch the old test runner. // Fix this when we ditch the old test runner.
start = "Fail" + "ure (" + name_opt + "): "; message += " (" + name_opt + ")";
} else {
start = "Fail" + "ure:";
} }
throw new MjsUnitAssertionError(start + " expected <" + expected + "> found <" + found + ">");
message += ": expected <" + MjsUnitToString(expected) +
"> found <" + MjsUnitToString(found) + ">";
throw new MjsUnitAssertionError(message);
} }
...@@ -73,13 +120,17 @@ function deepObjectEquals(a, b) { ...@@ -73,13 +120,17 @@ function deepObjectEquals(a, b) {
function deepEquals(a, b) { function deepEquals(a, b) {
if (a == b) return true; if (a == b) {
// Check for -0.
if (a === 0 && b === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a == "number" && typeof b == "number" && isNaN(a) && isNaN(b)) { if (typeof a == "number" && typeof b == "number" && isNaN(a) && isNaN(b)) {
return true; return true;
} }
if (a == null || b == null) return false; if (a == null || b == null) return false;
if (a.constructor === RegExp || b.constructor === RegExp) { if (a.constructor === RegExp || b.constructor === RegExp) {
return (a.constructor === b.constructor) && (a.toString === b.toString); return (a.constructor === b.constructor) && (a.toString() === b.toString());
} }
if ((typeof a) !== 'object' || (typeof b) !== 'object' || if ((typeof a) !== 'object' || (typeof b) !== 'object' ||
(a === null) || (b === null)) (a === null) || (b === null))
...@@ -205,7 +256,7 @@ function assertDoesNotThrow(code) { ...@@ -205,7 +256,7 @@ function assertDoesNotThrow(code) {
function assertUnreachable(name_opt) { function assertUnreachable(name_opt) {
// Fix this when we ditch the old test runner. // Fix this when we ditch the old test runner.
var message = "Fail" + "ure: unreachable" var message = "Fail" + "ure: unreachable";
if (name_opt) { if (name_opt) {
message += " - " + name_opt; message += " - " + name_opt;
} }
......
This diff is collapsed.
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function IsNegativeZero(x) { function IsNegativeZero(x) {
assertEquals(0, x); assertTrue(x == 0); // Is 0 or -0.
var y = 1 / x; var y = 1 / x;
assertFalse(isFinite(y)); assertFalse(isFinite(y));
return y < 0; return y < 0;
......
...@@ -109,5 +109,5 @@ function foo(x) { ...@@ -109,5 +109,5 @@ function foo(x) {
return -x; return -x;
} }
assertEquals(0, foo(x)); assertEquals(-0, foo(x));
assertEquals(0, foo(x)); assertEquals(-0, foo(x));
...@@ -190,7 +190,7 @@ assertEquals(100, toNumber("000100")); ...@@ -190,7 +190,7 @@ assertEquals(100, toNumber("000100"));
assertEquals(Infinity, toNumber("1e999"), "1e999"); assertEquals(Infinity, toNumber("1e999"), "1e999");
assertEquals(-Infinity, toNumber("-1e999")); assertEquals(-Infinity, toNumber("-1e999"));
assertEquals(0, toNumber("1e-999")); assertEquals(0, toNumber("1e-999"));
assertEquals(0, toNumber("-1e-999")); assertEquals(-0, toNumber("-1e-999"));
assertEquals(Infinity, 1 / toNumber("1e-999"), "1e-999"); assertEquals(Infinity, 1 / toNumber("1e-999"), "1e-999");
assertEquals(-Infinity, 1 / toNumber("-1e-999")); assertEquals(-Infinity, 1 / toNumber("-1e-999"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment