Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: tests/language/comparison_test.dart

Issue 3002573002: Migrating another batch of tests to dart 2. (Closed)
Patch Set: Removed library closure_type_test from test_file Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 import "package:expect/expect.dart";
7
8 class Helper {
9 static bool STRICT_EQ(a, b) {
10 return identical(a, b);
11 }
12
13 static bool STRICT_NE(a, b) {
14 return !identical(a, b);
15 }
16
17 static bool EQ(a, b) {
18 return a == b;
19 }
20
21 static bool NE(a, b) {
22 return a != b;
23 }
24
25 static bool LT(a, b) {
26 return a < b;
27 }
28
29 static bool LE(a, b) {
30 return a <= b;
31 }
32
33 static bool GT(a, b) {
34 return a > b;
35 }
36
37 static bool GE(a, b) {
38 return a >= b;
39 }
40 }
41
42 class A {
43 var b;
44
45 A(x) : b = x {}
46 }
47
48 class ComparisonTest {
49 static testMain() {
50 var a = new A(0);
51 var b = new A(1);
52 Expect.isTrue(Helper.STRICT_EQ(a, a));
53 Expect.isFalse(Helper.STRICT_EQ(a, b));
54 Expect.isFalse(Helper.STRICT_EQ(b, a));
55 Expect.isTrue(Helper.STRICT_EQ(b, b));
56
57 Expect.isFalse(Helper.STRICT_NE(a, a));
58 Expect.isTrue(Helper.STRICT_NE(a, b));
59 Expect.isTrue(Helper.STRICT_NE(b, a));
60 Expect.isFalse(Helper.STRICT_NE(b, b));
61
62 Expect.isTrue(Helper.STRICT_EQ(false, false));
63 Expect.isFalse(Helper.STRICT_EQ(false, true));
64 Expect.isFalse(Helper.STRICT_EQ(true, false));
65 Expect.isTrue(Helper.STRICT_EQ(true, true));
66
67 Expect.isFalse(Helper.STRICT_NE(false, false));
68 Expect.isTrue(Helper.STRICT_NE(false, true));
69 Expect.isTrue(Helper.STRICT_NE(true, false));
70 Expect.isFalse(Helper.STRICT_NE(true, true));
71
72 Expect.isTrue(Helper.STRICT_EQ(false, false));
73 Expect.isFalse(Helper.STRICT_EQ(false, true));
74 Expect.isFalse(Helper.STRICT_EQ(true, false));
75 Expect.isTrue(Helper.STRICT_EQ(true, true));
76
77 Expect.isFalse(Helper.STRICT_NE(false, false));
78 Expect.isTrue(Helper.STRICT_NE(false, true));
79 Expect.isTrue(Helper.STRICT_NE(true, false));
80 Expect.isFalse(Helper.STRICT_NE(true, true));
81
82 Expect.isTrue(Helper.EQ(false, false));
83 Expect.isFalse(Helper.EQ(false, true));
84 Expect.isFalse(Helper.EQ(true, false));
85 Expect.isTrue(Helper.EQ(true, true));
86
87 Expect.isFalse(Helper.NE(false, false));
88 Expect.isTrue(Helper.NE(false, true));
89 Expect.isTrue(Helper.NE(true, false));
90 Expect.isFalse(Helper.NE(true, true));
91
92 Expect.isTrue(Helper.STRICT_EQ(-1, -1));
93 Expect.isTrue(Helper.STRICT_EQ(0, 0));
94 Expect.isTrue(Helper.STRICT_EQ(1, 1));
95 Expect.isFalse(Helper.STRICT_EQ(-1, 0));
96 Expect.isFalse(Helper.STRICT_EQ(-1, 1));
97 Expect.isFalse(Helper.STRICT_EQ(0, 1));
98
99 Expect.isFalse(Helper.STRICT_NE(-1, -1));
100 Expect.isFalse(Helper.STRICT_NE(0, 0));
101 Expect.isFalse(Helper.STRICT_NE(1, 1));
102 Expect.isTrue(Helper.STRICT_NE(-1, 0));
103 Expect.isTrue(Helper.STRICT_NE(-1, 1));
104 Expect.isTrue(Helper.STRICT_NE(0, 1));
105
106 Expect.isTrue(Helper.EQ(-1, -1));
107 Expect.isTrue(Helper.EQ(0, 0));
108 Expect.isTrue(Helper.EQ(1, 1));
109 Expect.isFalse(Helper.EQ(-1, 0));
110 Expect.isFalse(Helper.EQ(-1, 1));
111 Expect.isFalse(Helper.EQ(0, 1));
112
113 Expect.isFalse(Helper.NE(-1, -1));
114 Expect.isFalse(Helper.NE(0, 0));
115 Expect.isFalse(Helper.NE(1, 1));
116 Expect.isTrue(Helper.NE(-1, 0));
117 Expect.isTrue(Helper.NE(-1, 1));
118 Expect.isTrue(Helper.NE(0, 1));
119
120 Expect.isFalse(Helper.LT(-1, -1));
121 Expect.isFalse(Helper.LT(0, 0));
122 Expect.isFalse(Helper.LT(1, 1));
123 Expect.isTrue(Helper.LT(-1, 0));
124 Expect.isTrue(Helper.LT(-1, 1));
125 Expect.isTrue(Helper.LT(0, 1));
126 Expect.isFalse(Helper.LT(0, -1));
127 Expect.isFalse(Helper.LT(1, -1));
128 Expect.isFalse(Helper.LT(1, 0));
129
130 Expect.isTrue(Helper.LE(-1, -1));
131 Expect.isTrue(Helper.LE(0, 0));
132 Expect.isTrue(Helper.LE(1, 1));
133 Expect.isTrue(Helper.LE(-1, 0));
134 Expect.isTrue(Helper.LE(-1, 1));
135 Expect.isTrue(Helper.LE(0, 1));
136 Expect.isFalse(Helper.LE(0, -1));
137 Expect.isFalse(Helper.LE(1, -1));
138 Expect.isFalse(Helper.LE(1, 0));
139
140 Expect.isFalse(Helper.GT(-1, -1));
141 Expect.isFalse(Helper.GT(0, 0));
142 Expect.isFalse(Helper.GT(1, 1));
143 Expect.isFalse(Helper.GT(-1, 0));
144 Expect.isFalse(Helper.GT(-1, 1));
145 Expect.isFalse(Helper.GT(0, 1));
146 Expect.isTrue(Helper.GT(0, -1));
147 Expect.isTrue(Helper.GT(1, -1));
148 Expect.isTrue(Helper.GT(1, 0));
149
150 Expect.isTrue(Helper.GE(-1, -1));
151 Expect.isTrue(Helper.GE(0, 0));
152 Expect.isTrue(Helper.GE(1, 1));
153 Expect.isFalse(Helper.GE(-1, 0));
154 Expect.isFalse(Helper.GE(-1, 1));
155 Expect.isFalse(Helper.GE(0, 1));
156 Expect.isTrue(Helper.GE(0, -1));
157 Expect.isTrue(Helper.GE(1, -1));
158 Expect.isTrue(Helper.GE(1, 0));
159
160 Expect.isTrue(Helper.STRICT_EQ(-1.0, -1.0));
161 Expect.isTrue(Helper.STRICT_EQ(0.0, 0.0));
162 Expect.isTrue(Helper.STRICT_EQ(1.0, 1.0));
163 Expect.isFalse(Helper.STRICT_EQ(-1.0, 0.0));
164 Expect.isFalse(Helper.STRICT_EQ(-1.0, 1.0));
165 Expect.isFalse(Helper.STRICT_EQ(0.0, 1.0));
166
167 Expect.isFalse(Helper.STRICT_NE(-1.0, -1.0));
168 Expect.isFalse(Helper.STRICT_NE(0.0, 0.0));
169 Expect.isFalse(Helper.STRICT_NE(1.0, 1.0));
170 Expect.isTrue(Helper.STRICT_NE(-1.0, 0.0));
171 Expect.isTrue(Helper.STRICT_NE(-1.0, 1.0));
172 Expect.isTrue(Helper.STRICT_NE(0.0, 1.0));
173
174 Expect.isTrue(Helper.EQ(-1.0, -1.0));
175 Expect.isTrue(Helper.EQ(0.0, 0.0));
176 Expect.isTrue(Helper.EQ(1.0, 1.0));
177 Expect.isFalse(Helper.EQ(-1.0, 0.0));
178 Expect.isFalse(Helper.EQ(-1.0, 1.0));
179 Expect.isFalse(Helper.EQ(0.0, 1.0));
180
181 Expect.isFalse(Helper.NE(-1.0, -1.0));
182 Expect.isFalse(Helper.NE(0.0, 0.0));
183 Expect.isFalse(Helper.NE(1.0, 1.0));
184 Expect.isTrue(Helper.NE(-1.0, 0.0));
185 Expect.isTrue(Helper.NE(-1.0, 1.0));
186 Expect.isTrue(Helper.NE(0.0, 1.0));
187
188 Expect.isFalse(Helper.LT(-1.0, -1.0));
189 Expect.isFalse(Helper.LT(0.0, 0.0));
190 Expect.isFalse(Helper.LT(1.0, 1.0));
191 Expect.isTrue(Helper.LT(-1.0, 0.0));
192 Expect.isTrue(Helper.LT(-1.0, 1.0));
193 Expect.isTrue(Helper.LT(0.0, 1.0));
194 Expect.isFalse(Helper.LT(0.0, -1.0));
195 Expect.isFalse(Helper.LT(1.0, -1.0));
196 Expect.isFalse(Helper.LT(1.0, 0.0));
197
198 Expect.isTrue(Helper.LE(-1.0, -1.0));
199 Expect.isTrue(Helper.LE(0.0, 0.0));
200 Expect.isTrue(Helper.LE(1.0, 1.0));
201 Expect.isTrue(Helper.LE(-1.0, 0.0));
202 Expect.isTrue(Helper.LE(-1.0, 1.0));
203 Expect.isTrue(Helper.LE(0.0, 1.0));
204 Expect.isFalse(Helper.LE(0.0, -1.0));
205 Expect.isFalse(Helper.LE(1.0, -1.0));
206 Expect.isFalse(Helper.LE(1.0, 0.0));
207
208 Expect.isFalse(Helper.GT(-1.0, -1.0));
209 Expect.isFalse(Helper.GT(0.0, 0.0));
210 Expect.isFalse(Helper.GT(1.0, 1.0));
211 Expect.isFalse(Helper.GT(-1.0, 0.0));
212 Expect.isFalse(Helper.GT(-1.0, 1.0));
213 Expect.isFalse(Helper.GT(0.0, 1.0));
214 Expect.isTrue(Helper.GT(0.0, -1.0));
215 Expect.isTrue(Helper.GT(1.0, -1.0));
216 Expect.isTrue(Helper.GT(1.0, 0.0));
217
218 Expect.isTrue(Helper.GE(-1.0, -1.0));
219 Expect.isTrue(Helper.GE(0.0, 0.0));
220 Expect.isTrue(Helper.GE(1.0, 1.0));
221 Expect.isFalse(Helper.GE(-1.0, 0.0));
222 Expect.isFalse(Helper.GE(-1.0, 1.0));
223 Expect.isFalse(Helper.GE(0.0, 1.0));
224 Expect.isTrue(Helper.GE(0.0, -1.0));
225 Expect.isTrue(Helper.GE(1.0, -1.0));
226 Expect.isTrue(Helper.GE(1.0, 0.0));
227
228 Expect.isTrue(Helper.EQ(null, null));
229 Expect.isFalse(Helper.EQ(null, "Str"));
230 Expect.isTrue(Helper.NE(null, 2));
231 Expect.isFalse(Helper.NE(null, null));
232
233 Expect.isTrue(Helper.STRICT_EQ(null, null));
234 Expect.isFalse(Helper.STRICT_EQ(null, "Str"));
235 Expect.isTrue(Helper.STRICT_NE(null, 2));
236 Expect.isFalse(Helper.STRICT_NE(null, null));
237
238 Expect.isFalse(Helper.GT(1, 1.2));
239 Expect.isTrue(Helper.GT(3, 1.2));
240 Expect.isTrue(Helper.GT(2.0, 1));
241 Expect.isFalse(Helper.GT(3.1, 4));
242
243 Expect.isFalse(Helper.GE(1, 1.2));
244 Expect.isTrue(Helper.GE(3, 1.2));
245 Expect.isTrue(Helper.GE(2.0, 1));
246 Expect.isFalse(Helper.GE(3.1, 4));
247 Expect.isTrue(Helper.GE(2.0, 2));
248 Expect.isTrue(Helper.GE(2, 2.0));
249
250 Expect.isTrue(Helper.LT(1, 1.2));
251 Expect.isFalse(Helper.LT(3, 1.2));
252 Expect.isFalse(Helper.LT(2.0, 1));
253 Expect.isTrue(Helper.LT(3.1, 4));
254
255 Expect.isTrue(Helper.LE(1, 1.2));
256 Expect.isFalse(Helper.LE(3, 1.2));
257 Expect.isFalse(Helper.LE(2.0, 1));
258 Expect.isTrue(Helper.LE(3.1, 4));
259 Expect.isTrue(Helper.LE(2.0, 2));
260 Expect.isTrue(Helper.LE(2, 2.0));
261
262 // Bignums.
263 Expect.isTrue(Helper.LE(0xF00000000005, 0xF00000000006));
264 Expect.isTrue(Helper.LE(0xF00000000005, 0xF00000000005));
265 Expect.isFalse(Helper.LE(0xF00000000006, 0xF00000000005));
266 Expect.isTrue(Helper.LE(12, 0xF00000000005));
267 Expect.isTrue(Helper.LE(12.2, 0xF00000000005));
268
269 Expect.isTrue(Helper.EQ(4294967295, 4.294967295e9));
270 Expect.isTrue(Helper.EQ(4.294967295e9, 4294967295));
271 Expect.isFalse(Helper.EQ(4.294967295e9, 42));
272 Expect.isFalse(Helper.EQ(42, 4.294967295e9));
273 Expect.isFalse(Helper.EQ(4294967295, 42));
274 Expect.isFalse(Helper.EQ(42, 4294967295));
275
276 // Fractions & mixed
277 Expect.isTrue(Helper.EQ(1.0, 1));
278 Expect.isTrue(Helper.EQ(1.0, 1));
279 Expect.isTrue(Helper.EQ(1, 1.0));
280 Expect.isTrue(Helper.EQ(1, 1.0));
281 Expect.isTrue(Helper.EQ(1.1, 1.1));
282 Expect.isTrue(Helper.EQ(1.1, 1.1));
283 Expect.isTrue(Helper.EQ(1.1, 1.1));
284
285 Expect.isFalse(Helper.GT(1, 1.2));
286 Expect.isTrue(Helper.GT(1.2, 1));
287 Expect.isTrue(Helper.GT(1.2, 1.1));
288 Expect.isTrue(Helper.GT(1.2, 1.1));
289 Expect.isTrue(Helper.GT(1.2, 1.1));
290
291 Expect.isTrue(Helper.LT(1, 1.2));
292 Expect.isFalse(Helper.LT(1.2, 1));
293 Expect.isFalse(Helper.LT(1.2, 1.1));
294 Expect.isFalse(Helper.LT(1.2, 1.1));
295 Expect.isFalse(Helper.LT(1.2, 1.1));
296
297 Expect.isFalse(Helper.GE(1.1, 1.2));
298 Expect.isFalse(Helper.GE(1.1, 1.2));
299 Expect.isTrue(Helper.GE(1.2, 1.2));
300 Expect.isTrue(Helper.GE(1.2, 1.2));
301
302 // With non-number classes.
303 Expect.isFalse(Helper.EQ(1, "eeny"));
304 Expect.isFalse(Helper.EQ("meeny", 1));
305 Expect.isFalse(Helper.EQ(1.1, "miny"));
306 Expect.isFalse(Helper.EQ("moe", 1.1));
307 Expect.isFalse(Helper.EQ(1.1, "catch"));
308 Expect.isFalse(Helper.EQ("the", 1.1));
309
310 // With null.
311 Expect.isFalse(Helper.EQ(1, null));
312 Expect.isFalse(Helper.EQ(null, 1));
313 Expect.isFalse(Helper.EQ(1.1, null));
314 Expect.isFalse(Helper.EQ(null, 1.1));
315 Expect.isFalse(Helper.EQ(1.1, null));
316 Expect.isFalse(Helper.EQ(null, 1.1));
317
318 // TODO(srdjan): Clarify behaviour of greater/less comparisons
319 // between numbers and non-numbers.
320 }
321 }
322
323 main() {
324 ComparisonTest.testMain();
325 }
OLDNEW
« no previous file with comments | « tests/language/code_motion_crash_test.dart ('k') | tests/language/compile_time_constant10_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698