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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/math/rectangle.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 var r = new MutableRectangle(0, 0, 1, 1); 170 var r = new MutableRectangle(0, 0, 1, 1);
171 r.width = -1; 171 r.width = -1;
172 r.height = -1; 172 r.height = -1;
173 expect(r, new Rectangle(0, 0, 0, 0)); 173 expect(r, new Rectangle(0, 0, 0, 0));
174 174
175 // Test that doubles are clamped to double zero. 175 // Test that doubles are clamped to double zero.
176 r = new Rectangle(1.5, 1.5, -2.5, -2.5); 176 r = new Rectangle(1.5, 1.5, -2.5, -2.5);
177 expect(identical(r.width, 0.0), isTrue); 177 expect(identical(r.width, 0.0), isTrue);
178 expect(identical(r.height, 0.0), isTrue); 178 expect(identical(r.height, 0.0), isTrue);
179 }); 179 });
180
181 // A NaN-value in any rectangle value means the rectange is considered
182 // empty (contains no points, doesn't intersect any other rectangle).
183 const NaN = double.NAN;
184 var isNaN = predicate((x) => x is double && x.isNaN);
185
186 test('NaN left', () {
187 var rectangles = [
188 const Rectangle(NaN, 1, 2, 3),
189 new MutableRectangle(NaN, 1, 2, 3),
190 new Rectangle.fromPoints(new Point(NaN, 1), new Point(2, 4)),
191 new MutableRectangle.fromPoints(new Point(NaN, 1), new Point(2, 4)),
192 ];
193 for (var r in rectangles) {
194 expect(r.containsPoint(new Point(0, 1)), false);
195 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
196 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
197 expect(r.left, isNaN);
198 expect(r.right, isNaN);
199 }
200 });
201
202 test('NaN top', () {
203 var rectangles = [
204 const Rectangle(0, NaN, 2, 3),
205 new MutableRectangle(0, NaN, 2, 3),
206 new Rectangle.fromPoints(new Point(0, NaN), new Point(2, 4)),
207 new MutableRectangle.fromPoints(new Point(0, NaN), new Point(2, 4)),
208 ];
209 for (var r in rectangles) {
210 expect(r.containsPoint(new Point(0, 1)), false);
211 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
212 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
213 expect(r.top, isNaN);
214 expect(r.bottom, isNaN);
215 }
216 });
217
218 test('NaN width', () {
219 var rectangles = [
220 const Rectangle(0, 1, NaN, 3),
221 new MutableRectangle(0, 1, NaN, 3),
222 new Rectangle.fromPoints(new Point(0, 1), new Point(NaN, 4)),
223 new MutableRectangle.fromPoints(new Point(0, 1), new Point(NaN, 4)),
224 ];
225 for (var r in rectangles) {
226 expect(r.containsPoint(new Point(0, 1)), false);
227 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
228 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
229 expect(r.right, isNaN);
230 expect(r.width, isNaN);
231 }
232 });
233
234 test('NaN heigth', () {
235 var rectangles = [
236 const Rectangle(0, 1, 2, NaN),
237 new MutableRectangle(0, 1, 2, NaN),
238 new Rectangle.fromPoints(new Point(0, 1), new Point(2, NaN)),
239 new MutableRectangle.fromPoints(new Point(0, 1), new Point(2, NaN)),
240 ];
241 for (var r in rectangles) {
242 expect(r.containsPoint(new Point(0, 1)), false);
243 expect(r.containsRectangle(new Rectangle(0, 1, 2, 3)), false);
244 expect(r.intersects(new Rectangle(0, 1, 2, 3)), false);
245 expect(r.bottom, isNaN);
246 expect(r.height, isNaN);
247 }
248 });
180 } 249 }
181 250
OLDNEW
« 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