OLD | NEW |
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', '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', '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', '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', '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', 'Point(NaN, 1000)'); |
47 }); | 44 }); |
48 | 45 |
49 test('squaredDistanceTo', () { | 46 test('squaredDistanceTo', () { |
50 var a = new Point(7, 11); | 47 var a = new Point(7, 11); |
51 var b = new Point(3, -1); | 48 var b = new Point(3, -1); |
52 expect(a.squaredDistanceTo(b), 160); | 49 expect(a.squaredDistanceTo(b), 160); |
53 expect(b.squaredDistanceTo(a), 160); | 50 expect(b.squaredDistanceTo(a), 160); |
54 }); | 51 }); |
55 | 52 |
56 test('distanceTo', () { | 53 test('distanceTo', () { |
57 var a = new Point(-2, -3); | 54 var a = new Point(-2, -3); |
58 var b = new Point(2, 0); | 55 var b = new Point(2, 0); |
59 expect(a.distanceTo(b), 5); | 56 expect(a.distanceTo(b), 5); |
60 expect(b.distanceTo(a), 5); | 57 expect(b.distanceTo(a), 5); |
61 }); | 58 }); |
62 | 59 |
63 test('subtract', () { | 60 test('subtract', () { |
64 var a = new Point(5, 10); | 61 var a = new Point(5, 10); |
65 var b = new Point(2, 50); | 62 var b = new Point(2, 50); |
66 expect(a - b, new Point(3, -40)); | 63 expect(a - b, new Point(3, -40)); |
67 }); | 64 }); |
68 | 65 |
69 test('add', () { | 66 test('add', () { |
70 var a = new Point(5, 10); | 67 var a = new Point(5, 10); |
71 var b = new Point(2, 50); | 68 var b = new Point(2, 50); |
72 expect(a + b, new Point(7, 60)); | 69 expect(a + b, new Point(7, 60)); |
73 }); | 70 }); |
74 | 71 |
75 test('ceil', () { | |
76 var a = new Point(5.1, 10.8); | |
77 expect(a.ceil(), new Point(6.0, 11.0)); | |
78 | |
79 var b = new Point(5, 10); | |
80 expect(b.ceil(), new Point(5, 10)); | |
81 }); | |
82 | |
83 test('floor', () { | |
84 var a = new Point(5.1, 10.8); | |
85 expect(a.floor(), new Point(5.0, 10.0)); | |
86 | |
87 var b = new Point(5, 10); | |
88 expect(b.floor(), new Point(5, 10)); | |
89 }); | |
90 | |
91 test('round', () { | |
92 var a = new Point(5.1, 10.8); | |
93 expect(a.round(), new Point(5.0, 11.0)); | |
94 | |
95 var b = new Point(5, 10); | |
96 expect(b.round(), new Point(5, 10)); | |
97 }); | |
98 | |
99 test('toInt', () { | |
100 var a = new Point(5.1, 10.8); | |
101 var b = a.toInt(); | |
102 expect(b, new Point(5, 10)); | |
103 expect(b.x is int, isTrue); | |
104 expect(b.y is int, isTrue); | |
105 }); | |
106 | |
107 test('hashCode', () { | 72 test('hashCode', () { |
108 var a = new Point(0, 1); | 73 var a = new Point(0, 1); |
109 var b = new Point(0, 1); | 74 var b = new Point(0, 1); |
110 expect(a.hashCode, b.hashCode); | 75 expect(a.hashCode, b.hashCode); |
111 | 76 |
112 var c = new Point(1, 0); | 77 var c = new Point(1, 0); |
113 expect(a.hashCode == c.hashCode, isFalse); | 78 expect(a.hashCode == c.hashCode, isFalse); |
114 }); | 79 }); |
115 | 80 |
116 test('magnitute', () { | 81 test('magnitute', () { |
117 var a = new Point(5, 10); | 82 var a = new Point(5, 10); |
118 var b = new Point(0, 0); | 83 var b = new Point(0, 0); |
119 expect(a.magnitude, a.distanceTo(b)); | 84 expect(a.magnitude, a.distanceTo(b)); |
120 expect(b.magnitude, 0); | 85 expect(b.magnitude, 0); |
121 | 86 |
122 var c = new Point(-5, -10); | 87 var c = new Point(-5, -10); |
123 expect(c.magnitude, a.distanceTo(b)); | 88 expect(c.magnitude, a.distanceTo(b)); |
124 }); | 89 }); |
125 } | 90 } |
OLD | NEW |