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

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

Issue 10692099: Fix int.compareTo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/lib/integers.dart ('k') | tests/corelib/compare_to_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
(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 negate(x) => -x;
7
8 main() {
9 // Test matrix:
10 var minNonZero = 5e-324;
11 var maxDenormal = 2.225073858507201e-308;
12 var minNormal = 2.2250738585072014e-308;
13 var maxFraction = 0.9999999999999999;
14 var minAbove1 = 1.0000000000000002;
15 var maxNonInt = 4503599627370495.5;
16 var maxNonIntFloorAsDouble = maxNonInt.floor();
17 var maxNonIntFloorAsInt = maxNonIntFloorAsDouble.toInt();
18 var maxExactIntAsDouble = 9007199254740992.0;
19 var maxExactIntAsInt = 9007199254740992;
20 var two53 = 1 << 53; // Same as maxExactIntAsInt.
21 var two53p1 = two53 + 1;
22 var maxFiniteAsDouble = 1.7976931348623157e+308;
23 var maxFiniteAsInt = maxFiniteAsDouble.toInt();
24 int huge = 1 << 2000;
25 int hugeP1 = huge + 1;
26 var inf = double.INFINITY;
27 var nan = double.NAN;
28 var mnan = negate(nan);
29 var matrix = [
30 -inf,
31 -hugeP1,
32 -huge,
33 [-maxFiniteAsDouble, -maxFiniteAsInt],
34 -two53p1,
35 [-two53, -maxExactIntAsInt, -maxExactIntAsDouble],
36 -maxNonInt,
37 [-maxNonIntFloorAsDouble, -maxNonIntFloorAsInt],
38 [-499.0, -499],
39 -minAbove1,
40 [-1.0, -1],
41 -maxFraction,
42 -minNormal,
43 -maxDenormal,
44 -minNonZero,
45 -0.0,
46 [0,0, 0],
47 minNonZero,
48 maxDenormal,
49 minNormal,
50 maxFraction,
51 [1.0, 1],
52 minAbove1,
53 [499.0, 499],
54 [maxNonIntFloorAsDouble, maxNonIntFloorAsInt],
55 maxNonInt,
56 [two53, maxExactIntAsInt, maxExactIntAsDouble],
57 two53p1,
58 [maxFiniteAsDouble, maxFiniteAsInt],
59 huge,
60 hugeP1,
61 inf,
62 [nan, mnan],
63 ];
64
65 check(left, right, expectedResult) {
66 if (left is List) {
67 for(var x in left) check(x, right, expectedResult);
68 return;
69 }
70 if (right is List) {
71 for(var x in right) check(left, x, expectedResult);
72 return;
73 }
74 int actual = left.compareTo(right);
75 Expect.equals(expectedResult, actual,
76 "($left).compareTo($right) failed "
77 "(should have been $expectedResult, was $actual");
78 }
79
80 for (int i = 0; i < matrix.length; i++) {
81 for (int j = 0; j < matrix.length; j++) {
82 var left = matrix[i];
83 var right = matrix[j];
84 if (left is List) {
85 check(left, left, 0);
86 }
87 check(left, right, i == j ? 0 : (i < j ? -1 : 1));
88 }
89 }
90 }
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | tests/corelib/compare_to_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698