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

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

Issue 228533002: Fix assert in dart:math/Rectangle. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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/rectangle.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/rectangle_test.dart
diff --git a/tests/lib/math/rectangle_test.dart b/tests/lib/math/rectangle_test.dart
index 45052f63e23b2446fa7d515932e84aa20f4da28f..3a5e792de9084b32d75d3991dd7f3cf2cb2eb3e7 100644
--- a/tests/lib/math/rectangle_test.dart
+++ b/tests/lib/math/rectangle_test.dart
@@ -177,5 +177,74 @@ main() {
expect(identical(r.width, 0.0), isTrue);
expect(identical(r.height, 0.0), isTrue);
});
+
+ // A NaN-value in any rectangle value means the rectange is considered
+ // empty (contains no points, doesn't intersect any other rectangle).
+ const NaN = double.NAN;
+ var isNaN = predicate((x) => x is double && x.isNaN);
+
+ test('NaN left', () {
+ var rectangles = [
+ const Rectangle(NaN, 1, 2, 3),
+ new MutableRectangle(NaN, 1, 2, 3),
+ new Rectangle.fromPoints(new Point(NaN, 1), new Point(2, 4)),
+ new MutableRectangle.fromPoints(new Point(NaN, 1), new Point(2, 4)),
+ ];
+ for (var r in rectangles) {
+ expect(r.containsPoint(new Point(0, 1)), false);
+ expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.left, isNaN);
+ expect(r.right, isNaN);
+ }
+ });
+
+ test('NaN top', () {
+ var rectangles = [
+ const Rectangle(0, NaN, 2, 3),
+ new MutableRectangle(0, NaN, 2, 3),
+ new Rectangle.fromPoints(new Point(0, NaN), new Point(2, 4)),
+ new MutableRectangle.fromPoints(new Point(0, NaN), new Point(2, 4)),
+ ];
+ for (var r in rectangles) {
+ expect(r.containsPoint(new Point(0, 1)), false);
+ expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.top, isNaN);
+ expect(r.bottom, isNaN);
+ }
+ });
+
+ test('NaN width', () {
+ var rectangles = [
+ const Rectangle(0, 1, NaN, 3),
+ new MutableRectangle(0, 1, NaN, 3),
+ new Rectangle.fromPoints(new Point(0, 1), new Point(NaN, 4)),
+ new MutableRectangle.fromPoints(new Point(0, 1), new Point(NaN, 4)),
+ ];
+ for (var r in rectangles) {
+ expect(r.containsPoint(new Point(0, 1)), false);
+ expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.right, isNaN);
+ expect(r.width, isNaN);
+ }
+ });
+
+ test('NaN heigth', () {
+ var rectangles = [
+ const Rectangle(0, 1, 2, NaN),
+ new MutableRectangle(0, 1, 2, NaN),
+ new Rectangle.fromPoints(new Point(0, 1), new Point(2, NaN)),
+ new MutableRectangle.fromPoints(new Point(0, 1), new Point(2, NaN)),
+ ];
+ for (var r in rectangles) {
+ expect(r.containsPoint(new Point(0, 1)), false);
+ expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
+ expect(r.bottom, isNaN);
+ expect(r.height, isNaN);
+ }
+ });
}
« no previous file with comments | « sdk/lib/math/rectangle.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698