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

Side by Side Diff: tests/lib/math/rectangle_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library rect_test; 5 library rect_test;
6 6
7 import 'dart:math'; 7 import 'dart:math';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 main() { 10 main() {
11 Rectangle createRectangle(List<num> a) { 11 Rectangle createRectangle(List<num> a) {
12 return a != null ? new Rectangle(a[0], a[1], a[2] - a[0], a[3] - a[1]) 12 return a != null
13 ? new Rectangle(a[0], a[1], a[2] - a[0], a[3] - a[1])
13 : null; 14 : null;
14 } 15 }
15 16
16 test('construction', () { 17 test('construction', () {
17 var r0 = new Rectangle(10, 20, 30, 40); 18 var r0 = new Rectangle(10, 20, 30, 40);
18 expect(r0.toString(), 'Rectangle (10, 20) 30 x 40'); 19 expect(r0.toString(), 'Rectangle (10, 20) 30 x 40');
19 expect(r0.right, 40); 20 expect(r0.right, 40);
20 expect(r0.bottom, 60); 21 expect(r0.bottom, 60);
21 22
22 var r1 = new Rectangle.fromPoints(r0.topLeft, r0.bottomRight); 23 var r1 = new Rectangle.fromPoints(r0.topLeft, r0.bottomRight);
23 expect(r1, r0); 24 expect(r1, r0);
24 25
25 var r2 = new Rectangle.fromPoints(r0.bottomRight, r0.topLeft); 26 var r2 = new Rectangle.fromPoints(r0.bottomRight, r0.topLeft);
26 expect(r2, r0); 27 expect(r2, r0);
27 }); 28 });
28 29
29 test('intersection', () { 30 test('intersection', () {
30 var tests = [ 31 var tests = [
31 [[10, 10, 20, 20], [15, 15, 25, 25], [15, 15, 20, 20]], 32 [
32 [[10, 10, 20, 20], [20, 0, 30, 10], [20, 10, 20, 10]], 33 [10, 10, 20, 20],
33 [[0, 0, 1, 1], [10, 11, 12, 13], null], 34 [15, 15, 25, 25],
34 [[11, 12, 98, 99], [22, 23, 34, 35], [22, 23, 34, 35]]]; 35 [15, 15, 20, 20]
36 ],
37 [
38 [10, 10, 20, 20],
39 [20, 0, 30, 10],
40 [20, 10, 20, 10]
41 ],
42 [
43 [0, 0, 1, 1],
44 [10, 11, 12, 13],
45 null
46 ],
47 [
48 [11, 12, 98, 99],
49 [22, 23, 34, 35],
50 [22, 23, 34, 35]
51 ]
52 ];
35 53
36 for (var test in tests) { 54 for (var test in tests) {
37 var r0 = createRectangle(test[0]); 55 var r0 = createRectangle(test[0]);
38 var r1 = createRectangle(test[1]); 56 var r1 = createRectangle(test[1]);
39 var expected = createRectangle(test[2]); 57 var expected = createRectangle(test[2]);
40 58
41 expect(r0.intersection(r1), expected); 59 expect(r0.intersection(r1), expected);
42 expect(r1.intersection(r0), expected); 60 expect(r1.intersection(r0), expected);
43 } 61 }
44 }); 62 });
45 63
46 test('intersects', () { 64 test('intersects', () {
47 var r0 = new Rectangle(10, 10, 20, 20); 65 var r0 = new Rectangle(10, 10, 20, 20);
48 var r1 = new Rectangle(15, 15, 25, 25); 66 var r1 = new Rectangle(15, 15, 25, 25);
49 var r2 = new Rectangle(0, 0, 1, 1); 67 var r2 = new Rectangle(0, 0, 1, 1);
50 68
51 expect(r0.intersects(r1), isTrue); 69 expect(r0.intersects(r1), isTrue);
52 expect(r1.intersects(r0), isTrue); 70 expect(r1.intersects(r0), isTrue);
53 71
54 expect(r0.intersects(r2), isFalse); 72 expect(r0.intersects(r2), isFalse);
55 expect(r2.intersects(r0), isFalse); 73 expect(r2.intersects(r0), isFalse);
56 }); 74 });
57 75
58 test('boundingBox', () { 76 test('boundingBox', () {
59 var tests = [ 77 var tests = [
60 [[10, 10, 20, 20], [15, 15, 25, 25], [10, 10, 25, 25]], 78 [
61 [[10, 10, 20, 20], [20, 0, 30, 10], [10, 0, 30, 20]], 79 [10, 10, 20, 20],
62 [[0, 0, 1, 1], [10, 11, 12, 13], [0, 0, 12, 13]], 80 [15, 15, 25, 25],
63 [[11, 12, 98, 99], [22, 23, 34, 35], [11, 12, 98, 99]]]; 81 [10, 10, 25, 25]
82 ],
83 [
84 [10, 10, 20, 20],
85 [20, 0, 30, 10],
86 [10, 0, 30, 20]
87 ],
88 [
89 [0, 0, 1, 1],
90 [10, 11, 12, 13],
91 [0, 0, 12, 13]
92 ],
93 [
94 [11, 12, 98, 99],
95 [22, 23, 34, 35],
96 [11, 12, 98, 99]
97 ]
98 ];
64 99
65 for (var test in tests) { 100 for (var test in tests) {
66 var r0 = createRectangle(test[0]); 101 var r0 = createRectangle(test[0]);
67 var r1 = createRectangle(test[1]); 102 var r1 = createRectangle(test[1]);
68 var expected = createRectangle(test[2]); 103 var expected = createRectangle(test[2]);
69 104
70 expect(r0.boundingBox(r1), expected); 105 expect(r0.boundingBox(r1), expected);
71 expect(r1.boundingBox(r0), expected); 106 expect(r1.boundingBox(r0), expected);
72 } 107 }
73 }); 108 });
74 109
75 test('containsRectangle', () { 110 test('containsRectangle', () {
76 var r = new Rectangle(-10, 0, 20, 10); 111 var r = new Rectangle(-10, 0, 20, 10);
77 expect(r.containsRectangle(r), isTrue); 112 expect(r.containsRectangle(r), isTrue);
78 113
79 expect(r.containsRectangle( 114 expect(
80 new Rectangle(double.NAN, double.NAN, double.NAN, double.NAN)), isFalse) ; 115 r.containsRectangle(
116 new Rectangle(double.NAN, double.NAN, double.NAN, double.NAN)),
117 isFalse);
81 118
82 var r2 = new Rectangle(0, 2, 5, 5); 119 var r2 = new Rectangle(0, 2, 5, 5);
83 expect(r.containsRectangle(r2), isTrue); 120 expect(r.containsRectangle(r2), isTrue);
84 expect(r2.containsRectangle(r), isFalse); 121 expect(r2.containsRectangle(r), isFalse);
85 122
86 r2 = new Rectangle(-11, 2, 5, 5); 123 r2 = new Rectangle(-11, 2, 5, 5);
87 expect(r.containsRectangle(r2), isFalse); 124 expect(r.containsRectangle(r2), isFalse);
88 r2 = new Rectangle(0, 2, 15, 5); 125 r2 = new Rectangle(0, 2, 15, 5);
89 expect(r.containsRectangle(r2), isFalse); 126 expect(r.containsRectangle(r2), isFalse);
90 r2 = new Rectangle(0, 2, 5, 10); 127 r2 = new Rectangle(0, 2, 5, 10);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 159
123 test('hashCode', () { 160 test('hashCode', () {
124 var a = new Rectangle(0, 1, 2, 3); 161 var a = new Rectangle(0, 1, 2, 3);
125 var b = new Rectangle(0, 1, 2, 3); 162 var b = new Rectangle(0, 1, 2, 3);
126 expect(a.hashCode, b.hashCode); 163 expect(a.hashCode, b.hashCode);
127 164
128 var c = new Rectangle(1, 0, 2, 3); 165 var c = new Rectangle(1, 0, 2, 3);
129 expect(a.hashCode == c.hashCode, isFalse); 166 expect(a.hashCode == c.hashCode, isFalse);
130 }); 167 });
131 168
132 { // Edge cases for boundingBox/intersection 169 {
170 // Edge cases for boundingBox/intersection
133 edgeTest(a, l) { 171 edgeTest(a, l) {
134 test('edge case $a/$l', () { 172 test('edge case $a/$l', () {
135 var r = new Rectangle(a, a, l, l); 173 var r = new Rectangle(a, a, l, l);
136 expect(r.boundingBox(r), r); 174 expect(r.boundingBox(r), r);
137 expect(r.intersection(r), r); 175 expect(r.intersection(r), r);
138 }); 176 });
139 } 177 }
140 178
141 var bignum1 = 0x20000000000000 + 0.0; 179 var bignum1 = 0x20000000000000 + 0.0;
142 var bignum2 = 0x20000000000002 + 0.0; 180 var bignum2 = 0x20000000000002 + 0.0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ]; 278 ];
241 for (var r in rectangles) { 279 for (var r in rectangles) {
242 expect(r.containsPoint(new Point(0, 1)), false); 280 expect(r.containsPoint(new Point(0, 1)), false);
243 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false); 281 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
244 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false); 282 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
245 expect(r.bottom, isNaN); 283 expect(r.bottom, isNaN);
246 expect(r.height, isNaN); 284 expect(r.height, isNaN);
247 } 285 }
248 }); 286 });
249 } 287 }
250
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698