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

Side by Side Diff: tests/lib_2/math/min_max_test.dart

Issue 2995343002: Migrated test block 216 to Dart 2.0. (Closed)
Patch Set: Migrated min_max_test to Dart 2.0 Created 3 years, 3 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
« no previous file with comments | « tests/lib_2/lib_2_vm.status ('k') | tests/lib_2/math/pi_test.dart » ('j') | 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) 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 for testing Math.min and Math.max. 4 // Dart test for testing Math.min and Math.max.
5 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation 5 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation
6 6
7 library min_max_test; 7 library min_max_test;
8 8
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 import 'dart:math'; 10 import 'dart:math';
11 11
12 var inf = double.INFINITY; 12 var inf = double.INFINITY;
13 var nan = double.NAN; 13 var nan = double.NAN;
14 14
15 // A class that might work if [min] and [max] worked for non-numbers. 15 // A class that might work if [min] and [max] worked for non-numbers.
16 class Wrap implements Comparable { 16 class Wrap implements Comparable<dynamic> {
17 final value; 17 final num value;
18 Wrap(this.value); 18 Wrap(this.value);
19 int compareTo(Wrap other) => value.compareTo(other.value); 19 int compareTo(dynamic other) => value.compareTo(other.value);
20 bool operator <(Wrap other) => compareTo(other) < 0; 20 bool operator <(Wrap other) => compareTo(other) < 0;
21 bool operator <=(Wrap other) => compareTo(other) <= 0; 21 bool operator <=(Wrap other) => compareTo(other) <= 0;
22 bool operator >(Wrap other) => compareTo(other) > 0; 22 bool operator >(Wrap other) => compareTo(other) > 0;
23 bool operator >=(Wrap other) => compareTo(other) >= 0; 23 bool operator >=(Wrap other) => compareTo(other) >= 0;
24 bool operator ==(other) => other is Wrap && compareTo(other) == 0; 24 bool operator ==(other) => other is Wrap && compareTo(other) == 0;
25 String toString() => 'Wrap($value)'; 25 String toString() => 'Wrap($value)';
26 int get hashCode => value.hashCode; 26 int get hashCode => value.hashCode;
27 } 27 }
28 28
29 var wrap1 = new Wrap(1); 29 var wrap1 = new Wrap(1);
30 var wrap2 = new Wrap(2); 30 var wrap2 = new Wrap(2);
31 31
32 testMin() { 32 testMin() {
33 testMin1(); 33 testMin1();
34 testMin2(); 34 testMin2();
35 testMin3(); 35 testMin3();
36 testMinChecks();
37 } 36 }
38 37
39 testMin1() { 38 testMin1() {
40 Expect.equals(0, min(0, 2)); 39 Expect.equals(0, min(0, 2));
41 Expect.equals(0, min(2, 0)); 40 Expect.equals(0, min(2, 0));
42 41
43 Expect.equals(-10, min(-10, -9)); 42 Expect.equals(-10, min(-10, -9));
44 Expect.equals(-10, min(-10, 9)); 43 Expect.equals(-10, min(-10, 9));
45 Expect.equals(-10, min(-10, 0)); 44 Expect.equals(-10, min(-10, 0));
46 Expect.equals(-10, min(-9, -10)); 45 Expect.equals(-10, min(-9, -10));
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 Expect.isTrue(min(inf, -499.0).isNegative); 290 Expect.isTrue(min(inf, -499.0).isNegative);
292 Expect.isTrue(min(inf, -499).isNegative); 291 Expect.isTrue(min(inf, -499).isNegative);
293 Expect.isTrue(min(inf, -0.0).isNegative); 292 Expect.isTrue(min(inf, -0.0).isNegative);
294 Expect.isFalse(min(inf, 0.0).isNegative); 293 Expect.isFalse(min(inf, 0.0).isNegative);
295 Expect.isFalse(min(inf, 0).isNegative); 294 Expect.isFalse(min(inf, 0).isNegative);
296 Expect.isFalse(min(inf, 499).isNegative); 295 Expect.isFalse(min(inf, 499).isNegative);
297 Expect.isFalse(min(inf, 499.0).isNegative); 296 Expect.isFalse(min(inf, 499.0).isNegative);
298 Expect.isFalse(min(inf, inf).isNegative); 297 Expect.isFalse(min(inf, inf).isNegative);
299 } 298 }
300 299
301 testMinChecks() {
302 // Min and max work only on numbers.
303 // These throw a type assertion or ArgumentError.
304 Expect.throws(() => min(wrap1, wrap2));
305 Expect.throws(() => min(wrap1, 0));
306 Expect.throws(() => min(0, wrap2));
307 }
308
309 testMax() { 300 testMax() {
310 testMax1(); 301 testMax1();
311 testMax2(); 302 testMax2();
312 testMax3(); 303 testMax3();
313 testMaxChecks();
314 } 304 }
315 305
316 testMax1() { 306 testMax1() {
317 Expect.equals(2, max(0, 2)); 307 Expect.equals(2, max(0, 2));
318 Expect.equals(2, max(2, 0)); 308 Expect.equals(2, max(2, 0));
319 309
320 Expect.equals(-9, max(-10, -9)); 310 Expect.equals(-9, max(-10, -9));
321 Expect.equals(9, max(-10, 9)); 311 Expect.equals(9, max(-10, 9));
322 Expect.equals(0, max(-10, 0)); 312 Expect.equals(0, max(-10, 0));
323 Expect.equals(-9, max(-9, -10)); 313 Expect.equals(-9, max(-9, -10));
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 Expect.isTrue(max(-inf, -inf) is double); 548 Expect.isTrue(max(-inf, -inf) is double);
559 549
560 Expect.isFalse(max(-inf, 0.0).isNegative); 550 Expect.isFalse(max(-inf, 0.0).isNegative);
561 Expect.isFalse(max(-inf, 0).isNegative); 551 Expect.isFalse(max(-inf, 0).isNegative);
562 Expect.isTrue(max(-inf, -0.0).isNegative); 552 Expect.isTrue(max(-inf, -0.0).isNegative);
563 Expect.isTrue(max(-inf, -499).isNegative); 553 Expect.isTrue(max(-inf, -499).isNegative);
564 Expect.isTrue(max(-inf, -499.0).isNegative); 554 Expect.isTrue(max(-inf, -499.0).isNegative);
565 Expect.isTrue(max(-inf, -inf).isNegative); 555 Expect.isTrue(max(-inf, -inf).isNegative);
566 } 556 }
567 557
568 testMaxChecks() {
569 // Min and max work only on numbers.
570 // These throw a type assertion or ArgumentError.
571 Expect.throws(() => min(wrap1, wrap2));
572 Expect.throws(() => min(wrap1, 0));
573 Expect.throws(() => min(0, wrap2));
574 }
575
576 main() { 558 main() {
577 testMin(); 559 testMin();
578 testMin(); 560 testMin();
579 testMax(); 561 testMax();
580 testMax(); 562 testMax();
581 } 563 }
OLDNEW
« no previous file with comments | « tests/lib_2/lib_2_vm.status ('k') | tests/lib_2/math/pi_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698