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

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

Issue 25808002: Move Rectangle and Point into dart:math. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
Index: tests/lib/math/rectangle_test.dart
diff --git a/tests/html/rect_test.dart b/tests/lib/math/rectangle_test.dart
similarity index 51%
rename from tests/html/rect_test.dart
rename to tests/lib/math/rectangle_test.dart
index 8b52f615839af2695559138224849a928e541430..2b214d296aa2cbdd574772e83dcb6dd2255eae80 100644
--- a/tests/html/rect_test.dart
+++ b/tests/lib/math/rectangle_test.dart
@@ -4,27 +4,25 @@
library rect_test;
-import 'dart:html';
-import '../../pkg/unittest/lib/unittest.dart';
-import '../../pkg/unittest/lib/html_config.dart';
+import 'dart:math';
+import 'package:unittest/unittest.dart';
main() {
- useHtmlConfiguration();
-
- Rect createRect(List<num> a) {
- return a != null ? new Rect(a[0], a[1], a[2] - a[0], a[3] - a[1]) : null;
+ Rectangle createRectangle(List<num> a) {
+ return a != null ? new Rectangle(a[0], a[1], a[2] - a[0], a[3] - a[1])
+ : null;
}
test('construction', () {
- var r0 = new Rect(10, 20, 30, 40);
- expect(r0.toString(), '(10, 20, 30, 40)');
+ var r0 = new Rectangle(10, 20, 30, 40);
+ expect(r0.toString(), 'Rectangle (10, 20) 30 x 40');
expect(r0.right, 40);
expect(r0.bottom, 60);
- var r1 = new Rect.fromPoints(r0.topLeft, r0.bottomRight);
+ var r1 = new Rectangle.fromPoints(r0.topLeft, r0.bottomRight);
expect(r1, r0);
- var r2 = new Rect.fromPoints(r0.bottomRight, r0.topLeft);
+ var r2 = new Rectangle.fromPoints(r0.bottomRight, r0.topLeft);
expect(r2, r0);
});
@@ -36,9 +34,9 @@ main() {
[[11, 12, 98, 99], [22, 23, 34, 35], [22, 23, 34, 35]]];
for (var test in tests) {
- var r0 = createRect(test[0]);
- var r1 = createRect(test[1]);
- var expected = createRect(test[2]);
+ var r0 = createRectangle(test[0]);
+ var r1 = createRectangle(test[1]);
+ var expected = createRectangle(test[2]);
expect(r0.intersection(r1), expected);
expect(r1.intersection(r0), expected);
@@ -46,9 +44,9 @@ main() {
});
test('intersects', () {
- var r0 = new Rect(10, 10, 20, 20);
- var r1 = new Rect(15, 15, 25, 25);
- var r2 = new Rect(0, 0, 1, 1);
+ var r0 = new Rectangle(10, 10, 20, 20);
+ var r1 = new Rectangle(15, 15, 25, 25);
+ var r2 = new Rectangle(0, 0, 1, 1);
expect(r0.intersects(r1), isTrue);
expect(r1.intersects(r0), isTrue);
@@ -57,7 +55,7 @@ main() {
expect(r2.intersects(r0), isFalse);
});
- test('union', () {
+ test('boundingBox', () {
var tests = [
[[10, 10, 20, 20], [15, 15, 25, 25], [10, 10, 25, 25]],
[[10, 10, 20, 20], [20, 0, 30, 10], [10, 0, 30, 20]],
@@ -65,38 +63,38 @@ main() {
[[11, 12, 98, 99], [22, 23, 34, 35], [11, 12, 98, 99]]];
for (var test in tests) {
- var r0 = createRect(test[0]);
- var r1 = createRect(test[1]);
- var expected = createRect(test[2]);
+ var r0 = createRectangle(test[0]);
+ var r1 = createRectangle(test[1]);
+ var expected = createRectangle(test[2]);
- expect(r0.union(r1), expected);
- expect(r1.union(r0), expected);
+ expect(r0.boundingBox(r1), expected);
+ expect(r1.boundingBox(r0), expected);
}
});
- test('containsRect', () {
- var r = new Rect(-10, 0, 20, 10);
- expect(r.containsRect(r), isTrue);
-
- expect(r.containsRect(
- new Rect(double.NAN, double.NAN, double.NAN, double.NAN)), isFalse);
-
- var r2 = new Rect(0, 2, 5, 5);
- expect(r.containsRect(r2), isTrue);
- expect(r2.containsRect(r), isFalse);
-
- r2 = new Rect(-11, 2, 5, 5);
- expect(r.containsRect(r2), isFalse);
- r2 = new Rect(0, 2, 15, 5);
- expect(r.containsRect(r2), isFalse);
- r2 = new Rect(0, 2, 5, 10);
- expect(r.containsRect(r2), isFalse);
- r2 = new Rect(0, 0, 5, 10);
- expect(r.containsRect(r2), isTrue);
+ test('containsRectangle', () {
+ var r = new Rectangle(-10, 0, 20, 10);
+ expect(r.contains(r), isTrue);
+
+ expect(r.contains(
+ new Rectangle(double.NAN, double.NAN, double.NAN, double.NAN)), isFalse);
+
+ var r2 = new Rectangle(0, 2, 5, 5);
+ expect(r.contains(r2), isTrue);
+ expect(r2.contains(r), isFalse);
+
+ r2 = new Rectangle(-11, 2, 5, 5);
+ expect(r.contains(r2), isFalse);
+ r2 = new Rectangle(0, 2, 15, 5);
+ expect(r.contains(r2), isFalse);
+ r2 = new Rectangle(0, 2, 5, 10);
+ expect(r.contains(r2), isFalse);
+ r2 = new Rectangle(0, 0, 5, 10);
+ expect(r.contains(r2), isTrue);
});
test('containsPoint', () {
- var r = new Rect(20, 40, 60, 80);
+ var r = new Rectangle(20, 40, 60, 80);
// Test middle.
expect(r.containsPoint(new Point(50, 80)), isTrue);
@@ -122,38 +120,12 @@ main() {
expect(r.containsPoint(new Point(0, 80)), isFalse);
});
- test('ceil', () {
- var rect = new Rect(11.4, 26.6, 17.8, 9.2);
- expect(rect.ceil(), new Rect(12.0, 27.0, 18.0, 10.0));
- });
-
- test('floor', () {
- var rect = new Rect(11.4, 26.6, 17.8, 9.2);
- expect(rect.floor(), new Rect(11.0, 26.0, 17.0, 9.0));
- });
-
- test('round', () {
- var rect = new Rect(11.4, 26.6, 17.8, 9.2);
- expect(rect.round(), new Rect(11.0, 27.0, 18.0, 9.0));
- });
-
- test('toInt', () {
- var rect = new Rect(11.4, 26.6, 17.8, 9.2);
- var b = rect.toInt();
- expect(b, new Rect(11, 26, 17, 9));
-
- expect(b.left is int, isTrue);
- expect(b.top is int, isTrue);
- expect(b.width is int, isTrue);
- expect(b.height is int, isTrue);
- });
-
test('hashCode', () {
- var a = new Rect(0, 1, 2, 3);
- var b = new Rect(0, 1, 2, 3);
+ var a = new Rectangle(0, 1, 2, 3);
+ var b = new Rectangle(0, 1, 2, 3);
expect(a.hashCode, b.hashCode);
- var c = new Rect(1, 0, 2, 3);
+ var c = new Rectangle(1, 0, 2, 3);
expect(a.hashCode == c.hashCode, isFalse);
});
}

Powered by Google App Engine
This is Rietveld 408576698