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 import 'dart:math'; | |
6 import 'package:expect/expect.dart'; | |
7 | |
8 main() { | |
9 // constructor | |
10 { | |
11 var point = new Point(0, 0); | |
12 Expect.equals(0, point.x); | |
13 Expect.equals(0, point.y); | |
14 Expect.equals('Point(0, 0)', '$point'); | |
15 } | |
16 | |
17 // constructor X | |
18 { | |
19 var point = new Point<int>(10, 0); | |
20 Expect.equals(10, point.x); | |
21 Expect.equals(0, point.y); | |
22 Expect.equals('Point(10, 0)', '$point'); | |
23 } | |
24 | |
25 // constructor X Y | |
26 { | |
27 var point = new Point<int>(10, 20); | |
28 Expect.equals(10, point.x); | |
29 Expect.equals(20, point.y); | |
30 Expect.equals('Point(10, 20)', '$point'); | |
31 } | |
32 | |
33 // constructor X Y double | |
34 { | |
35 var point = new Point<double>(10.5, 20.897); | |
36 Expect.equals(10.5, point.x); | |
37 Expect.equals(20.897, point.y); | |
38 Expect.equals('Point(10.5, 20.897)', '$point'); | |
39 } | |
40 | |
41 // constructor X Y NaN | |
42 { | |
43 var point = new Point(double.NAN, 1000); | |
44 Expect.isTrue(point.x.isNaN); | |
45 Expect.equals(1000, point.y); | |
46 Expect.equals('Point(NaN, 1000)', '$point'); | |
47 } | |
48 | |
49 // squaredDistanceTo | |
50 { | |
51 var a = new Point(7, 11); | |
52 var b = new Point(3, -1); | |
53 Expect.equals(160, a.squaredDistanceTo(b)); | |
54 Expect.equals(160, b.squaredDistanceTo(a)); | |
55 } | |
56 | |
57 // distanceTo | |
58 { | |
59 var a = new Point(-2, -3); | |
60 var b = new Point(2, 0); | |
61 Expect.equals(5, a.distanceTo(b)); | |
62 Expect.equals(5, b.distanceTo(a)); | |
63 } | |
64 | |
65 // subtract | |
66 { | |
67 var a = new Point(5, 10); | |
68 var b = new Point(2, 50); | |
69 Expect.equals(new Point(3, -40), a - b); | |
70 } | |
71 | |
72 // add | |
73 { | |
74 var a = new Point(5, 10); | |
75 var b = new Point(2, 50); | |
76 Expect.equals(new Point(7, 60), a + b); | |
77 } | |
78 | |
79 // hashCode | |
80 { | |
81 var a = new Point(0, 1); | |
82 var b = new Point(0, 1); | |
83 Expect.equals(b.hashCode, a.hashCode); | |
84 | |
85 var c = new Point(1, 0); | |
86 Expect.isFalse(a.hashCode == c.hashCode); | |
87 } | |
88 | |
89 // magnitude | |
90 { | |
91 var a = new Point(5, 10); | |
92 var b = new Point(0, 0); | |
93 Expect.equals(a.distanceTo(b), a.magnitude); | |
94 Expect.equals(0, b.magnitude); | |
95 | |
96 var c = new Point(-5, -10); | |
97 Expect.equals(a.distanceTo(b), c.magnitude); | |
98 } | |
99 } | |
OLD | NEW |