1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include "core.h" |
---|
16 | #include "lol/unit.h" |
---|
17 | |
---|
18 | namespace lol |
---|
19 | { |
---|
20 | |
---|
21 | LOLUNIT_FIXTURE(VectorTest) |
---|
22 | { |
---|
23 | void SetUp() {} |
---|
24 | |
---|
25 | void TearDown() {} |
---|
26 | |
---|
27 | LOLUNIT_TEST(VectorEquality) |
---|
28 | { |
---|
29 | vec2 a2(1.0f, 2.0f); |
---|
30 | vec2 b2(0.0f, 2.0f); |
---|
31 | vec2 c2(1.0f, 0.0f); |
---|
32 | |
---|
33 | LOLUNIT_ASSERT_EQUAL(a2, a2); |
---|
34 | LOLUNIT_ASSERT_NOT_DIFFERENT(a2, a2); |
---|
35 | |
---|
36 | LOLUNIT_ASSERT_DIFFERENT(a2, b2); |
---|
37 | LOLUNIT_ASSERT_NOT_EQUAL(a2, b2); |
---|
38 | LOLUNIT_ASSERT_DIFFERENT(a2, c2); |
---|
39 | LOLUNIT_ASSERT_NOT_EQUAL(a2, c2); |
---|
40 | |
---|
41 | vec3 a3(1.0f, 2.0f, 3.0f); |
---|
42 | vec3 b3(0.0f, 2.0f, 3.0f); |
---|
43 | vec3 c3(1.0f, 0.0f, 3.0f); |
---|
44 | vec3 d3(1.0f, 2.0f, 0.0f); |
---|
45 | |
---|
46 | LOLUNIT_ASSERT_EQUAL(a3, a3); |
---|
47 | LOLUNIT_ASSERT_NOT_DIFFERENT(a3, a3); |
---|
48 | |
---|
49 | LOLUNIT_ASSERT_DIFFERENT(a3, b3); |
---|
50 | LOLUNIT_ASSERT_NOT_EQUAL(a3, b3); |
---|
51 | LOLUNIT_ASSERT_DIFFERENT(a3, c3); |
---|
52 | LOLUNIT_ASSERT_NOT_EQUAL(a3, c3); |
---|
53 | LOLUNIT_ASSERT_DIFFERENT(a3, d3); |
---|
54 | LOLUNIT_ASSERT_NOT_EQUAL(a3, d3); |
---|
55 | |
---|
56 | vec4 a4(1.0f, 2.0f, 3.0f, 4.0f); |
---|
57 | vec4 b4(0.0f, 2.0f, 3.0f, 4.0f); |
---|
58 | vec4 c4(1.0f, 0.0f, 3.0f, 4.0f); |
---|
59 | vec4 d4(1.0f, 2.0f, 0.0f, 4.0f); |
---|
60 | vec4 e4(1.0f, 2.0f, 3.0f, 0.0f); |
---|
61 | |
---|
62 | LOLUNIT_ASSERT_EQUAL(a4, a4); |
---|
63 | LOLUNIT_ASSERT_NOT_DIFFERENT(a4, a4); |
---|
64 | |
---|
65 | LOLUNIT_ASSERT_DIFFERENT(a4, b4); |
---|
66 | LOLUNIT_ASSERT_NOT_EQUAL(a4, b4); |
---|
67 | LOLUNIT_ASSERT_DIFFERENT(a4, c4); |
---|
68 | LOLUNIT_ASSERT_NOT_EQUAL(a4, c4); |
---|
69 | LOLUNIT_ASSERT_DIFFERENT(a4, d4); |
---|
70 | LOLUNIT_ASSERT_NOT_EQUAL(a4, d4); |
---|
71 | LOLUNIT_ASSERT_DIFFERENT(a4, e4); |
---|
72 | LOLUNIT_ASSERT_NOT_EQUAL(a4, e4); |
---|
73 | } |
---|
74 | |
---|
75 | LOLUNIT_TEST(VectorInequality) |
---|
76 | { |
---|
77 | vec2 a2(1.0f, 3.0f); |
---|
78 | vec2 b2(0.0f, 0.0f); |
---|
79 | vec2 c2(1.0f, 1.0f); |
---|
80 | vec2 d2(2.0f, 2.0f); |
---|
81 | vec2 e2(3.0f, 3.0f); |
---|
82 | vec2 f2(4.0f, 4.0f); |
---|
83 | |
---|
84 | LOLUNIT_ASSERT_LEQUAL(a2, a2); |
---|
85 | LOLUNIT_ASSERT_NOT_LESS(a2, a2); |
---|
86 | |
---|
87 | LOLUNIT_ASSERT_NOT_LEQUAL(a2, b2); |
---|
88 | LOLUNIT_ASSERT_NOT_LESS(a2, b2); |
---|
89 | LOLUNIT_ASSERT_NOT_LEQUAL(a2, c2); |
---|
90 | LOLUNIT_ASSERT_NOT_LESS(a2, c2); |
---|
91 | LOLUNIT_ASSERT_NOT_LEQUAL(a2, d2); |
---|
92 | LOLUNIT_ASSERT_NOT_LESS(a2, d2); |
---|
93 | LOLUNIT_ASSERT_LEQUAL(a2, e2); |
---|
94 | LOLUNIT_ASSERT_NOT_LESS(a2, e2); |
---|
95 | LOLUNIT_ASSERT_LEQUAL(a2, f2); |
---|
96 | LOLUNIT_ASSERT_LESS(a2, f2); |
---|
97 | } |
---|
98 | |
---|
99 | LOLUNIT_TEST(VectorUnaryMinus) |
---|
100 | { |
---|
101 | vec2 a(1.0f, 3.0f); |
---|
102 | vec2 b(-1.0f, -3.0f); |
---|
103 | |
---|
104 | LOLUNIT_ASSERT_EQUAL(a, -b); |
---|
105 | LOLUNIT_ASSERT_EQUAL(-a, b); |
---|
106 | } |
---|
107 | |
---|
108 | LOLUNIT_TEST(CastVector) |
---|
109 | { |
---|
110 | vec2 a1(1.0f, 3.0f); |
---|
111 | |
---|
112 | vec3 b(a1, 0.0f); |
---|
113 | vec2 a2(b.xy); |
---|
114 | LOLUNIT_ASSERT_EQUAL(b.x, a1.x); |
---|
115 | LOLUNIT_ASSERT_EQUAL(b.y, a1.y); |
---|
116 | LOLUNIT_ASSERT_EQUAL(b.z, 0.0f); |
---|
117 | LOLUNIT_ASSERT_EQUAL(a2, a1); |
---|
118 | |
---|
119 | vec4 c(a1, 0.0f, 0.0f); |
---|
120 | vec2 a3(c.xy); |
---|
121 | LOLUNIT_ASSERT_EQUAL(c.x, a1.x); |
---|
122 | LOLUNIT_ASSERT_EQUAL(c.y, a1.y); |
---|
123 | LOLUNIT_ASSERT_EQUAL(c.z, 0.0f); |
---|
124 | LOLUNIT_ASSERT_EQUAL(c.w, 0.0f); |
---|
125 | LOLUNIT_ASSERT_EQUAL(a3, a1); |
---|
126 | } |
---|
127 | }; |
---|
128 | |
---|
129 | } /* namespace lol */ |
---|
130 | |
---|