| OLD | NEW |
| 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 integer div by zero. | 4 // Dart test program to test integer div by zero. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 class DivByZeroTest { | 8 class DivByZeroTest { |
| 9 | |
| 10 static double divBy(int a, int b) { | 9 static double divBy(int a, int b) { |
| 11 var result = a/b; | 10 var result = a / b; |
| 12 return 1.0 * result; | 11 return 1.0 * result; |
| 13 } | 12 } |
| 14 | 13 |
| 15 static bool moustacheDivBy(int a, int b) { | 14 static bool moustacheDivBy(int a, int b) { |
| 16 var val = null; | 15 var val = null; |
| 17 try { | 16 try { |
| 18 val = a~/b; | 17 val = a ~/ b; |
| 19 } catch (e) { | 18 } catch (e) { |
| 20 return true; | 19 return true; |
| 21 } | 20 } |
| 22 print("Should not have gotten: $val"); | 21 print("Should not have gotten: $val"); |
| 23 return false; | 22 return false; |
| 24 } | 23 } |
| 25 | 24 |
| 26 static void testMain() { | 25 static void testMain() { |
| 27 Expect.isTrue(divBy(0, 0).isNaN); | 26 Expect.isTrue(divBy(0, 0).isNaN); |
| 28 Expect.isTrue(moustacheDivBy(0, 0)); | 27 Expect.isTrue(moustacheDivBy(0, 0)); |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 main() { | 31 main() { |
| 33 DivByZeroTest.testMain(); | 32 DivByZeroTest.testMain(); |
| 34 } | 33 } |
| OLD | NEW |