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

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

Issue 11573044: Inline Doubles truncate and round. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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
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
(...skipping 19 matching lines...) Expand all
30 // No exception allowed for parse double. 30 // No exception allowed for parse double.
31 double d = double.parse(str); 31 double d = double.parse(str);
32 try { 32 try {
33 var a = d.toInt(); 33 var a = d.toInt();
34 return false; 34 return false;
35 } on UnsupportedError catch (e) { 35 } on UnsupportedError catch (e) {
36 return true; 36 return true;
37 } 37 }
38 } 38 }
39 39
40 static runOne() { 40 static runOne() {
Florian Schneider 2013/01/11 09:49:30 This is not directly related to your CL, but we ne
srdjan 2013/01/11 19:41:08 I agree, suggestions?
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);
46 Expect.equals(88, a * b); 46 Expect.equals(88, a * b);
47 Expect.equals(5, a ~/ b); 47 Expect.equals(5, a ~/ b);
48 Expect.equals(5.5, a / b); 48 Expect.equals(5.5, a / b);
49 Expect.equals(2.0, 10 / 5); 49 Expect.equals(2.0, 10 / 5);
50 Expect.equals(2, a % b); 50 Expect.equals(2, a % b);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 Expect.equals(-3.0, (-2.6).round()); 275 Expect.equals(-3.0, (-2.6).round());
276 Expect.equals(0.0, (0.0).round()); 276 Expect.equals(0.0, (0.0).round());
277 Expect.equals(0.0, (0.1).round()); 277 Expect.equals(0.0, (0.1).round());
278 Expect.equals(false, (0.0).round().isNegative); 278 Expect.equals(false, (0.0).round().isNegative);
279 Expect.equals(false, (0.1).round().isNegative); 279 Expect.equals(false, (0.1).round().isNegative);
280 Expect.equals(-0.0, (-0.0).round()); 280 Expect.equals(-0.0, (-0.0).round());
281 Expect.equals(-0.0, (-0.3).round()); 281 Expect.equals(-0.0, (-0.3).round());
282 Expect.equals(2.0, (2.1).round()); 282 Expect.equals(2.0, (2.1).round());
283 Expect.equals(-2.0, (-2.1).round()); 283 Expect.equals(-2.0, (-2.1).round());
284 Expect.equals(1.0, (0.5).round()); 284 Expect.equals(1.0, (0.5).round());
285 // TODO(floitsch): enable or adapt test, once we reached conclusion on 285 Expect.equals(0.0, (0.49999999999999994).round());
286 // b/4539188. 286 Expect.equals(-0.0, (-0.49999999999999994).round());
287 // Expect.equals(-0.0, (-0.5).round()); 287 Expect.equals(-1.0, (-0.5).round());
288 // TODO(srdjan): enable the following tests once isNegative works. 288 Expect.equals(true, (-0.0).round().isNegative);
289 // Expect.equals(true, (-0.0).round().isNegative); 289 Expect.equals(true, (-0.3).round().isNegative);
290 // Expect.equals(true, (-0.3).round().isNegative); 290 Expect.equals(true, (-0.5).round().isNegative);
291 // Expect.equals(true, (-0.5).round().isNegative);
292 Expect.equals(2.0, (1.5).round()); 291 Expect.equals(2.0, (1.5).round());
293 // TODO(floitsch): enable or adapt test, once we reached conclusion on 292 Expect.equals(-2.0, (-1.5).round());
Florian Schneider 2013/01/11 09:49:30 Please also add another corner case (2^53-1) and -
srdjan 2013/01/11 19:41:08 Thanks, using 9007199254740991.0.
294 // b/4539188.
295 // Expect.equals(-1.0, (-1.5).round());
296 Expect.equals(1.0, (0.99).round()); 293 Expect.equals(1.0, (0.99).round());
297 294
298 // -- toInt --. 295 // -- toInt --.
299 // Smi. 296 // Smi.
300 Expect.equals(0, (0).toInt()); 297 Expect.equals(0, (0).toInt());
301 Expect.equals(1, (1).toInt()); 298 Expect.equals(1, (1).toInt());
302 Expect.equals(-1, (-1).toInt()); 299 Expect.equals(-1, (-1).toInt());
303 // Type checks. 300 // Type checks.
304 { int i = (0).toInt(); } 301 { int i = (0).toInt(); }
305 { int i = (1).toInt(); } 302 { int i = (1).toInt(); }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 for (int i = 0; i < 1500; i++) { 421 for (int i = 0; i < 1500; i++) {
425 runOne(); 422 runOne();
426 testSmiDivDeopt(); 423 testSmiDivDeopt();
427 } 424 }
428 } 425 }
429 } 426 }
430 427
431 main() { 428 main() {
432 ArithmeticTest.testMain(); 429 ArithmeticTest.testMain();
433 } 430 }
OLDNEW
« runtime/vm/intermediate_language.h ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698