OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library point_test; | |
6 | |
7 import 'dart:html'; | |
8 import '../../pkg/unittest/lib/unittest.dart'; | |
9 import '../../pkg/unittest/lib/html_config.dart'; | |
10 | |
11 main() { | |
12 useHtmlConfiguration(); | |
13 | |
14 test('constructor', () { | |
15 var point = new Point(); | |
16 expect(point.x, 0); | |
17 expect(point.y, 0); | |
18 expect('$point', '(0, 0)'); | |
19 }); | |
20 | |
21 test('constructor X', () { | |
22 var point = new Point(10); | |
23 expect(point.x, 10); | |
24 expect(point.y, 0); | |
25 expect('$point', '(10, 0)'); | |
26 }); | |
27 | |
28 test('constructor X Y', () { | |
29 var point = new Point(10, 20); | |
30 expect(point.x, 10); | |
31 expect(point.y, 20); | |
32 expect('$point', '(10, 20)'); | |
33 }); | |
34 | |
35 test('constructor X Y double', () { | |
36 var point = new Point(10.5, 20.897); | |
37 expect(point.x, 10.5); | |
38 expect(point.y, 20.897); | |
39 expect('$point', '(10.5, 20.897)'); | |
40 }); | |
41 | |
42 test('constructor X Y NaN', () { | |
43 var point = new Point(double.NAN, 1000); | |
44 expect(point.x.isNaN, isTrue); | |
45 expect(point.y, 1000); | |
46 expect('$point', '(NaN, 1000)'); | |
47 }); | |
48 | |
49 test('squaredDistanceTo', () { | |
50 var a = new Point(7, 11); | |
51 var b = new Point(3, -1); | |
52 expect(a.squaredDistanceTo(b), 160); | |
53 expect(b.squaredDistanceTo(a), 160); | |
54 }); | |
55 | |
56 test('distanceTo', () { | |
57 var a = new Point(-2, -3); | |
58 var b = new Point(2, 0); | |
59 expect(a.distanceTo(b), 5); | |
60 expect(b.distanceTo(a), 5); | |
61 }); | |
62 | |
63 test('subtract', () { | |
64 var a = new Point(5, 10); | |
65 var b = new Point(2, 50); | |
66 expect(a - b, new Point(3, -40)); | |
67 }); | |
68 | |
69 test('add', () { | |
70 var a = new Point(5, 10); | |
71 var b = new Point(2, 50); | |
72 expect(a + b, new Point(7, 60)); | |
73 }); | |
74 | |
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', () { | |
108 var a = new Point(0, 1); | |
109 var b = new Point(0, 1); | |
110 expect(a.hashCode, b.hashCode); | |
111 | |
112 var c = new Point(1, 0); | |
113 expect(a.hashCode == c.hashCode, isFalse); | |
114 }); | |
115 | |
116 test('magnitute', () { | |
117 var a = new Point(5, 10); | |
118 var b = new Point(0, 0); | |
119 expect(a.magnitude, a.distanceTo(b)); | |
120 expect(b.magnitude, 0); | |
121 | |
122 var c = new Point(-5, -10); | |
123 expect(c.magnitude, a.distanceTo(b)); | |
124 }); | |
125 } | |
OLD | NEW |