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

Unified Diff: tests/lib/math/min_max_test.dart

Issue 24918003: Revert "Revert "Reinstate type checks in Math.min and Math.max"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/math/math.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/math/min_max_test.dart
diff --git a/tests/lib/math/min_max_test.dart b/tests/lib/math/min_max_test.dart
index 46d05665e7af66f3d93457b953aab0099d9cbd92..2b16176740f3449cacdc90bf5bef07aa2618403a 100644
--- a/tests/lib/math/min_max_test.dart
+++ b/tests/lib/math/min_max_test.dart
@@ -11,10 +11,28 @@ import 'dart:math';
var inf = double.INFINITY;
var nan = double.NAN;
+// A class that might work if [min] and [max] worked for non-numbers.
+class Wrap implements Comparable {
+ final value;
+ Wrap(this.value);
+ int compare(Wrap other) => value.compare(other.value);
+ bool operator<(Wrap other) => compare(other) < 0;
+ bool operator<=(Wrap other) => compare(other) <= 0;
+ bool operator>(Wrap other) => compare(other) > 0;
+ bool operator>=(Wrap other) => compare(other) >= 0;
+ bool operator==(other) => other is Wrap && compare(other) == 0;
+ String toString() => 'Wrap($value)';
+ int get hashCode => value.hashCode;
+}
+
+var wrap1 = new Wrap(1);
+var wrap2 = new Wrap(2);
+
testMin() {
testMin1();
testMin2();
testMin3();
+ testMinChecks();
}
testMin1() {
@@ -279,10 +297,19 @@ testMin3() {
Expect.isFalse(min(inf, inf).isNegative);
}
+testMinChecks() {
+ // Min and max work only on numbers.
+ // These throw a type assertion or ArgumentError.
+ Expect.throws(() => min(wrap1, wrap2));
+ Expect.throws(() => min(wrap1, 0));
+ Expect.throws(() => min(0, wrap2));
+}
+
testMax() {
testMax1();
testMax2();
testMax3();
+ testMaxChecks();
}
testMax1() {
@@ -537,6 +564,14 @@ testMax3() {
Expect.isTrue(max(-inf, -inf).isNegative);
}
+testMaxChecks() {
+ // Min and max work only on numbers.
+ // These throw a type assertion or ArgumentError.
+ Expect.throws(() => min(wrap1, wrap2));
+ Expect.throws(() => min(wrap1, 0));
+ Expect.throws(() => min(0, wrap2));
+}
+
main() {
testMin();
testMin();
« no previous file with comments | « sdk/lib/math/math.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698