OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing comparison operators. | |
5 | |
6 class Helper { | |
7 static bool STRICT_EQ(a, b) { | |
8 return a === b; | |
9 } | |
10 | |
11 static bool STRICT_NE(a, b) { | |
12 return a !== b; | |
13 } | |
14 | |
15 static bool EQ(a, b) { | |
16 return a == b; | |
17 } | |
18 | |
19 static bool NE(a, b) { | |
20 return a != b; | |
21 } | |
22 | |
23 static bool LT(a, b) { | |
24 return a < b; | |
25 } | |
26 | |
27 static bool LE(a,b) { | |
28 return a <= b; | |
29 } | |
30 | |
31 static bool GT(a, b) { | |
32 return a > b; | |
33 } | |
34 | |
35 static bool GE(a, b) { | |
36 return a >= b; | |
37 } | |
38 } | |
39 | |
40 class A { | |
41 var b; | |
42 | |
43 A(x) : b = x { } | |
44 } | |
45 | |
46 class ComparisonTest { | |
47 static testMain() { | |
48 var a = new A(0); | |
49 var b = new A(1); | |
50 Expect.equals(true, Helper.STRICT_EQ(a, a)); | |
51 Expect.equals(false, Helper.STRICT_EQ(a, b)); | |
52 Expect.equals(false, Helper.STRICT_EQ(b, a)); | |
53 Expect.equals(true, Helper.STRICT_EQ(b, b)); | |
54 | |
55 Expect.equals(false, Helper.STRICT_NE(a, a)); | |
56 Expect.equals(true, Helper.STRICT_NE(a, b)); | |
57 Expect.equals(true, Helper.STRICT_NE(b, a)); | |
58 Expect.equals(false, Helper.STRICT_NE(b, b)); | |
59 | |
60 Expect.equals(true, Helper.STRICT_EQ(false, false)); | |
61 Expect.equals(false, Helper.STRICT_EQ(false, true)); | |
62 Expect.equals(false, Helper.STRICT_EQ(true, false)); | |
63 Expect.equals(true, Helper.STRICT_EQ(true, true)); | |
64 | |
65 Expect.equals(false, Helper.STRICT_NE(false, false)); | |
66 Expect.equals(true, Helper.STRICT_NE(false, true)); | |
67 Expect.equals(true, Helper.STRICT_NE(true, false)); | |
68 Expect.equals(false, Helper.STRICT_NE(true, true)); | |
69 | |
70 Expect.equals(true, Helper.STRICT_EQ(false, false)); | |
71 Expect.equals(false, Helper.STRICT_EQ(false, true)); | |
72 Expect.equals(false, Helper.STRICT_EQ(true, false)); | |
73 Expect.equals(true, Helper.STRICT_EQ(true, true)); | |
74 | |
75 Expect.equals(false, Helper.STRICT_NE(false, false)); | |
76 Expect.equals(true, Helper.STRICT_NE(false, true)); | |
77 Expect.equals(true, Helper.STRICT_NE(true, false)); | |
78 Expect.equals(false, Helper.STRICT_NE(true, true)); | |
79 | |
80 Expect.equals(true, Helper.EQ(false, false)); | |
81 Expect.equals(false, Helper.EQ(false, true)); | |
82 Expect.equals(false, Helper.EQ(true, false)); | |
83 Expect.equals(true, Helper.EQ(true, true)); | |
84 | |
85 Expect.equals(false, Helper.NE(false, false)); | |
86 Expect.equals(true, Helper.NE(false, true)); | |
87 Expect.equals(true, Helper.NE(true, false)); | |
88 Expect.equals(false, Helper.NE(true, true)); | |
89 | |
90 Expect.equals(true, Helper.STRICT_EQ(-1, -1)); | |
91 Expect.equals(true, Helper.STRICT_EQ(0, 0)); | |
92 Expect.equals(true, Helper.STRICT_EQ(1, 1)); | |
93 Expect.equals(false, Helper.STRICT_EQ(-1, 0)); | |
94 Expect.equals(false, Helper.STRICT_EQ(-1, 1)); | |
95 Expect.equals(false, Helper.STRICT_EQ(0, 1)); | |
96 | |
97 Expect.equals(false, Helper.STRICT_NE(-1, -1)); | |
98 Expect.equals(false, Helper.STRICT_NE(0, 0)); | |
99 Expect.equals(false, Helper.STRICT_NE(1, 1)); | |
100 Expect.equals(true, Helper.STRICT_NE(-1, 0)); | |
101 Expect.equals(true, Helper.STRICT_NE(-1, 1)); | |
102 Expect.equals(true, Helper.STRICT_NE(0, 1)); | |
103 | |
104 Expect.equals(true, Helper.EQ(-1, -1)); | |
105 Expect.equals(true, Helper.EQ(0, 0)); | |
106 Expect.equals(true, Helper.EQ(1, 1)); | |
107 Expect.equals(false, Helper.EQ(-1, 0)); | |
108 Expect.equals(false, Helper.EQ(-1, 1)); | |
109 Expect.equals(false, Helper.EQ(0, 1)); | |
110 | |
111 Expect.equals(false, Helper.NE(-1, -1)); | |
112 Expect.equals(false, Helper.NE(0, 0)); | |
113 Expect.equals(false, Helper.NE(1, 1)); | |
114 Expect.equals(true, Helper.NE(-1, 0)); | |
115 Expect.equals(true, Helper.NE(-1, 1)); | |
116 Expect.equals(true, Helper.NE(0, 1)); | |
117 | |
118 Expect.equals(false, Helper.LT(-1, -1)); | |
119 Expect.equals(false, Helper.LT(0, 0)); | |
120 Expect.equals(false, Helper.LT(1, 1)); | |
121 Expect.equals(true, Helper.LT(-1, 0)); | |
122 Expect.equals(true, Helper.LT(-1, 1)); | |
123 Expect.equals(true, Helper.LT(0, 1)); | |
124 Expect.equals(false, Helper.LT(0, -1)); | |
125 Expect.equals(false, Helper.LT(1, -1)); | |
126 Expect.equals(false, Helper.LT(1, 0)); | |
127 | |
128 Expect.equals(true, Helper.LE(-1, -1)); | |
129 Expect.equals(true, Helper.LE(0, 0)); | |
130 Expect.equals(true, Helper.LE(1, 1)); | |
131 Expect.equals(true, Helper.LE(-1, 0)); | |
132 Expect.equals(true, Helper.LE(-1, 1)); | |
133 Expect.equals(true, Helper.LE(0, 1)); | |
134 Expect.equals(false, Helper.LE(0, -1)); | |
135 Expect.equals(false, Helper.LE(1, -1)); | |
136 Expect.equals(false, Helper.LE(1, 0)); | |
137 | |
138 Expect.equals(false, Helper.GT(-1, -1)); | |
139 Expect.equals(false, Helper.GT(0, 0)); | |
140 Expect.equals(false, Helper.GT(1, 1)); | |
141 Expect.equals(false, Helper.GT(-1, 0)); | |
142 Expect.equals(false, Helper.GT(-1, 1)); | |
143 Expect.equals(false, Helper.GT(0, 1)); | |
144 Expect.equals(true, Helper.GT(0, -1)); | |
145 Expect.equals(true, Helper.GT(1, -1)); | |
146 Expect.equals(true, Helper.GT(1, 0)); | |
147 | |
148 Expect.equals(true, Helper.GE(-1, -1)); | |
149 Expect.equals(true, Helper.GE(0, 0)); | |
150 Expect.equals(true, Helper.GE(1, 1)); | |
151 Expect.equals(false, Helper.GE(-1, 0)); | |
152 Expect.equals(false, Helper.GE(-1, 1)); | |
153 Expect.equals(false, Helper.GE(0, 1)); | |
154 Expect.equals(true, Helper.GE(0, -1)); | |
155 Expect.equals(true, Helper.GE(1, -1)); | |
156 Expect.equals(true, Helper.GE(1, 0)); | |
157 | |
158 // TODO(regis): Double literals are not yet canonicalized. | |
159 // Expect.equals(true, Helper.STRICT_EQ(-1.0, -1.0)); | |
160 // Expect.equals(true, Helper.STRICT_EQ(0.0, 0.0)); | |
161 // Expect.equals(true, Helper.STRICT_EQ(1.0, 1.0)); | |
162 // Expect.equals(false, Helper.STRICT_EQ(-1.0, 0.0)); | |
163 // Expect.equals(false, Helper.STRICT_EQ(-1.0, 1.0)); | |
164 // Expect.equals(false, Helper.STRICT_EQ(0.0, 1.0)); | |
165 | |
166 // Expect.equals(false, Helper.STRICT_NE(-1.0, -1.0)); | |
167 // Expect.equals(false, Helper.STRICT_NE(0.0, 0.0)); | |
168 // Expect.equals(false, Helper.STRICT_NE(1.0, 1.0)); | |
169 // Expect.equals(true, Helper.STRICT_NE(-1.0, 0.0)); | |
170 // Expect.equals(true, Helper.STRICT_NE(-1.0, 1.0)); | |
171 // Expect.equals(true, Helper.STRICT_NE(0.0, 1.0)); | |
172 | |
173 Expect.equals(true, Helper.EQ(-1.0, -1.0)); | |
174 Expect.equals(true, Helper.EQ(0.0, 0.0)); | |
175 Expect.equals(true, Helper.EQ(1.0, 1.0)); | |
176 Expect.equals(false, Helper.EQ(-1.0, 0.0)); | |
177 Expect.equals(false, Helper.EQ(-1.0, 1.0)); | |
178 Expect.equals(false, Helper.EQ(0.0, 1.0)); | |
179 | |
180 Expect.equals(false, Helper.NE(-1.0, -1.0)); | |
181 Expect.equals(false, Helper.NE(0.0, 0.0)); | |
182 Expect.equals(false, Helper.NE(1.0, 1.0)); | |
183 Expect.equals(true, Helper.NE(-1.0, 0.0)); | |
184 Expect.equals(true, Helper.NE(-1.0, 1.0)); | |
185 Expect.equals(true, Helper.NE(0.0, 1.0)); | |
186 | |
187 Expect.equals(false, Helper.LT(-1.0, -1.0)); | |
188 Expect.equals(false, Helper.LT(0.0, 0.0)); | |
189 Expect.equals(false, Helper.LT(1.0, 1.0)); | |
190 Expect.equals(true, Helper.LT(-1.0, 0.0)); | |
191 Expect.equals(true, Helper.LT(-1.0, 1.0)); | |
192 Expect.equals(true, Helper.LT(0.0, 1.0)); | |
193 Expect.equals(false, Helper.LT(0.0, -1.0)); | |
194 Expect.equals(false, Helper.LT(1.0, -1.0)); | |
195 Expect.equals(false, Helper.LT(1.0, 0.0)); | |
196 | |
197 Expect.equals(true, Helper.LE(-1.0, -1.0)); | |
198 Expect.equals(true, Helper.LE(0.0, 0.0)); | |
199 Expect.equals(true, Helper.LE(1.0, 1.0)); | |
200 Expect.equals(true, Helper.LE(-1.0, 0.0)); | |
201 Expect.equals(true, Helper.LE(-1.0, 1.0)); | |
202 Expect.equals(true, Helper.LE(0.0, 1.0)); | |
203 Expect.equals(false, Helper.LE(0.0, -1.0)); | |
204 Expect.equals(false, Helper.LE(1.0, -1.0)); | |
205 Expect.equals(false, Helper.LE(1.0, 0.0)); | |
206 | |
207 Expect.equals(false, Helper.GT(-1.0, -1.0)); | |
208 Expect.equals(false, Helper.GT(0.0, 0.0)); | |
209 Expect.equals(false, Helper.GT(1.0, 1.0)); | |
210 Expect.equals(false, Helper.GT(-1.0, 0.0)); | |
211 Expect.equals(false, Helper.GT(-1.0, 1.0)); | |
212 Expect.equals(false, Helper.GT(0.0, 1.0)); | |
213 Expect.equals(true, Helper.GT(0.0, -1.0)); | |
214 Expect.equals(true, Helper.GT(1.0, -1.0)); | |
215 Expect.equals(true, Helper.GT(1.0, 0.0)); | |
216 | |
217 Expect.equals(true, Helper.GE(-1.0, -1.0)); | |
218 Expect.equals(true, Helper.GE(0.0, 0.0)); | |
219 Expect.equals(true, Helper.GE(1.0, 1.0)); | |
220 Expect.equals(false, Helper.GE(-1.0, 0.0)); | |
221 Expect.equals(false, Helper.GE(-1.0, 1.0)); | |
222 Expect.equals(false, Helper.GE(0.0, 1.0)); | |
223 Expect.equals(true, Helper.GE(0.0, -1.0)); | |
224 Expect.equals(true, Helper.GE(1.0, -1.0)); | |
225 Expect.equals(true, Helper.GE(1.0, 0.0)); | |
226 | |
227 Expect.equals(true, Helper.EQ(null, null)); | |
228 Expect.equals(false, Helper.EQ(null, "Str")); | |
229 Expect.equals(true, Helper.NE(null, 2)); | |
230 Expect.equals(false, Helper.NE(null, null)); | |
231 | |
232 Expect.equals(true, Helper.STRICT_EQ(null, null)); | |
233 Expect.equals(false, Helper.STRICT_EQ(null, "Str")); | |
234 Expect.equals(true, Helper.STRICT_NE(null, 2)); | |
235 Expect.equals(false, Helper.STRICT_NE(null, null)); | |
236 | |
237 Expect.equals(false, Helper.GT(1, 1.2)); | |
238 Expect.equals(true, Helper.GT(3, 1.2)); | |
239 Expect.equals(true, Helper.GT(2.0, 1)); | |
240 Expect.equals(false, Helper.GT(3.1, 4)); | |
241 | |
242 Expect.equals(false, Helper.GE(1, 1.2)); | |
243 Expect.equals(true, Helper.GE(3, 1.2)); | |
244 Expect.equals(true, Helper.GE(2.0, 1)); | |
245 Expect.equals(false, Helper.GE(3.1, 4)); | |
246 Expect.equals(true, Helper.GE(2.0, 2)); | |
247 Expect.equals(true, Helper.GE(2, 2.0)); | |
248 | |
249 Expect.equals(true, Helper.LT(1, 1.2)); | |
250 Expect.equals(false, Helper.LT(3, 1.2)); | |
251 Expect.equals(false, Helper.LT(2.0, 1)); | |
252 Expect.equals(true, Helper.LT(3.1, 4)); | |
253 | |
254 Expect.equals(true, Helper.LE(1, 1.2)); | |
255 Expect.equals(false, Helper.LE(3, 1.2)); | |
256 Expect.equals(false, Helper.LE(2.0, 1)); | |
257 Expect.equals(true, Helper.LE(3.1, 4)); | |
258 Expect.equals(true, Helper.LE(2.0, 2)); | |
259 Expect.equals(true, Helper.LE(2, 2.0)); | |
260 | |
261 // Bignums. | |
262 Expect.equals(true, Helper.LE(0xF00000000005, 0xF00000000006)); | |
263 Expect.equals(true, Helper.LE(0xF00000000005, 0xF00000000005)); | |
264 Expect.equals(false, Helper.LE(0xF00000000006, 0xF00000000005)); | |
265 Expect.equals(true, Helper.LE(12, 0xF00000000005)); | |
266 Expect.equals(true, Helper.LE(12.2, 0xF00000000005)); | |
267 | |
268 Expect.equals(true, Helper.EQ(4294967295, 4.294967295e9)); | |
269 Expect.equals(true, Helper.EQ(4.294967295e9, 4294967295)); | |
270 Expect.equals(false, Helper.EQ(4.294967295e9, 42)); | |
271 Expect.equals(false, Helper.EQ(42, 4.294967295e9)); | |
272 Expect.equals(false, Helper.EQ(4294967295, 42)); | |
273 Expect.equals(false, Helper.EQ(42, 4294967295)); | |
274 | |
275 // Fractions & mixed | |
276 Expect.equals(true, Helper.EQ(1.0, 1)); | |
277 Expect.equals(true, Helper.EQ(1.0, 1)); | |
278 Expect.equals(true, Helper.EQ(1, 1.0)); | |
279 Expect.equals(true, Helper.EQ(1, 1.0)); | |
280 Expect.equals(true, Helper.EQ(1.1, 1.1)); | |
281 Expect.equals(true, Helper.EQ(1.1, 1.1)); | |
282 Expect.equals(true, Helper.EQ(1.1, 1.1)); | |
283 | |
284 Expect.equals(false, Helper.GT(1, 1.2)); | |
285 Expect.equals(true, Helper.GT(1.2, 1)); | |
286 Expect.equals(true, Helper.GT(1.2, 1.1)); | |
287 Expect.equals(true, Helper.GT(1.2, 1.1)); | |
288 Expect.equals(true, Helper.GT(1.2, 1.1)); | |
289 | |
290 Expect.equals(true, Helper.LT(1, 1.2)); | |
291 Expect.equals(false, Helper.LT(1.2, 1)); | |
292 Expect.equals(false, Helper.LT(1.2, 1.1)); | |
293 Expect.equals(false, Helper.LT(1.2, 1.1)); | |
294 Expect.equals(false, Helper.LT(1.2, 1.1)); | |
295 | |
296 Expect.equals(false, Helper.GE(1.1, 1.2)); | |
297 Expect.equals(false, Helper.GE(1.1, 1.2)); | |
298 Expect.equals(true, Helper.GE(1.2, 1.2)); | |
299 Expect.equals(true, Helper.GE(1.2, 1.2)); | |
300 | |
301 // With non-number classes. | |
302 Expect.equals(false, Helper.EQ(1, "eeny")); | |
303 Expect.equals(false, Helper.EQ("meeny", 1)); | |
304 Expect.equals(false, Helper.EQ(1.1, "miny")); | |
305 Expect.equals(false, Helper.EQ("moe", 1.1)); | |
306 Expect.equals(false, Helper.EQ(1.1, "catch")); | |
307 Expect.equals(false, Helper.EQ("the", 1.1)); | |
308 | |
309 // With null. | |
310 Expect.equals(false, Helper.EQ(1, null)); | |
311 Expect.equals(false, Helper.EQ(null, 1)); | |
312 Expect.equals(false, Helper.EQ(1.1, null)); | |
313 Expect.equals(false, Helper.EQ(null, 1.1)); | |
314 Expect.equals(false, Helper.EQ(1.1, null)); | |
315 Expect.equals(false, Helper.EQ(null, 1.1)); | |
316 | |
317 // TODO(srdjan): Clarify behaviour of greater/less comparisons | |
318 // between numbers and non-numbers. | |
319 } | |
320 } | |
321 | |
322 main() { | |
323 ComparisonTest.testMain(); | |
324 } | |
OLD | NEW |