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

Side by Side Diff: tests/corelib/compare_to2_test.dart

Issue 2977403002: Migrate test block 3 to Dart 2.0. (Closed)
Patch Set: Addressed Bob's nits Created 3 years, 5 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/corelib/collection_to_string_test.dart ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test for testing Math.min and Math.max.
5
6 import "package:expect/expect.dart";
7
8 negate(x) => -x;
9
10 main() {
11 // Test matrix:
12 var minNonZero = 5e-324;
13 var maxDenormal = 2.225073858507201e-308;
14 var minNormal = 2.2250738585072014e-308;
15 var maxFraction = 0.9999999999999999;
16 var minAbove1 = 1.0000000000000002;
17 var maxNonInt = 4503599627370495.5;
18 var maxNonIntFloorAsInt = maxNonInt.floor();
19 var maxNonIntFloorAsDouble = maxNonIntFloorAsInt.toDouble();
20 var maxExactIntAsDouble = 9007199254740992.0;
21 var maxExactIntAsInt = 9007199254740992;
22 var two53 = 1 << 53; // Same as maxExactIntAsInt.
23 var two53p1 = two53 + 1;
24 var maxFiniteAsDouble = 1.7976931348623157e+308;
25 var maxFiniteAsInt = maxFiniteAsDouble.truncate();
26 int huge = 1 << 2000;
27 int hugeP1 = huge + 1;
28 var inf = double.INFINITY;
29 var nan = double.NAN;
30 var mnan = negate(nan);
31 var matrix = [
32 -inf,
33 -hugeP1,
34 -huge,
35 [-maxFiniteAsDouble, -maxFiniteAsInt],
36 -two53p1,
37 [-two53, -maxExactIntAsInt, -maxExactIntAsDouble],
38 -maxNonInt,
39 [-maxNonIntFloorAsDouble, -maxNonIntFloorAsInt],
40 [-499.0, -499],
41 -minAbove1,
42 [-1.0, -1],
43 -maxFraction,
44 -minNormal,
45 -maxDenormal,
46 -minNonZero,
47 -0.0,
48 [0, 0, 0],
49 minNonZero,
50 maxDenormal,
51 minNormal,
52 maxFraction,
53 [1.0, 1],
54 minAbove1,
55 [499.0, 499],
56 [maxNonIntFloorAsDouble, maxNonIntFloorAsInt],
57 maxNonInt,
58 [two53, maxExactIntAsInt, maxExactIntAsDouble],
59 two53p1,
60 [maxFiniteAsDouble, maxFiniteAsInt],
61 huge,
62 hugeP1,
63 inf,
64 [nan, mnan],
65 ];
66
67 check(left, right, expectedResult) {
68 if (left is List) {
69 for (var x in left) check(x, right, expectedResult);
70 return;
71 }
72 if (right is List) {
73 for (var x in right) check(left, x, expectedResult);
74 return;
75 }
76 int actual = left.compareTo(right);
77 Expect.equals(
78 expectedResult,
79 actual,
80 "($left).compareTo($right) failed "
81 "(should have been $expectedResult, was $actual");
82 }
83
84 for (int i = 0; i < matrix.length; i++) {
85 for (int j = 0; j < matrix.length; j++) {
86 var left = matrix[i];
87 var right = matrix[j];
88 if (left is List) {
89 check(left, left, 0);
90 }
91 check(left, right, i == j ? 0 : (i < j ? -1 : 1));
92 }
93 }
94 }
OLDNEW
« no previous file with comments | « tests/corelib/collection_to_string_test.dart ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698