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
|
// Test comparison between Boolean x {String, Double}.
// Boolean R String <=> ToNumber(Boolean) R ToNumber(String)
// Boolean R Number <=> ToNumber(Boolean) R Number
// The entries in the first halves of xs, ys, and zs should be loose-equal to each other.
var xs = [
// ToNumber(bool) == 0
false, false, false, false,
// ToNumber(bool) == 1
true, true, true, true,
// Filler
false, false, false, false,
true, true, true, true,
];
var ys = [
// ToNumber(str) == 0
"", "0", "0.0", ".0",
// ToNumber(str) == 1
"1", "1.0", "0x1", " 1\t\r\n",
// ToNumber(str) != {0, 1}
// (Duplicate entries to ensure they're neither equal to |true| nor to |false|.)
"not-a-number", "NaN", "Infinity", "2",
"not-a-number", "NaN", "Infinity", "2",
];
function Double(x) {
// numberToDouble always returns a Double valued number.
return numberToDouble(x);
}
var zs = [
// = 0
Double(0), Double(0), -0, -0,
// = 1
Double(1), Double(1), Double(1), Double(1),
// != {0, 1}
// (Duplicate entries to ensure they're neither equal to |true| nor to |false|.)
NaN, Infinity, Double(2), Double(-1.5),
NaN, Infinity, Double(2), Double(-1.5),
];
function testLooseEqual() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
var r = j < (xs.length >> 1);
assertEq(x == y, r);
assertEq(y == x, r);
assertEq(x == z, r);
assertEq(z == x, r);
}
}
testLooseEqual();
function testLooseNotEqual() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
var r = j < (xs.length >> 1);
assertEq(x != y, !r);
assertEq(y != x, !r);
assertEq(x != z, !r);
assertEq(z != x, !r);
}
}
testLooseNotEqual();
function testLessThan() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
assertEq(x < y, +x < +y);
assertEq(y < x, +y < +x);
assertEq(x < z, +x < +z);
assertEq(z < x, +z < +x);
}
}
testLessThan();
function testLessThanEqual() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
assertEq(x <= y, +x <= +y);
assertEq(y <= x, +y <= +x);
assertEq(x <= z, +x <= +z);
assertEq(z <= x, +z <= +x);
}
}
testLessThanEqual();
function testGreaterThan() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
assertEq(x > y, +x > +y);
assertEq(y > x, +y > +x);
assertEq(x > z, +x > +z);
assertEq(z > x, +z > +x);
}
}
testGreaterThan();
function testGreaterThanEqual() {
for (var i = 0; i < 100; ++i) {
var j = i % xs.length;
var x = xs[j];
var y = ys[j];
var z = zs[j];
assertEq(x >= y, +x >= +y);
assertEq(y >= x, +y >= +x);
assertEq(x >= z, +x >= +z);
assertEq(z >= x, +z >= +x);
}
}
testGreaterThanEqual();
|