Add more exhaustive tests for Math.min and Math.max.
R=mstarzinger@chromium.org BUG= Review URL: https://codereview.chromium.org/1078073002 Cr-Commit-Position: refs/heads/master@{#27747}
This commit is contained in:
parent
7667d19eec
commit
dee044d601
@ -127,6 +127,10 @@
|
||||
'debug-stepout-scope-part3': [PASS, NO_VARIANTS],
|
||||
'es6/debug-evaluate-blockscopes': [PASS, NO_VARIANTS],
|
||||
|
||||
# TODO(titzer): --always-opt incorrectly disables CrankShaft soft deopt points
|
||||
'result-table-min': [PASS, NO_VARIANTS],
|
||||
'result-table-max': [PASS, NO_VARIANTS],
|
||||
|
||||
##############################################################################
|
||||
# Too slow in debug mode with --stress-opt mode.
|
||||
'compiler/regress-stacktrace-methods': [PASS, ['mode == debug', SKIP]],
|
||||
|
105
test/mjsunit/result-table-max.js
Normal file
105
test/mjsunit/result-table-max.js
Normal file
@ -0,0 +1,105 @@
|
||||
// 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.
|
||||
|
||||
var values = [true,false,null,void 0,0,0.0,-0,"",-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN];
|
||||
var expected = [
|
||||
[1,1,1,NaN,1,1,1,1,1,1,1,1.25,1,2147483648,Infinity,1,NaN],
|
||||
[1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
|
||||
[1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
|
||||
[NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN],
|
||||
[1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
|
||||
[1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-0,-0,1,1.25,-0,2147483648,Infinity,-0,NaN],
|
||||
[1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1,1,1.25,-1,2147483648,Infinity,-1,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-1.25,2147483648,Infinity,-1.25,NaN],
|
||||
[1,1,1,NaN,1,1,1,1,1,1,1,1.25,1,2147483648,Infinity,1,NaN],
|
||||
[1.25,1.25,1.25,NaN,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,2147483648,Infinity,1.25,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-2147483648,NaN],
|
||||
[2147483648,2147483648,2147483648,NaN,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,Infinity,2147483648,NaN],
|
||||
[Infinity,Infinity,Infinity,NaN,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN],
|
||||
[NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]
|
||||
];
|
||||
var func = (function max(a,b) { return Math.max(a, b); });
|
||||
var left_funcs = [
|
||||
(function max_L0(b) { return Math.max(true, b); }),
|
||||
(function max_L1(b) { return Math.max(false, b); }),
|
||||
(function max_L2(b) { return Math.max(null, b); }),
|
||||
(function max_L3(b) { return Math.max(void 0, b); }),
|
||||
(function max_L4(b) { return Math.max(0, b); }),
|
||||
(function max_L5(b) { return Math.max(0.0, b); }),
|
||||
(function max_L6(b) { return Math.max(-0, b); }),
|
||||
(function max_L7(b) { return Math.max("", b); }),
|
||||
(function max_L8(b) { return Math.max(-1, b); }),
|
||||
(function max_L9(b) { return Math.max(-1.25, b); }),
|
||||
(function max_L10(b) { return Math.max(1, b); }),
|
||||
(function max_L11(b) { return Math.max(1.25, b); }),
|
||||
(function max_L12(b) { return Math.max(-2147483648, b); }),
|
||||
(function max_L13(b) { return Math.max(2147483648, b); }),
|
||||
(function max_L14(b) { return Math.max(Infinity, b); }),
|
||||
(function max_L15(b) { return Math.max(-Infinity, b); }),
|
||||
(function max_L16(b) { return Math.max(NaN, b); })
|
||||
];
|
||||
var right_funcs = [
|
||||
(function max_R0(a) { return Math.max(a, true); }),
|
||||
(function max_R1(a) { return Math.max(a, false); }),
|
||||
(function max_R2(a) { return Math.max(a, null); }),
|
||||
(function max_R3(a) { return Math.max(a, void 0); }),
|
||||
(function max_R4(a) { return Math.max(a, 0); }),
|
||||
(function max_R5(a) { return Math.max(a, 0.0); }),
|
||||
(function max_R6(a) { return Math.max(a, -0); }),
|
||||
(function max_R7(a) { return Math.max(a, ""); }),
|
||||
(function max_R8(a) { return Math.max(a, -1); }),
|
||||
(function max_R9(a) { return Math.max(a, -1.25); }),
|
||||
(function max_R10(a) { return Math.max(a, 1); }),
|
||||
(function max_R11(a) { return Math.max(a, 1.25); }),
|
||||
(function max_R12(a) { return Math.max(a, -2147483648); }),
|
||||
(function max_R13(a) { return Math.max(a, 2147483648); }),
|
||||
(function max_R14(a) { return Math.max(a, Infinity); }),
|
||||
(function max_R15(a) { return Math.max(a, -Infinity); }),
|
||||
(function max_R16(a) { return Math.max(a, NaN); })
|
||||
];
|
||||
function matrix() {
|
||||
return [
|
||||
[Math.max(true, true),Math.max(true, false),Math.max(true, null),Math.max(true, void 0),Math.max(true, 0),Math.max(true, 0.0),Math.max(true, -0),Math.max(true, ""),Math.max(true, -1),Math.max(true, -1.25),Math.max(true, 1),Math.max(true, 1.25),Math.max(true, -2147483648),Math.max(true, 2147483648),Math.max(true, Infinity),Math.max(true, -Infinity),Math.max(true, NaN)],
|
||||
[Math.max(false, true),Math.max(false, false),Math.max(false, null),Math.max(false, void 0),Math.max(false, 0),Math.max(false, 0.0),Math.max(false, -0),Math.max(false, ""),Math.max(false, -1),Math.max(false, -1.25),Math.max(false, 1),Math.max(false, 1.25),Math.max(false, -2147483648),Math.max(false, 2147483648),Math.max(false, Infinity),Math.max(false, -Infinity),Math.max(false, NaN)],
|
||||
[Math.max(null, true),Math.max(null, false),Math.max(null, null),Math.max(null, void 0),Math.max(null, 0),Math.max(null, 0.0),Math.max(null, -0),Math.max(null, ""),Math.max(null, -1),Math.max(null, -1.25),Math.max(null, 1),Math.max(null, 1.25),Math.max(null, -2147483648),Math.max(null, 2147483648),Math.max(null, Infinity),Math.max(null, -Infinity),Math.max(null, NaN)],
|
||||
[Math.max(void 0, true),Math.max(void 0, false),Math.max(void 0, null),Math.max(void 0, void 0),Math.max(void 0, 0),Math.max(void 0, 0.0),Math.max(void 0, -0),Math.max(void 0, ""),Math.max(void 0, -1),Math.max(void 0, -1.25),Math.max(void 0, 1),Math.max(void 0, 1.25),Math.max(void 0, -2147483648),Math.max(void 0, 2147483648),Math.max(void 0, Infinity),Math.max(void 0, -Infinity),Math.max(void 0, NaN)],
|
||||
[Math.max(0, true),Math.max(0, false),Math.max(0, null),Math.max(0, void 0),Math.max(0, 0),Math.max(0, 0.0),Math.max(0, -0),Math.max(0, ""),Math.max(0, -1),Math.max(0, -1.25),Math.max(0, 1),Math.max(0, 1.25),Math.max(0, -2147483648),Math.max(0, 2147483648),Math.max(0, Infinity),Math.max(0, -Infinity),Math.max(0, NaN)],
|
||||
[Math.max(0.0, true),Math.max(0.0, false),Math.max(0.0, null),Math.max(0.0, void 0),Math.max(0.0, 0),Math.max(0.0, 0.0),Math.max(0.0, -0),Math.max(0.0, ""),Math.max(0.0, -1),Math.max(0.0, -1.25),Math.max(0.0, 1),Math.max(0.0, 1.25),Math.max(0.0, -2147483648),Math.max(0.0, 2147483648),Math.max(0.0, Infinity),Math.max(0.0, -Infinity),Math.max(0.0, NaN)],
|
||||
[Math.max(-0, true),Math.max(-0, false),Math.max(-0, null),Math.max(-0, void 0),Math.max(-0, 0),Math.max(-0, 0.0),Math.max(-0, -0),Math.max(-0, ""),Math.max(-0, -1),Math.max(-0, -1.25),Math.max(-0, 1),Math.max(-0, 1.25),Math.max(-0, -2147483648),Math.max(-0, 2147483648),Math.max(-0, Infinity),Math.max(-0, -Infinity),Math.max(-0, NaN)],
|
||||
[Math.max("", true),Math.max("", false),Math.max("", null),Math.max("", void 0),Math.max("", 0),Math.max("", 0.0),Math.max("", -0),Math.max("", ""),Math.max("", -1),Math.max("", -1.25),Math.max("", 1),Math.max("", 1.25),Math.max("", -2147483648),Math.max("", 2147483648),Math.max("", Infinity),Math.max("", -Infinity),Math.max("", NaN)],
|
||||
[Math.max(-1, true),Math.max(-1, false),Math.max(-1, null),Math.max(-1, void 0),Math.max(-1, 0),Math.max(-1, 0.0),Math.max(-1, -0),Math.max(-1, ""),Math.max(-1, -1),Math.max(-1, -1.25),Math.max(-1, 1),Math.max(-1, 1.25),Math.max(-1, -2147483648),Math.max(-1, 2147483648),Math.max(-1, Infinity),Math.max(-1, -Infinity),Math.max(-1, NaN)],
|
||||
[Math.max(-1.25, true),Math.max(-1.25, false),Math.max(-1.25, null),Math.max(-1.25, void 0),Math.max(-1.25, 0),Math.max(-1.25, 0.0),Math.max(-1.25, -0),Math.max(-1.25, ""),Math.max(-1.25, -1),Math.max(-1.25, -1.25),Math.max(-1.25, 1),Math.max(-1.25, 1.25),Math.max(-1.25, -2147483648),Math.max(-1.25, 2147483648),Math.max(-1.25, Infinity),Math.max(-1.25, -Infinity),Math.max(-1.25, NaN)],
|
||||
[Math.max(1, true),Math.max(1, false),Math.max(1, null),Math.max(1, void 0),Math.max(1, 0),Math.max(1, 0.0),Math.max(1, -0),Math.max(1, ""),Math.max(1, -1),Math.max(1, -1.25),Math.max(1, 1),Math.max(1, 1.25),Math.max(1, -2147483648),Math.max(1, 2147483648),Math.max(1, Infinity),Math.max(1, -Infinity),Math.max(1, NaN)],
|
||||
[Math.max(1.25, true),Math.max(1.25, false),Math.max(1.25, null),Math.max(1.25, void 0),Math.max(1.25, 0),Math.max(1.25, 0.0),Math.max(1.25, -0),Math.max(1.25, ""),Math.max(1.25, -1),Math.max(1.25, -1.25),Math.max(1.25, 1),Math.max(1.25, 1.25),Math.max(1.25, -2147483648),Math.max(1.25, 2147483648),Math.max(1.25, Infinity),Math.max(1.25, -Infinity),Math.max(1.25, NaN)],
|
||||
[Math.max(-2147483648, true),Math.max(-2147483648, false),Math.max(-2147483648, null),Math.max(-2147483648, void 0),Math.max(-2147483648, 0),Math.max(-2147483648, 0.0),Math.max(-2147483648, -0),Math.max(-2147483648, ""),Math.max(-2147483648, -1),Math.max(-2147483648, -1.25),Math.max(-2147483648, 1),Math.max(-2147483648, 1.25),Math.max(-2147483648, -2147483648),Math.max(-2147483648, 2147483648),Math.max(-2147483648, Infinity),Math.max(-2147483648, -Infinity),Math.max(-2147483648, NaN)],
|
||||
[Math.max(2147483648, true),Math.max(2147483648, false),Math.max(2147483648, null),Math.max(2147483648, void 0),Math.max(2147483648, 0),Math.max(2147483648, 0.0),Math.max(2147483648, -0),Math.max(2147483648, ""),Math.max(2147483648, -1),Math.max(2147483648, -1.25),Math.max(2147483648, 1),Math.max(2147483648, 1.25),Math.max(2147483648, -2147483648),Math.max(2147483648, 2147483648),Math.max(2147483648, Infinity),Math.max(2147483648, -Infinity),Math.max(2147483648, NaN)],
|
||||
[Math.max(Infinity, true),Math.max(Infinity, false),Math.max(Infinity, null),Math.max(Infinity, void 0),Math.max(Infinity, 0),Math.max(Infinity, 0.0),Math.max(Infinity, -0),Math.max(Infinity, ""),Math.max(Infinity, -1),Math.max(Infinity, -1.25),Math.max(Infinity, 1),Math.max(Infinity, 1.25),Math.max(Infinity, -2147483648),Math.max(Infinity, 2147483648),Math.max(Infinity, Infinity),Math.max(Infinity, -Infinity),Math.max(Infinity, NaN)],
|
||||
[Math.max(-Infinity, true),Math.max(-Infinity, false),Math.max(-Infinity, null),Math.max(-Infinity, void 0),Math.max(-Infinity, 0),Math.max(-Infinity, 0.0),Math.max(-Infinity, -0),Math.max(-Infinity, ""),Math.max(-Infinity, -1),Math.max(-Infinity, -1.25),Math.max(-Infinity, 1),Math.max(-Infinity, 1.25),Math.max(-Infinity, -2147483648),Math.max(-Infinity, 2147483648),Math.max(-Infinity, Infinity),Math.max(-Infinity, -Infinity),Math.max(-Infinity, NaN)],
|
||||
[Math.max(NaN, true),Math.max(NaN, false),Math.max(NaN, null),Math.max(NaN, void 0),Math.max(NaN, 0),Math.max(NaN, 0.0),Math.max(NaN, -0),Math.max(NaN, ""),Math.max(NaN, -1),Math.max(NaN, -1.25),Math.max(NaN, 1),Math.max(NaN, 1.25),Math.max(NaN, -2147483648),Math.max(NaN, 2147483648),Math.max(NaN, Infinity),Math.max(NaN, -Infinity),Math.max(NaN, NaN)]
|
||||
];
|
||||
}
|
||||
function test() {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var a = values[i];
|
||||
var b = values[j];
|
||||
var x = expected[i][j];
|
||||
assertEquals(x, func(a,b));
|
||||
assertEquals(x, left_funcs[i](b));
|
||||
assertEquals(x, right_funcs[j](a));
|
||||
}
|
||||
}
|
||||
|
||||
var result = matrix();
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
assertEquals(expected[i][j], result[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
test();
|
||||
test();
|
105
test/mjsunit/result-table-min.js
vendored
Normal file
105
test/mjsunit/result-table-min.js
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
// 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.
|
||||
|
||||
var values = [true,false,null,void 0,0,0.0,-0,"",-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN];
|
||||
var expected = [
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1,-2147483648,1,1,-Infinity,NaN],
|
||||
[0,0,0,NaN,0,0,-0,0,-1,-1.25,0,0,-2147483648,0,0,-Infinity,NaN],
|
||||
[0,0,0,NaN,0,0,-0,0,-1,-1.25,0,0,-2147483648,0,0,-Infinity,NaN],
|
||||
[NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN],
|
||||
[0,0,0,NaN,0,0,-0,0,-1,-1.25,0,0,-2147483648,0,0,-Infinity,NaN],
|
||||
[0,0,0,NaN,0,0,-0,0,-1,-1.25,0,0,-2147483648,0,0,-Infinity,NaN],
|
||||
[-0,-0,-0,NaN,-0,-0,-0,-0,-1,-1.25,-0,-0,-2147483648,-0,-0,-Infinity,NaN],
|
||||
[0,0,0,NaN,0,0,-0,0,-1,-1.25,0,0,-2147483648,0,0,-Infinity,NaN],
|
||||
[-1,-1,-1,NaN,-1,-1,-1,-1,-1,-1.25,-1,-1,-2147483648,-1,-1,-Infinity,NaN],
|
||||
[-1.25,-1.25,-1.25,NaN,-1.25,-1.25,-1.25,-1.25,-1.25,-1.25,-1.25,-1.25,-2147483648,-1.25,-1.25,-Infinity,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1,-2147483648,1,1,-Infinity,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,1.25,1.25,-Infinity,NaN],
|
||||
[-2147483648,-2147483648,-2147483648,NaN,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-2147483648,-Infinity,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,2147483648,-Infinity,NaN],
|
||||
[1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN],
|
||||
[-Infinity,-Infinity,-Infinity,NaN,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,-Infinity,NaN],
|
||||
[NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]
|
||||
];
|
||||
var func = (function min(a,b) { return Math.min(a, b); });
|
||||
var left_funcs = [
|
||||
(function min_L0(b) { return Math.min(true, b); }),
|
||||
(function min_L1(b) { return Math.min(false, b); }),
|
||||
(function min_L2(b) { return Math.min(null, b); }),
|
||||
(function min_L3(b) { return Math.min(void 0, b); }),
|
||||
(function min_L4(b) { return Math.min(0, b); }),
|
||||
(function min_L5(b) { return Math.min(0.0, b); }),
|
||||
(function min_L6(b) { return Math.min(-0, b); }),
|
||||
(function min_L7(b) { return Math.min("", b); }),
|
||||
(function min_L8(b) { return Math.min(-1, b); }),
|
||||
(function min_L9(b) { return Math.min(-1.25, b); }),
|
||||
(function min_L10(b) { return Math.min(1, b); }),
|
||||
(function min_L11(b) { return Math.min(1.25, b); }),
|
||||
(function min_L12(b) { return Math.min(-2147483648, b); }),
|
||||
(function min_L13(b) { return Math.min(2147483648, b); }),
|
||||
(function min_L14(b) { return Math.min(Infinity, b); }),
|
||||
(function min_L15(b) { return Math.min(-Infinity, b); }),
|
||||
(function min_L16(b) { return Math.min(NaN, b); })
|
||||
];
|
||||
var right_funcs = [
|
||||
(function min_R0(a) { return Math.min(a, true); }),
|
||||
(function min_R1(a) { return Math.min(a, false); }),
|
||||
(function min_R2(a) { return Math.min(a, null); }),
|
||||
(function min_R3(a) { return Math.min(a, void 0); }),
|
||||
(function min_R4(a) { return Math.min(a, 0); }),
|
||||
(function min_R5(a) { return Math.min(a, 0.0); }),
|
||||
(function min_R6(a) { return Math.min(a, -0); }),
|
||||
(function min_R7(a) { return Math.min(a, ""); }),
|
||||
(function min_R8(a) { return Math.min(a, -1); }),
|
||||
(function min_R9(a) { return Math.min(a, -1.25); }),
|
||||
(function min_R10(a) { return Math.min(a, 1); }),
|
||||
(function min_R11(a) { return Math.min(a, 1.25); }),
|
||||
(function min_R12(a) { return Math.min(a, -2147483648); }),
|
||||
(function min_R13(a) { return Math.min(a, 2147483648); }),
|
||||
(function min_R14(a) { return Math.min(a, Infinity); }),
|
||||
(function min_R15(a) { return Math.min(a, -Infinity); }),
|
||||
(function min_R16(a) { return Math.min(a, NaN); })
|
||||
];
|
||||
function matrix() {
|
||||
return [
|
||||
[Math.min(true, true),Math.min(true, false),Math.min(true, null),Math.min(true, void 0),Math.min(true, 0),Math.min(true, 0.0),Math.min(true, -0),Math.min(true, ""),Math.min(true, -1),Math.min(true, -1.25),Math.min(true, 1),Math.min(true, 1.25),Math.min(true, -2147483648),Math.min(true, 2147483648),Math.min(true, Infinity),Math.min(true, -Infinity),Math.min(true, NaN)],
|
||||
[Math.min(false, true),Math.min(false, false),Math.min(false, null),Math.min(false, void 0),Math.min(false, 0),Math.min(false, 0.0),Math.min(false, -0),Math.min(false, ""),Math.min(false, -1),Math.min(false, -1.25),Math.min(false, 1),Math.min(false, 1.25),Math.min(false, -2147483648),Math.min(false, 2147483648),Math.min(false, Infinity),Math.min(false, -Infinity),Math.min(false, NaN)],
|
||||
[Math.min(null, true),Math.min(null, false),Math.min(null, null),Math.min(null, void 0),Math.min(null, 0),Math.min(null, 0.0),Math.min(null, -0),Math.min(null, ""),Math.min(null, -1),Math.min(null, -1.25),Math.min(null, 1),Math.min(null, 1.25),Math.min(null, -2147483648),Math.min(null, 2147483648),Math.min(null, Infinity),Math.min(null, -Infinity),Math.min(null, NaN)],
|
||||
[Math.min(void 0, true),Math.min(void 0, false),Math.min(void 0, null),Math.min(void 0, void 0),Math.min(void 0, 0),Math.min(void 0, 0.0),Math.min(void 0, -0),Math.min(void 0, ""),Math.min(void 0, -1),Math.min(void 0, -1.25),Math.min(void 0, 1),Math.min(void 0, 1.25),Math.min(void 0, -2147483648),Math.min(void 0, 2147483648),Math.min(void 0, Infinity),Math.min(void 0, -Infinity),Math.min(void 0, NaN)],
|
||||
[Math.min(0, true),Math.min(0, false),Math.min(0, null),Math.min(0, void 0),Math.min(0, 0),Math.min(0, 0.0),Math.min(0, -0),Math.min(0, ""),Math.min(0, -1),Math.min(0, -1.25),Math.min(0, 1),Math.min(0, 1.25),Math.min(0, -2147483648),Math.min(0, 2147483648),Math.min(0, Infinity),Math.min(0, -Infinity),Math.min(0, NaN)],
|
||||
[Math.min(0.0, true),Math.min(0.0, false),Math.min(0.0, null),Math.min(0.0, void 0),Math.min(0.0, 0),Math.min(0.0, 0.0),Math.min(0.0, -0),Math.min(0.0, ""),Math.min(0.0, -1),Math.min(0.0, -1.25),Math.min(0.0, 1),Math.min(0.0, 1.25),Math.min(0.0, -2147483648),Math.min(0.0, 2147483648),Math.min(0.0, Infinity),Math.min(0.0, -Infinity),Math.min(0.0, NaN)],
|
||||
[Math.min(-0, true),Math.min(-0, false),Math.min(-0, null),Math.min(-0, void 0),Math.min(-0, 0),Math.min(-0, 0.0),Math.min(-0, -0),Math.min(-0, ""),Math.min(-0, -1),Math.min(-0, -1.25),Math.min(-0, 1),Math.min(-0, 1.25),Math.min(-0, -2147483648),Math.min(-0, 2147483648),Math.min(-0, Infinity),Math.min(-0, -Infinity),Math.min(-0, NaN)],
|
||||
[Math.min("", true),Math.min("", false),Math.min("", null),Math.min("", void 0),Math.min("", 0),Math.min("", 0.0),Math.min("", -0),Math.min("", ""),Math.min("", -1),Math.min("", -1.25),Math.min("", 1),Math.min("", 1.25),Math.min("", -2147483648),Math.min("", 2147483648),Math.min("", Infinity),Math.min("", -Infinity),Math.min("", NaN)],
|
||||
[Math.min(-1, true),Math.min(-1, false),Math.min(-1, null),Math.min(-1, void 0),Math.min(-1, 0),Math.min(-1, 0.0),Math.min(-1, -0),Math.min(-1, ""),Math.min(-1, -1),Math.min(-1, -1.25),Math.min(-1, 1),Math.min(-1, 1.25),Math.min(-1, -2147483648),Math.min(-1, 2147483648),Math.min(-1, Infinity),Math.min(-1, -Infinity),Math.min(-1, NaN)],
|
||||
[Math.min(-1.25, true),Math.min(-1.25, false),Math.min(-1.25, null),Math.min(-1.25, void 0),Math.min(-1.25, 0),Math.min(-1.25, 0.0),Math.min(-1.25, -0),Math.min(-1.25, ""),Math.min(-1.25, -1),Math.min(-1.25, -1.25),Math.min(-1.25, 1),Math.min(-1.25, 1.25),Math.min(-1.25, -2147483648),Math.min(-1.25, 2147483648),Math.min(-1.25, Infinity),Math.min(-1.25, -Infinity),Math.min(-1.25, NaN)],
|
||||
[Math.min(1, true),Math.min(1, false),Math.min(1, null),Math.min(1, void 0),Math.min(1, 0),Math.min(1, 0.0),Math.min(1, -0),Math.min(1, ""),Math.min(1, -1),Math.min(1, -1.25),Math.min(1, 1),Math.min(1, 1.25),Math.min(1, -2147483648),Math.min(1, 2147483648),Math.min(1, Infinity),Math.min(1, -Infinity),Math.min(1, NaN)],
|
||||
[Math.min(1.25, true),Math.min(1.25, false),Math.min(1.25, null),Math.min(1.25, void 0),Math.min(1.25, 0),Math.min(1.25, 0.0),Math.min(1.25, -0),Math.min(1.25, ""),Math.min(1.25, -1),Math.min(1.25, -1.25),Math.min(1.25, 1),Math.min(1.25, 1.25),Math.min(1.25, -2147483648),Math.min(1.25, 2147483648),Math.min(1.25, Infinity),Math.min(1.25, -Infinity),Math.min(1.25, NaN)],
|
||||
[Math.min(-2147483648, true),Math.min(-2147483648, false),Math.min(-2147483648, null),Math.min(-2147483648, void 0),Math.min(-2147483648, 0),Math.min(-2147483648, 0.0),Math.min(-2147483648, -0),Math.min(-2147483648, ""),Math.min(-2147483648, -1),Math.min(-2147483648, -1.25),Math.min(-2147483648, 1),Math.min(-2147483648, 1.25),Math.min(-2147483648, -2147483648),Math.min(-2147483648, 2147483648),Math.min(-2147483648, Infinity),Math.min(-2147483648, -Infinity),Math.min(-2147483648, NaN)],
|
||||
[Math.min(2147483648, true),Math.min(2147483648, false),Math.min(2147483648, null),Math.min(2147483648, void 0),Math.min(2147483648, 0),Math.min(2147483648, 0.0),Math.min(2147483648, -0),Math.min(2147483648, ""),Math.min(2147483648, -1),Math.min(2147483648, -1.25),Math.min(2147483648, 1),Math.min(2147483648, 1.25),Math.min(2147483648, -2147483648),Math.min(2147483648, 2147483648),Math.min(2147483648, Infinity),Math.min(2147483648, -Infinity),Math.min(2147483648, NaN)],
|
||||
[Math.min(Infinity, true),Math.min(Infinity, false),Math.min(Infinity, null),Math.min(Infinity, void 0),Math.min(Infinity, 0),Math.min(Infinity, 0.0),Math.min(Infinity, -0),Math.min(Infinity, ""),Math.min(Infinity, -1),Math.min(Infinity, -1.25),Math.min(Infinity, 1),Math.min(Infinity, 1.25),Math.min(Infinity, -2147483648),Math.min(Infinity, 2147483648),Math.min(Infinity, Infinity),Math.min(Infinity, -Infinity),Math.min(Infinity, NaN)],
|
||||
[Math.min(-Infinity, true),Math.min(-Infinity, false),Math.min(-Infinity, null),Math.min(-Infinity, void 0),Math.min(-Infinity, 0),Math.min(-Infinity, 0.0),Math.min(-Infinity, -0),Math.min(-Infinity, ""),Math.min(-Infinity, -1),Math.min(-Infinity, -1.25),Math.min(-Infinity, 1),Math.min(-Infinity, 1.25),Math.min(-Infinity, -2147483648),Math.min(-Infinity, 2147483648),Math.min(-Infinity, Infinity),Math.min(-Infinity, -Infinity),Math.min(-Infinity, NaN)],
|
||||
[Math.min(NaN, true),Math.min(NaN, false),Math.min(NaN, null),Math.min(NaN, void 0),Math.min(NaN, 0),Math.min(NaN, 0.0),Math.min(NaN, -0),Math.min(NaN, ""),Math.min(NaN, -1),Math.min(NaN, -1.25),Math.min(NaN, 1),Math.min(NaN, 1.25),Math.min(NaN, -2147483648),Math.min(NaN, 2147483648),Math.min(NaN, Infinity),Math.min(NaN, -Infinity),Math.min(NaN, NaN)]
|
||||
];
|
||||
}
|
||||
function test() {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var a = values[i];
|
||||
var b = values[j];
|
||||
var x = expected[i][j];
|
||||
assertEquals(x, func(a,b));
|
||||
assertEquals(x, left_funcs[i](b));
|
||||
assertEquals(x, right_funcs[j](a));
|
||||
}
|
||||
}
|
||||
|
||||
var result = matrix();
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
assertEquals(expected[i][j], result[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
test();
|
||||
test();
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user