Mercurial > projects > doodle
comparison doodle/tk/test/test1.d @ 100:a274d16ab6ce
struct initialisers
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Mon, 18 Oct 2010 18:10:02 +1030 |
parents | 1b4c9ba58673 |
children | 89e8b0d92f36 |
comparison
equal
deleted
inserted
replaced
99:ad672ab258c5 | 100:a274d16ab6ce |
---|---|
4 } | 4 } |
5 | 5 |
6 void test1() { | 6 void test1() { |
7 writefln("*** Test1 ***"); | 7 writefln("*** Test1 ***"); |
8 | 8 |
9 Point p1 = Point.DEFAULT; | 9 Point p1; |
10 Point p2 = p1; // copy construction | 10 Point p2 = p1; // copy construction |
11 assert(p1 == p2); // equality | 11 assert(p1 == p2); // equality |
12 assert(!(p1 != p2)); // inequality | 12 assert(!(p1 != p2)); // inequality |
13 p2 = p1; // assignment | 13 p2 = p1; // assignment |
14 assert(p1 == p2); | 14 assert(p1 == p2); |
15 | 15 |
16 Point p3 = Point(3.0, 5.0); // standard constructor | 16 Point p3 = Point(3.0, 5.0); // standard constructor |
17 assert(p3 - p3 == Vector.DEFAULT); // subtraction (point minus point) | 17 assert(p3 - p3 == Vector()); // subtraction (point minus point) |
18 | 18 |
19 Vector v3 = Vector(3.0, 5.0); | 19 Vector v3 = Vector(3.0, 5.0); |
20 assert(p3 - v3 == Point.DEFAULT); // subtraction (point minus vector) | 20 assert(p3 - v3 == Point()); // subtraction (point minus vector) |
21 | 21 |
22 Point p4 = Point(1.0, 10.0); | 22 Point p4 = Point(1.0, 10.0); |
23 Point p5 = Point(10.0, 1.0); | 23 Point p5 = Point(10.0, 1.0); |
24 assert(minExtents(p4, p5) == Point(1.0, 1.0)); // min extents | 24 assert(minExtents(p4, p5) == Point(1.0, 1.0)); // min extents |
25 assert(maxExtents(p4, p5) == Point(10.0, 10.0)); // max extents | 25 assert(maxExtents(p4, p5) == Point(10.0, 10.0)); // max extents |
28 } | 28 } |
29 | 29 |
30 void test2() { | 30 void test2() { |
31 writefln("*** Test2 ***"); | 31 writefln("*** Test2 ***"); |
32 | 32 |
33 Vector v1 = Vector.DEFAULT; | 33 Vector v1; |
34 Vector v2 = v1; // copy construction | 34 Vector v2 = v1; // copy construction |
35 assert(v1 == v2); // equality | 35 assert(v1 == v2); // equality |
36 assert(!(v1 != v2)); // inequality | 36 assert(!(v1 != v2)); // inequality |
37 v2 = v1; // assignment | 37 v2 = v1; // assignment |
38 | 38 |
39 Vector v3 = Vector(3.0, 4.0); // standard construction | 39 Vector v3 = Vector(3.0, 4.0); // standard construction |
40 assert(v3 + v3 == Vector(6.0, 8.0)); // addition | 40 assert(v3 + v3 == Vector(6.0, 8.0)); // addition |
41 assert(v3 - v3 == Vector.DEFAULT); // subtraction | 41 assert(v3 - v3 == Vector()); // subtraction |
42 assert(-v3 == Vector(-3.0, -4.0)); // negation | 42 assert(-v3 == Vector(-3.0, -4.0)); // negation |
43 assert(v3.length == 5.0); // length | 43 assert(v3.length == 5.0); // length |
44 assert(2.0 * v3 == Vector(6.0, 8.0)); // scalar multiplication | 44 assert(2.0 * v3 == Vector(6.0, 8.0)); // scalar multiplication |
45 assert(v3 / 2.0 == Vector(1.5, 2.0)); // scalar division | 45 assert(v3 / 2.0 == Vector(1.5, 2.0)); // scalar division |
46 | 46 |