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

Side by Side Diff: language/src/ArithmeticTest.dart

Issue 8935015: Expand ArithmeticTest to include truncate divide corner case and to trigger optimizing compiler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/tests/
Patch Set: Created 9 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test program to test arithmetic operations. 4 // Dart test program to test arithmetic operations.
5 5
6 class ArithmeticTest { 6 class ArithmeticTest {
7 7
8 static bool exceptionCaughtParseInt(String s) { 8 static bool exceptionCaughtParseInt(String s) {
9 try { 9 try {
10 Math.parseInt(s); 10 Math.parseInt(s);
(...skipping 16 matching lines...) Expand all
27 // No exception allowed for parse double. 27 // No exception allowed for parse double.
28 double d = Math.parseDouble(str); 28 double d = Math.parseDouble(str);
29 try { 29 try {
30 var a = d.toInt(); 30 var a = d.toInt();
31 return false; 31 return false;
32 } catch (BadNumberFormatException e) { 32 } catch (BadNumberFormatException e) {
33 return true; 33 return true;
34 } 34 }
35 } 35 }
36 36
37 static testMain() { 37 static runOne() {
38 var a = 22; 38 var a = 22;
39 var b = 4; 39 var b = 4;
40 // Smi & smi. 40 // Smi & smi.
41 Expect.equals(26, a + b); 41 Expect.equals(26, a + b);
42 Expect.equals(18, a - b); 42 Expect.equals(18, a - b);
43 Expect.equals(88, a * b); 43 Expect.equals(88, a * b);
44 Expect.equals(5, a ~/ b); 44 Expect.equals(5, a ~/ b);
45 Expect.equals(5.5, a / b); 45 Expect.equals(5.5, a / b);
46 Expect.equals(2.0, 10 / 5); 46 Expect.equals(2.0, 10 / 5);
47 Expect.equals(2, a % b); 47 Expect.equals(2, a % b);
48 Expect.equals(2, a.remainder(b)); 48 Expect.equals(2, a.remainder(b));
49 a = -(1 << 30);
50 b = -1;
51 // Smi corner cases.
52 Expect.equals(1 << 30, a ~/ b);
regis 2011/12/14 00:58:03 You could already add a test for 62-bit Smi.
sra1 2011/12/14 01:05:25 I would loop, 30 and 62 are not the only choices.
srdjan 2011/12/14 01:14:30 Looping 1..80
49 a = 22; 53 a = 22;
50 b = 4.0; 54 b = 4.0;
51 // Smi & double. 55 // Smi & double.
52 Expect.equals(26.0, a + b); 56 Expect.equals(26.0, a + b);
53 Expect.equals(18.0, a - b); 57 Expect.equals(18.0, a - b);
54 Expect.equals(88.0, a * b); 58 Expect.equals(88.0, a * b);
55 Expect.equals(5.0, a ~/ b); 59 Expect.equals(5.0, a ~/ b);
56 Expect.equals(5.5, a / b); 60 Expect.equals(5.5, a / b);
57 Expect.equals(2.0, a % b); 61 Expect.equals(2.0, a % b);
58 Expect.equals(2.0, a.remainder(b)); 62 Expect.equals(2.0, a.remainder(b));
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 Expect.equals(12.0, Math.max(1.0, 12.0)); 385 Expect.equals(12.0, Math.max(1.0, 12.0));
382 Expect.equals(false, 1.0 < Math.min(1.0, 12.0)); 386 Expect.equals(false, 1.0 < Math.min(1.0, 12.0));
383 Expect.equals(true, 1.0 < Math.max(1.0, 12.0)); 387 Expect.equals(true, 1.0 < Math.max(1.0, 12.0));
384 388
385 // Hashcode 389 // Hashcode
386 Expect.equals(false, (3.4).hashCode() == (1.2).hashCode()); 390 Expect.equals(false, (3.4).hashCode() == (1.2).hashCode());
387 Expect.equals(true, (1.2).hashCode() == (1.2).hashCode()); 391 Expect.equals(true, (1.2).hashCode() == (1.2).hashCode());
388 Expect.equals(false, (3).hashCode() == (1).hashCode()); 392 Expect.equals(false, (3).hashCode() == (1).hashCode());
389 Expect.equals(true, (10).hashCode() == (10).hashCode()); 393 Expect.equals(true, (10).hashCode() == (10).hashCode());
390 } 394 }
395
396 static testMain() {
397 for (int i = 0; i < 1500; i++) {
398 runOne();
399 }
400 }
391 } 401 }
392 402
393 main() { 403 main() {
394 ArithmeticTest.testMain(); 404 ArithmeticTest.testMain();
395 } 405 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698