]> git.localhorst.tv Git - blank.git/blob - tst/world/BlockTest.cpp
(shabby) client side handling of messages
[blank.git] / tst / world / BlockTest.cpp
1 #include "BlockTest.hpp"
2
3 #include "world/Block.hpp"
4
5 #include <glm/gtx/io.hpp>
6
7 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::BlockTest);
8
9
10 namespace blank {
11 namespace test {
12
13 void BlockTest::setUp() {
14 }
15
16 void BlockTest::tearDown() {
17 }
18
19
20 void BlockTest::testFaceOpposite() {
21         CPPUNIT_ASSERT_EQUAL_MESSAGE(
22                 "DOWN not opposite of UP",
23                 Block::FACE_DOWN, Block::Opposite(Block::FACE_UP)
24         );
25         CPPUNIT_ASSERT_EQUAL_MESSAGE(
26                 "UP not opposite of DOWN",
27                 Block::FACE_UP, Block::Opposite(Block::FACE_DOWN)
28         );
29         CPPUNIT_ASSERT_EQUAL_MESSAGE(
30                 "LEFT not opposite of RIGHT",
31                 Block::FACE_LEFT, Block::Opposite(Block::FACE_RIGHT)
32         );
33         CPPUNIT_ASSERT_EQUAL_MESSAGE(
34                 "RIGHT not opposite of LEFT",
35                 Block::FACE_RIGHT, Block::Opposite(Block::FACE_LEFT)
36         );
37         CPPUNIT_ASSERT_EQUAL_MESSAGE(
38                 "BACK not opposite of FRONT",
39                 Block::FACE_BACK, Block::Opposite(Block::FACE_FRONT)
40         );
41         CPPUNIT_ASSERT_EQUAL_MESSAGE(
42                 "FRONT not opposite of BACk",
43                 Block::FACE_FRONT, Block::Opposite(Block::FACE_BACK)
44         );
45 }
46
47 void BlockTest::testFaceAxis() {
48         CPPUNIT_ASSERT_EQUAL_MESSAGE(
49                 "1/Y not axis of UP",
50                 1, Block::Axis(Block::FACE_UP)
51         );
52         CPPUNIT_ASSERT_EQUAL_MESSAGE(
53                 "1/Y not axis of DOWN",
54                 1, Block::Axis(Block::FACE_DOWN)
55         );
56         CPPUNIT_ASSERT_EQUAL_MESSAGE(
57                 "0/X not axis of RIGHT",
58                 0, Block::Axis(Block::FACE_RIGHT)
59         );
60         CPPUNIT_ASSERT_EQUAL_MESSAGE(
61                 "0/X not axis of LEFT",
62                 0, Block::Axis(Block::FACE_LEFT)
63         );
64         CPPUNIT_ASSERT_EQUAL_MESSAGE(
65                 "2/Z not axis of FRONT",
66                 2, Block::Axis(Block::FACE_FRONT)
67         );
68         CPPUNIT_ASSERT_EQUAL_MESSAGE(
69                 "2/Z not axis of BACK",
70                 2, Block::Axis(Block::FACE_BACK)
71         );
72 }
73
74 void BlockTest::testFaceNormal() {
75         CPPUNIT_ASSERT_EQUAL_MESSAGE(
76                 "[ 0, 1, 0 ] not normal of UP",
77                 glm::ivec3(0, 1, 0), Block::FaceNormal(Block::FACE_UP)
78         );
79         CPPUNIT_ASSERT_EQUAL_MESSAGE(
80                 "[ 0, -1, 0 ] not normal of DOWN",
81                 glm::ivec3(0, -1, 0), Block::FaceNormal(Block::FACE_DOWN)
82         );
83         CPPUNIT_ASSERT_EQUAL_MESSAGE(
84                 "[ 1, 0, 0 ] not normal of RIGHT",
85                 glm::ivec3(1, 0, 0), Block::FaceNormal(Block::FACE_RIGHT)
86         );
87         CPPUNIT_ASSERT_EQUAL_MESSAGE(
88                 "[ -1, 0, 0 ] not normal of LEFT",
89                 glm::ivec3(-1, 0, 0), Block::FaceNormal(Block::FACE_LEFT)
90         );
91         CPPUNIT_ASSERT_EQUAL_MESSAGE(
92                 "[ 0, 0, 1 ] not normal of FRONT",
93                 glm::ivec3(0, 0, 1), Block::FaceNormal(Block::FACE_FRONT)
94         );
95         CPPUNIT_ASSERT_EQUAL_MESSAGE(
96                 "[ 0, 0, -1 ] not normal of BACK",
97                 glm::ivec3(0, 0, -1), Block::FaceNormal(Block::FACE_BACK)
98         );
99 }
100
101 void BlockTest::testNormalFace() {
102         CPPUNIT_ASSERT_EQUAL_MESSAGE(
103                 "UP not face of [ 0, 1, 0 ]",
104                 Block::FACE_UP, Block::NormalFace(glm::vec3(0, 1, 0))
105         );
106         CPPUNIT_ASSERT_EQUAL_MESSAGE(
107                 "DOWN not face of [ 0, -1, 0 ]",
108                 Block::FACE_DOWN, Block::NormalFace(glm::vec3(0, -1, 0))
109         );
110         CPPUNIT_ASSERT_EQUAL_MESSAGE(
111                 "RIGHT not face of [ 1, 0, 0 ]",
112                 Block::FACE_RIGHT, Block::NormalFace(glm::vec3(1, 0, 0))
113         );
114         CPPUNIT_ASSERT_EQUAL_MESSAGE(
115                 "LEFT not face of [ -1, 0, 0 ]",
116                 Block::FACE_LEFT, Block::NormalFace(glm::vec3(-1, 0, 0))
117         );
118         CPPUNIT_ASSERT_EQUAL_MESSAGE(
119                 "FRONT not face of [ 0, 0, 1 ]",
120                 Block::FACE_FRONT, Block::NormalFace(glm::vec3(0, 0, 1))
121         );
122         CPPUNIT_ASSERT_EQUAL_MESSAGE(
123                 "BACK not face of [ 0, 0, -1 ]",
124                 Block::FACE_BACK, Block::NormalFace(glm::vec3(0, 0, -1))
125         );
126 }
127
128
129 void BlockTest::testFaceSet() {
130         Block::FaceSet set;
131         CPPUNIT_ASSERT_MESSAGE(
132                 "default faceset not empty",
133                 set.Empty()
134         );
135         for (int i = 0; i < Block::FACE_COUNT; ++i) {
136                 CPPUNIT_ASSERT_MESSAGE(
137                         "something set on default faceset",
138                         !set.IsSet(Block::Face(i))
139                 );
140         }
141         set.Fill();
142         CPPUNIT_ASSERT_MESSAGE(
143                 "not all set on filled faceset",
144                 set.All()
145         );
146         for (int i = 0; i < Block::FACE_COUNT; ++i) {
147                 CPPUNIT_ASSERT_MESSAGE(
148                         "something not set on filled faceset",
149                         set.IsSet(Block::Face(i))
150                 );
151         }
152         set.Clear();
153         CPPUNIT_ASSERT_MESSAGE(
154                 "cleared faceset not empty",
155                 set.Empty()
156         );
157         for (int i = 0; i < Block::FACE_COUNT; ++i) {
158                 CPPUNIT_ASSERT_MESSAGE(
159                         "something set on cleared faceset",
160                         !set.IsSet(Block::Face(i))
161                 );
162                 set.Set(Block::Face(i));
163                 CPPUNIT_ASSERT_MESSAGE(
164                         "face not set after setting",
165                         set.IsSet(Block::Face(i))
166                 );
167         }
168         CPPUNIT_ASSERT_MESSAGE(
169                 "set not filled after setting all faces",
170                 set.All()
171         );
172         for (int i = 0; i < Block::FACE_COUNT; ++i) {
173                 CPPUNIT_ASSERT_MESSAGE(
174                         "something not set after setting all faces",
175                         set.IsSet(Block::Face(i))
176                 );
177                 set.Unset(Block::Face(i));
178                 CPPUNIT_ASSERT_MESSAGE(
179                         "face set after unsetting",
180                         !set.IsSet(Block::Face(i))
181                 );
182         }
183         CPPUNIT_ASSERT_MESSAGE(
184                 "set not empty after unsetting all faces",
185                 set.Empty()
186         );
187 }
188
189
190 void BlockTest::testDefaultBlock() {
191         Block block;
192         CPPUNIT_ASSERT_EQUAL_MESSAGE(
193                 "0 type id of default block",
194                 Block::Type(0), block.type
195         );
196         CPPUNIT_ASSERT_EQUAL_MESSAGE(
197                 "identity transform of default block",
198                 glm::mat4(1), block.Transform()
199         );
200         CPPUNIT_ASSERT_EQUAL_MESSAGE(
201                 "no turn of default block",
202                 Block::TURN_NONE, block.GetTurn()
203         );
204         for (int i = 0; i < Block::FACE_COUNT; ++i) {
205                 CPPUNIT_ASSERT_EQUAL_MESSAGE(
206                         "face is oriented face of default block",
207                         Block::Face(i), block.OrientedFace(Block::Face(i))
208                 );
209         }
210 }
211
212 }
213 }