From 694103d549235d8b92e69ad8e41f0c9308bdb4d2 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Sun, 7 Jun 2020 11:48:45 +0000 Subject: [PATCH] Bug 1643680 part 3 - Add a test. r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D78515 --- js/src/jit-test/tests/cacheir/math-min-max.js | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 js/src/jit-test/tests/cacheir/math-min-max.js diff --git a/js/src/jit-test/tests/cacheir/math-min-max.js b/js/src/jit-test/tests/cacheir/math-min-max.js new file mode 100644 index 000000000000..b7b9fbe86adb --- /dev/null +++ b/js/src/jit-test/tests/cacheir/math-min-max.js @@ -0,0 +1,180 @@ +function test1ArgInt32() { + function test(x, expected) { + assertEq(Math.max(x), expected); + assertEq(Math.min(x), expected); + } + for (var i = 0; i < 20; i++) { + test(i, i); + } + // Fail Int32 guard. + test(true, 1); + test({}, NaN); +} +test1ArgInt32(); + +function test1ArgNumber() { + function test(x, expected) { + assertEq(Math.max(x), expected); + assertEq(Math.min(x), expected); + } + for (var i = 0; i < 20; i++) { + test(3.14, 3.14); + test(-0, -0); + test(i, i); + } + // Fail Number guard. + test(true, 1); + test({}, NaN); +} +test1ArgNumber(); + +function test1ArgInt32ThenNumber() { + function test(x, expected) { + assertEq(Math.max(x), expected); + assertEq(Math.min(x), expected); + } + for (var i = 0; i < 20; i++) { + test(i, i); + } + for (var i = 0; i < 10; i++) { + test(i * 3.14, i * 3.14); + } +} +test1ArgInt32ThenNumber(); + +function test2ArgsInt32() { + function test(x, y, expectedMax, expectedMin) { + assertEq(Math.max(x, y), expectedMax); + assertEq(Math.min(x, y), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(0, i, i, 0); + test(-9, -1, -1, -9); + test(0, 0, 0, 0); + } + // Fail Int32 guard. + test(0, "3", 3, 0); + test({}, 2, NaN, NaN); +} +test2ArgsInt32(); + +function test2ArgsNumber() { + function test(x, y, expectedMax, expectedMin) { + assertEq(Math.max(x, y), expectedMax); + assertEq(Math.min(x, y), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(1.1, 2.2, 2.2, 1.1); + test(8, NaN, NaN, NaN); + test(NaN, 8, NaN, NaN); + test(-0, i, i, -0); + test(Infinity, -0, Infinity, -0); + test(-Infinity, Infinity, Infinity, -Infinity); + } + // Fail Number guard. + test(-0, "3", 3, -0); + test({}, 2.1, NaN, NaN); +} +test2ArgsNumber(); + +function test2ArgsInt32ThenNumber() { + function test(x, y, expectedMax, expectedMin) { + assertEq(Math.max(x, y), expectedMax); + assertEq(Math.min(x, y), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(-1, i, i, -1); + } + for (var i = 0; i < 10; i++) { + test(-0, i, i, -0); + } +} +test2ArgsInt32ThenNumber(); + +function test3ArgsInt32() { + function test(a, b, c, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c), expectedMax); + assertEq(Math.min(a, b, c), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(30, 100, i, 100, i); + test(i, 0, -2, i, -2); + } + // Fail Int32 guard. + test(0, 1, "2", 2, 0); + test(-0, 1, 2, 2, -0); +} +test3ArgsInt32(); + +function test3ArgsNumber() { + function test(a, b, c, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c), expectedMax); + assertEq(Math.min(a, b, c), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(100, i, -0, 100, -0); + test(i, NaN, -1, NaN, NaN); + } + // Fail Number guard. + test(-0, "3", 1, 3, -0); + test("9", 1.1, 3, 9, 1.1); +} +test3ArgsNumber(); + +function test3ArgsInt32ThenNumber() { + function test(a, b, c, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c), expectedMax); + assertEq(Math.min(a, b, c), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(30, 100, i, 100, i); + } + for (var i = 0; i < 10; i++) { + test(123.4, 100, i, 123.4, i); + } +} +test3ArgsInt32ThenNumber(); + +function test4ArgsInt32() { + function test(a, b, c, d, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c, d), expectedMax); + assertEq(Math.min(a, b, c, d), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(30, 100, i, 0, 100, 0); + test(i, 0, -1, -2, i, -2); + } + // Fail Int32 guard. + test(0, 1, 2, "3", 3, 0); + test(-0, 1, 2, 3, 3, -0); +} +test4ArgsInt32(); + +function test4ArgsNumber() { + function test(a, b, c, d, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c, d), expectedMax); + assertEq(Math.min(a, b, c, d), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(3.1, 100, i, -0, 100, -0); + test(i, NaN, -1, -2, NaN, NaN); + } + // Fail Number guard. + test(-0, 1, 2, "3", 3, -0); + test("9", 1.1, 2, 3, 9, 1.1); +} +test4ArgsNumber(); + +function test4ArgsInt32ThenNumber() { + function test(a, b, c, d, expectedMax, expectedMin) { + assertEq(Math.max(a, b, c, d), expectedMax); + assertEq(Math.min(a, b, c, d), expectedMin); + } + for (var i = 0; i < 20; i++) { + test(i << 1, i - 100, -1, -2, i * 2, i - 100); + } + for (var i = 0; i < 10; i++) { + test(i * 1.1, i, -0, 0, i * 1.1, -0); + } +} +test4ArgsInt32ThenNumber();