OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('arithmetic_test'); | 6 #library('arithmetic_test'); |
7 #import('dart:math'); | 7 #import('dart:math'); |
8 | 8 |
9 class ArithmeticTest { | 9 class ArithmeticTest { |
10 | 10 |
11 static bool exceptionCaughtParseInt(String s) { | 11 static bool exceptionCaughtParseInt(String s) { |
12 try { | 12 try { |
13 parseInt(s); | 13 parseInt(s); |
14 return false; | 14 return false; |
15 } catch (FormatException e) { | 15 } on FormatException catch (e) { |
16 return true; | 16 return true; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 static bool exceptionCaughtParseDouble(String s) { | 20 static bool exceptionCaughtParseDouble(String s) { |
21 try { | 21 try { |
22 parseDouble(s); | 22 parseDouble(s); |
23 return false; | 23 return false; |
24 } catch (FormatException e) { | 24 } on FormatException catch (e) { |
25 return true; | 25 return true; |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 static bool toIntThrowsFormatException(String str) { | 29 static bool toIntThrowsFormatException(String str) { |
30 // No exception allowed for parse double. | 30 // No exception allowed for parse double. |
31 double d = parseDouble(str); | 31 double d = parseDouble(str); |
32 try { | 32 try { |
33 var a = d.toInt(); | 33 var a = d.toInt(); |
34 return false; | 34 return false; |
35 } catch (FormatException e) { | 35 } on FormatException catch (e) { |
36 return true; | 36 return true; |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 static runOne() { | 40 static runOne() { |
41 var a = 22; | 41 var a = 22; |
42 var b = 4; | 42 var b = 4; |
43 // Smi & smi. | 43 // Smi & smi. |
44 Expect.equals(26, a + b); | 44 Expect.equals(26, a + b); |
45 Expect.equals(18, a - b); | 45 Expect.equals(18, a - b); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 static testMain() { | 414 static testMain() { |
415 for (int i = 0; i < 1500; i++) { | 415 for (int i = 0; i < 1500; i++) { |
416 runOne(); | 416 runOne(); |
417 } | 417 } |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
421 main() { | 421 main() { |
422 ArithmeticTest.testMain(); | 422 ArithmeticTest.testMain(); |
423 } | 423 } |
OLD | NEW |