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

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
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,
63 mnan,
Lasse Reichstein Nielsen 2012/07/09 07:38:00 Should nan and mnan not be equal? If not, are nan
floitsch 2012/07/09 07:56:31 Done.
64 ];
65
66 check(left, right, expectedResult) {
67 if (left is List) {
68 for(var x in left) check(x, right, expectedResult);
69 return;
70 }
71 if (right is List) {
72 for(var x in right) check(left, x, expectedResult);
73 return;
74 }
75 int actual = left.compareTo(right);
76 if (actual != expectedResult) {
77 print("($left).compareTo($right) failed "
Lasse Reichstein Nielsen 2012/07/09 07:38:00 Can't we pass a message to Expect.equals instead o
floitsch 2012/07/09 07:56:31 Done.
78 "(should have been $expectedResult, was $actual");
79 }
80 Expect.equals(expectedResult, actual);
81 }
82
83 for (int i = 0; i < matrix.length; i++) {
84 for (int j = 0; j < matrix.length; j++) {
85 var left = matrix[i];
86 var right = matrix[j];
87 if (left is List) {
88 check(left, left, 0);
89 }
90 check(left, right, i == j ? 0 : (i < j ? -1 : 1));
91 }
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698