diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/cacheir/math-min-max.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/cacheir/math-min-max.js')
-rw-r--r-- | js/src/jit-test/tests/cacheir/math-min-max.js | 180 |
1 files changed, 180 insertions, 0 deletions
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 0000000000..b7b9fbe86a --- /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(); |