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

Side by Side Diff: frog/tests/leg_only/operator_test.dart

Issue 10536169: Move frog/tests/{leg,leg_only,frog_native} to tests/compiler/. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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
5 int zero() { return 0; }
6 int one() { return 1; }
7 int minus1() { return 0 - 1; }
8 int two() { return 2; }
9 int three() { return 3; }
10 int five() { return 5; }
11 int minus5() { return 0 - 5; }
12 int ninetyNine() { return 99; }
13 int four99() { return 499; }
14 int four99times99() { return 499 * 99; }
15 int four99times99plus1() { return 499 * 99 + 1; }
16
17 void addTest() {
18 var m1 = 0 - 1;
19 Expect.equals(0, 0 + 0);
20 Expect.equals(m1, m1 + 0);
21 Expect.equals(0, m1 + 1);
22 Expect.equals(499, 400 + 99);
23 Expect.equals(1, 0 + one());
24 Expect.equals(1, one() + 0);
25 Expect.equals(2, one() + one());
26 }
27
28 void subTest() {
29 var m1 = 0 - 1;
30 Expect.equals(0, 0 - 0);
31 Expect.equals(m1, 0 - 1);
32 Expect.equals(0, 1 - 1);
33 Expect.equals(400, 499 - 99);
34 Expect.equals(m1, 0 - one());
35 Expect.equals(1, one() - 0);
36 Expect.equals(0, one() - one());
37 }
38
39 void mulTest() {
40 var m1 = 0 - 1;
41 Expect.equals(0, 0 * 0);
42 Expect.equals(m1, m1 * 1);
43 Expect.equals(1, 1 * 1);
44 Expect.equals(49401, 499 * 99);
45 Expect.equals(499, 499 * one());
46 Expect.equals(499, one() * 499);
47 Expect.equals(49401, four99() * 99);
48 }
49
50 void divTest() {
51 var m1 = 0.0 - 1.0;
52 var m2 = 0 - 2;
53 Expect.equals(1.0, 2 / 2);
54 Expect.equals(m1, m2 / 2);
55 Expect.equals(0.5, 1 / 2);
56 Expect.equals(499.0, 49401 / 99);
57
58 Expect.equals(1.0, two() / 2);
59 Expect.equals(1.0, 2 / two());
60 Expect.equals(m1, m2 / two());
61 Expect.equals(m1, two() / m2);
62 Expect.equals(0.5, 1 / two());
63 Expect.equals(0.5, one() / 2);
64 Expect.equals(499.0, four99times99() / 99);
65 }
66
67 void tdivTest() {
68 var m1 = 0 - 1;
69 var m2 = 0 - 2;
70 Expect.equals(1, 2 ~/ 2);
71 Expect.equals(m1, m2 ~/ 2);
72 Expect.equals(0, 1 ~/ 2);
73 Expect.equals(0, m1 ~/ 2);
74 Expect.equals(499, 49401 ~/ 99);
75 Expect.equals(499, 49402 ~/ 99);
76
77 Expect.equals(1, two() ~/ 2);
78 Expect.equals(1, 2 ~/ two());
79 Expect.equals(m1, m2 ~/ two());
80 Expect.equals(m1, two() ~/ m2);
81 Expect.equals(0, 1 ~/ two());
82 Expect.equals(0, one() ~/ 2);
83 Expect.equals(499, four99times99() ~/ 99);
84 Expect.equals(499, four99times99plus1() ~/ 99);
85 }
86
87 void modTest() {
88 var m5 = 0 - 5;
89 var m3 = 0 - 3;
90 Expect.equals(2, 5 % 3);
91 Expect.equals(0, 49401 % 99);
92 Expect.equals(1, 49402 % 99);
93 Expect.equals(1, m5 % 3);
94 Expect.equals(2, 5 % m3);
95
96 Expect.equals(2, five() % 3);
97 Expect.equals(2, 5 % three());
98 Expect.equals(0, four99times99() % 99);
99 Expect.equals(1, four99times99plus1() % 99);
100 Expect.equals(1, minus5() % 3);
101 Expect.equals(2, five() % m3);
102 }
103
104 void shlTest() {
105 Expect.equals(2, 1 << 1);
106 Expect.equals(8, 1 << 3);
107 Expect.equals(6, 3 << 1);
108
109 Expect.equals(10, five() << 1);
110 Expect.equals(24, 3 << three());
111 }
112
113 void shrTest() {
114 Expect.equals(1, 2 >> 1);
115 Expect.equals(1, 8 >> 3);
116 Expect.equals(3, 6 >> 1);
117
118 var x = 0 - ninetyNine();
119 Expect.equals(6, ninetyNine() >> 4);
120 }
121
122 void andTest() {
123 Expect.equals(2, 10 & 3);
124 Expect.equals(7, 15 & 7);
125 Expect.equals(10, 10 & 10);
126
127 Expect.equals(99, ninetyNine() & ninetyNine());
128 Expect.equals(34, four99() & 42);
129 Expect.equals(3, minus5() & 7);
130 }
131
132 void orTest() {
133 Expect.equals(11, 10 | 3);
134 Expect.equals(15, 15 | 7);
135 Expect.equals(10, 10 | 10);
136
137 Expect.equals(99, ninetyNine() | ninetyNine());
138 Expect.equals(507, four99() | 42);
139 }
140
141 void xorTest() {
142 Expect.equals(9, 10 ^ 3);
143 Expect.equals(8, 15 ^ 7);
144 Expect.equals(0, 10 ^ 10);
145
146 Expect.equals(0, ninetyNine() ^ ninetyNine());
147 Expect.equals(473, four99() ^ 42);
148 Expect.equals(0, minus5() ^ -5);
149 Expect.equals(6, minus5() ^ -3);
150 }
151
152 void notTest() {
153 Expect.equals(4, ~minus5());
154 }
155
156 void negateTest() {
157 Expect.equals(minus5(), -5);
158 Expect.equals(-5, -five());
159 Expect.equals(5, -minus5());
160 var x = 3;
161 if (false) x = 5;
162 Expect.equals(-3, -x);
163 var y = -5;
164 Expect.equals(8, x - y);
165 }
166
167 void equalsTest() {
168 // Equality of normal numbers is already well tested with "Expect.equals".
169 Expect.equals(true, true == true);
170 Expect.equals(true, false == false);
171 Expect.equals(true, 0 == 0);
172 Expect.equals(true, null == null);
173
174 Expect.equals(false, 1 == 2);
175 Expect.equals(false, 1 == "foo");
176 Expect.equals(false, 1 == true);
177 Expect.equals(false, 1 == false);
178 Expect.equals(false, false == "");
179 Expect.equals(false, false == 0);
180 Expect.equals(false, false == null);
181 Expect.equals(false, "" == false);
182 Expect.equals(false, 0 == false);
183 Expect.equals(false, null == false);
184
185 var falseValue = false;
186 var trueValue = true;
187 var nullValue = null;
188 if (one() == 2) {
189 falseValue = true;
190 trueValue = false;
191 nullValue = 5;
192 }
193
194 Expect.equals(true, true == trueValue);
195 Expect.equals(true, false == falseValue);
196 Expect.equals(true, 1 == one());
197 Expect.equals(true, null == nullValue);
198 Expect.equals(false, one() == 2);
199 Expect.equals(false, one() == "foo");
200 Expect.equals(false, one() == true);
201 Expect.equals(false, one() == false);
202 Expect.equals(false, falseValue == "");
203 Expect.equals(false, falseValue == 0);
204 Expect.equals(false, falseValue == null);
205 Expect.equals(false, "" == falseValue);
206 Expect.equals(false, 0 == falseValue);
207 Expect.equals(false, null == falseValue);
208 }
209
210 void lessTest() {
211 var m1 = minus1();
212 Expect.equals(true, 1 < 2);
213 Expect.equals(false, 2 < 1);
214 Expect.equals(false, 1 < 1);
215
216 Expect.equals(true, 0 < 1);
217 Expect.equals(false, 1 < 0);
218 Expect.equals(false, 0 < 0);
219
220 Expect.equals(true, one() < 2);
221 Expect.equals(false, 2 < one());
222 Expect.equals(false, 1 < one());
223
224 Expect.equals(true, 0 < one());
225 Expect.equals(false, one() < 0);
226 Expect.equals(false, 0 < 0);
227
228 Expect.equals(true, m1 < 0);
229 Expect.equals(false, 0 < m1);
230 Expect.equals(false, m1 < m1);
231 }
232
233 void lessEqualTest() {
234 var m1 = minus1();
235 Expect.equals(true, 1 <= 2);
236 Expect.equals(false, 2 <= 1);
237 Expect.equals(true, 1 <= 1);
238
239 Expect.equals(true, 0 <= 1);
240 Expect.equals(false, 1 <= 0);
241 Expect.equals(true, 0 <= 0);
242
243 Expect.equals(true, one() <= 2);
244 Expect.equals(false, 2 <= one());
245 Expect.equals(true, 1 <= one());
246
247 Expect.equals(true, 0 <= one());
248 Expect.equals(false, one() <= 0);
249 Expect.equals(true, 0 <= 0);
250
251 Expect.equals(true, m1 <= 0);
252 Expect.equals(false, 0 <= m1);
253 Expect.equals(true, m1 <= m1);
254 }
255
256 void greaterTest() {
257 var m1 = minus1();
258 Expect.equals(false, 1 > 2);
259 Expect.equals(true, 2 > 1);
260 Expect.equals(false, 1 > 1);
261
262 Expect.equals(false, 0 > 1);
263 Expect.equals(true, 1 > 0);
264 Expect.equals(false, 0 > 0);
265
266 Expect.equals(false, one() > 2);
267 Expect.equals(true, 2 > one());
268 Expect.equals(false, 1 > one());
269
270 Expect.equals(false, 0 > one());
271 Expect.equals(true, one() > 0);
272 Expect.equals(false, 0 > 0);
273
274 Expect.equals(false, m1 > 0);
275 Expect.equals(true, 0 > m1);
276 Expect.equals(false, m1 > m1);
277 }
278
279 void greaterEqualTest() {
280 var m1 = minus1();
281 Expect.equals(false, 1 >= 2);
282 Expect.equals(true, 2 >= 1);
283 Expect.equals(true, 1 >= 1);
284
285 Expect.equals(false, 0 >= 1);
286 Expect.equals(true, 1 >= 0);
287 Expect.equals(true, 0 >= 0);
288
289 Expect.equals(false, one() >= 2);
290 Expect.equals(true, 2 >= one());
291 Expect.equals(true, 1 >= one());
292
293 Expect.equals(false, 0 >= one());
294 Expect.equals(true, one() >= 0);
295 Expect.equals(true, 0 >= 0);
296
297 Expect.equals(false, m1 >= 0);
298 Expect.equals(true, 0 >= m1);
299 Expect.equals(true, m1 >= m1);
300 }
301
302 void main() {
303 addTest();
304 subTest();
305 mulTest();
306 divTest();
307 tdivTest();
308 modTest();
309 shlTest();
310 shrTest();
311 andTest();
312 orTest();
313 xorTest();
314 notTest();
315 negateTest();
316 equalsTest();
317 lessTest();
318 lessEqualTest();
319 greaterTest();
320 greaterEqualTest();
321 }
OLDNEW
« no previous file with comments | « frog/tests/leg_only/operator_equals_test.dart ('k') | frog/tests/leg_only/optional_parameter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698