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