summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/math-min-max.js
blob: b7b9fbe86adb32761c7060f34fe86dd7c0b3452e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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();