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

Side by Side Diff: tests/lib/math/point_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 unified diff | Download patch | Annotate | Revision Log
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 point_test; 5 library point_test;
6 6
7 import 'dart:html'; 7 import 'dart:math';
8 import '../../pkg/unittest/lib/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import '../../pkg/unittest/lib/html_config.dart';
10 9
11 main() { 10 main() {
12 useHtmlConfiguration();
13
14 test('constructor', () { 11 test('constructor', () {
15 var point = new Point(); 12 var point = new Point();
16 expect(point.x, 0); 13 expect(point.x, 0);
17 expect(point.y, 0); 14 expect(point.y, 0);
18 expect('$point', '(0, 0)'); 15 expect('$point', '(0, 0)');
19 }); 16 });
20 17
21 test('constructor X', () { 18 test('constructor X', () {
22 var point = new Point(10); 19 var point = new Point<int>(10);
23 expect(point.x, 10); 20 expect(point.x, 10);
24 expect(point.y, 0); 21 expect(point.y, 0);
25 expect('$point', '(10, 0)'); 22 expect('$point', '(10, 0)');
26 }); 23 });
27 24
28 test('constructor X Y', () { 25 test('constructor X Y', () {
29 var point = new Point(10, 20); 26 var point = new Point<int>(10, 20);
30 expect(point.x, 10); 27 expect(point.x, 10);
31 expect(point.y, 20); 28 expect(point.y, 20);
32 expect('$point', '(10, 20)'); 29 expect('$point', '(10, 20)');
33 }); 30 });
34 31
35 test('constructor X Y double', () { 32 test('constructor X Y double', () {
36 var point = new Point(10.5, 20.897); 33 var point = new Point<double>(10.5, 20.897);
37 expect(point.x, 10.5); 34 expect(point.x, 10.5);
38 expect(point.y, 20.897); 35 expect(point.y, 20.897);
39 expect('$point', '(10.5, 20.897)'); 36 expect('$point', '(10.5, 20.897)');
40 }); 37 });
41 38
42 test('constructor X Y NaN', () { 39 test('constructor X Y NaN', () {
43 var point = new Point(double.NAN, 1000); 40 var point = new Point(double.NAN, 1000);
44 expect(point.x.isNaN, isTrue); 41 expect(point.x.isNaN, isTrue);
45 expect(point.y, 1000); 42 expect(point.y, 1000);
46 expect('$point', '(NaN, 1000)'); 43 expect('$point', '(NaN, 1000)');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 }); 86 });
90 87
91 test('round', () { 88 test('round', () {
92 var a = new Point(5.1, 10.8); 89 var a = new Point(5.1, 10.8);
93 expect(a.round(), new Point(5.0, 11.0)); 90 expect(a.round(), new Point(5.0, 11.0));
94 91
95 var b = new Point(5, 10); 92 var b = new Point(5, 10);
96 expect(b.round(), new Point(5, 10)); 93 expect(b.round(), new Point(5, 10));
97 }); 94 });
98 95
99 test('toInt', () { 96 test('truncate', () {
100 var a = new Point(5.1, 10.8); 97 var a = new Point(5.1, 10.8);
101 var b = a.toInt(); 98 var b = a.truncate();
102 expect(b, new Point(5, 10)); 99 expect(b, new Point(5, 10));
103 expect(b.x is int, isTrue); 100 expect(b.x is int, isTrue);
104 expect(b.y is int, isTrue); 101 expect(b.y is int, isTrue);
105 }); 102 });
106 103
107 test('hashCode', () { 104 test('hashCode', () {
108 var a = new Point(0, 1); 105 var a = new Point(0, 1);
109 var b = new Point(0, 1); 106 var b = new Point(0, 1);
110 expect(a.hashCode, b.hashCode); 107 expect(a.hashCode, b.hashCode);
111 108
112 var c = new Point(1, 0); 109 var c = new Point(1, 0);
113 expect(a.hashCode == c.hashCode, isFalse); 110 expect(a.hashCode == c.hashCode, isFalse);
114 }); 111 });
115 112
116 test('magnitute', () { 113 test('magnitute', () {
117 var a = new Point(5, 10); 114 var a = new Point(5, 10);
118 var b = new Point(0, 0); 115 var b = new Point(0, 0);
119 expect(a.magnitude, a.distanceTo(b)); 116 expect(a.magnitude, a.distanceTo(b));
120 expect(b.magnitude, 0); 117 expect(b.magnitude, 0);
121 118
122 var c = new Point(-5, -10); 119 var c = new Point(-5, -10);
123 expect(c.magnitude, a.distanceTo(b)); 120 expect(c.magnitude, a.distanceTo(b));
124 }); 121 });
125 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698