Debian Codegraph @

js/src/jit-test/tests/cacheir/math-min-max.js

raw
1 function test1ArgInt32() {
2 function test(x, expected) {
3 assertEq(Math.max(x), expected);
4 assertEq(Math.min(x), expected);
5 }
6 for (var i = 0; i < 20; i++) {
7 test(i, i);
8 }
9 // Fail Int32 guard.
10 test(true, 1);
11 test({}, NaN);
12 }
13 test1ArgInt32();
14
15 function test1ArgNumber() {
16 function test(x, expected) {
17 assertEq(Math.max(x), expected);
18 assertEq(Math.min(x), expected);
19 }
20 for (var i = 0; i < 20; i++) {
21 test(3.14, 3.14);
22 test(-0, -0);
23 test(i, i);
24 }
25 // Fail Number guard.
26 test(true, 1);
27 test({}, NaN);
28 }
29 test1ArgNumber();
30
31 function test1ArgInt32ThenNumber() {
32 function test(x, expected) {
33 assertEq(Math.max(x), expected);
34 assertEq(Math.min(x), expected);
35 }
36 for (var i = 0; i < 20; i++) {
37 test(i, i);
38 }
39 for (var i = 0; i < 10; i++) {
40 test(i * 3.14, i * 3.14);
41 }
42 }
43 test1ArgInt32ThenNumber();
44
45 function test2ArgsInt32() {
46 function test(x, y, expectedMax, expectedMin) {
47 assertEq(Math.max(x, y), expectedMax);
48 assertEq(Math.min(x, y), expectedMin);
49 }
50 for (var i = 0; i < 20; i++) {
51 test(0, i, i, 0);
52 test(-9, -1, -1, -9);
53 test(0, 0, 0, 0);
54 }
55 // Fail Int32 guard.
56 test(0, "3", 3, 0);
57 test({}, 2, NaN, NaN);
58 }
59 test2ArgsInt32();
60
61 function test2ArgsNumber() {
62 function test(x, y, expectedMax, expectedMin) {
63 assertEq(Math.max(x, y), expectedMax);
64 assertEq(Math.min(x, y), expectedMin);
65 }
66 for (var i = 0; i < 20; i++) {
67 test(1.1, 2.2, 2.2, 1.1);
68 test(8, NaN, NaN, NaN);
69 test(NaN, 8, NaN, NaN);
70 test(-0, i, i, -0);
71 test(Infinity, -0, Infinity, -0);
72 test(-Infinity, Infinity, Infinity, -Infinity);
73 }
74 // Fail Number guard.
75 test(-0, "3", 3, -0);
76 test({}, 2.1, NaN, NaN);
77 }
78 test2ArgsNumber();
79
80 function test2ArgsInt32ThenNumber() {
81 function test(x, y, expectedMax, expectedMin) {
82 assertEq(Math.max(x, y), expectedMax);
83 assertEq(Math.min(x, y), expectedMin);
84 }
85 for (var i = 0; i < 20; i++) {
86 test(-1, i, i, -1);
87 }
88 for (var i = 0; i < 10; i++) {
89 test(-0, i, i, -0);
90 }
91 }
92 test2ArgsInt32ThenNumber();
93
94 function test3ArgsInt32() {
95 function test(a, b, c, expectedMax, expectedMin) {
96 assertEq(Math.max(a, b, c), expectedMax);
97 assertEq(Math.min(a, b, c), expectedMin);
98 }
99 for (var i = 0; i < 20; i++) {
100 test(30, 100, i, 100, i);
101 test(i, 0, -2, i, -2);
102 }
103 // Fail Int32 guard.
104 test(0, 1, "2", 2, 0);
105 test(-0, 1, 2, 2, -0);
106 }
107 test3ArgsInt32();
108
109 function test3ArgsNumber() {
110 function test(a, b, c, expectedMax, expectedMin) {
111 assertEq(Math.max(a, b, c), expectedMax);
112 assertEq(Math.min(a, b, c), expectedMin);
113 }
114 for (var i = 0; i < 20; i++) {
115 test(100, i, -0, 100, -0);
116 test(i, NaN, -1, NaN, NaN);
117 }
118 // Fail Number guard.
119 test(-0, "3", 1, 3, -0);
120 test("9", 1.1, 3, 9, 1.1);
121 }
122 test3ArgsNumber();
123
124 function test3ArgsInt32ThenNumber() {
125 function test(a, b, c, expectedMax, expectedMin) {
126 assertEq(Math.max(a, b, c), expectedMax);
127 assertEq(Math.min(a, b, c), expectedMin);
128 }
129 for (var i = 0; i < 20; i++) {
130 test(30, 100, i, 100, i);
131 }
132 for (var i = 0; i < 10; i++) {
133 test(123.4, 100, i, 123.4, i);
134 }
135 }
136 test3ArgsInt32ThenNumber();
137
138 function test4ArgsInt32() {
139 function test(a, b, c, d, expectedMax, expectedMin) {
140 assertEq(Math.max(a, b, c, d), expectedMax);
141 assertEq(Math.min(a, b, c, d), expectedMin);
142 }
143 for (var i = 0; i < 20; i++) {
144 test(30, 100, i, 0, 100, 0);
145 test(i, 0, -1, -2, i, -2);
146 }
147 // Fail Int32 guard.
148 test(0, 1, 2, "3", 3, 0);
149 test(-0, 1, 2, 3, 3, -0);
150 }
151 test4ArgsInt32();
152
153 function test4ArgsNumber() {
154 function test(a, b, c, d, expectedMax, expectedMin) {
155 assertEq(Math.max(a, b, c, d), expectedMax);
156 assertEq(Math.min(a, b, c, d), expectedMin);
157 }
158 for (var i = 0; i < 20; i++) {
159 test(3.1, 100, i, -0, 100, -0);
160 test(i, NaN, -1, -2, NaN, NaN);
161 }
162 // Fail Number guard.
163 test(-0, 1, 2, "3", 3, -0);
164 test("9", 1.1, 2, 3, 9, 1.1);
165 }
166 test4ArgsNumber();
167
168 function test4ArgsInt32ThenNumber() {
169 function test(a, b, c, d, expectedMax, expectedMin) {
170 assertEq(Math.max(a, b, c, d), expectedMax);
171 assertEq(Math.min(a, b, c, d), expectedMin);
172 }
173 for (var i = 0; i < 20; i++) {
174 test(i << 1, i - 100, -1, -2, i * 2, i - 100);
175 }
176 for (var i = 0; i < 10; i++) {
177 test(i * 1.1, i, -0, 0, i * 1.1, -0);
178 }
179 }
180 test4ArgsInt32ThenNumber();