1 #include "BlockTest.hpp"
3 #include "world/Block.hpp"
5 #include <glm/gtx/io.hpp>
7 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::BlockTest);
13 void BlockTest::setUp() {
16 void BlockTest::tearDown() {
20 void BlockTest::testFaceOpposite() {
21 CPPUNIT_ASSERT_EQUAL_MESSAGE(
22 "DOWN not opposite of UP",
23 Block::FACE_DOWN, Block::Opposite(Block::FACE_UP)
25 CPPUNIT_ASSERT_EQUAL_MESSAGE(
26 "UP not opposite of DOWN",
27 Block::FACE_UP, Block::Opposite(Block::FACE_DOWN)
29 CPPUNIT_ASSERT_EQUAL_MESSAGE(
30 "LEFT not opposite of RIGHT",
31 Block::FACE_LEFT, Block::Opposite(Block::FACE_RIGHT)
33 CPPUNIT_ASSERT_EQUAL_MESSAGE(
34 "RIGHT not opposite of LEFT",
35 Block::FACE_RIGHT, Block::Opposite(Block::FACE_LEFT)
37 CPPUNIT_ASSERT_EQUAL_MESSAGE(
38 "BACK not opposite of FRONT",
39 Block::FACE_BACK, Block::Opposite(Block::FACE_FRONT)
41 CPPUNIT_ASSERT_EQUAL_MESSAGE(
42 "FRONT not opposite of BACk",
43 Block::FACE_FRONT, Block::Opposite(Block::FACE_BACK)
47 void BlockTest::testFaceAxis() {
48 CPPUNIT_ASSERT_EQUAL_MESSAGE(
50 1, Block::Axis(Block::FACE_UP)
52 CPPUNIT_ASSERT_EQUAL_MESSAGE(
53 "1/Y not axis of DOWN",
54 1, Block::Axis(Block::FACE_DOWN)
56 CPPUNIT_ASSERT_EQUAL_MESSAGE(
57 "0/X not axis of RIGHT",
58 0, Block::Axis(Block::FACE_RIGHT)
60 CPPUNIT_ASSERT_EQUAL_MESSAGE(
61 "0/X not axis of LEFT",
62 0, Block::Axis(Block::FACE_LEFT)
64 CPPUNIT_ASSERT_EQUAL_MESSAGE(
65 "2/Z not axis of FRONT",
66 2, Block::Axis(Block::FACE_FRONT)
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(
69 "2/Z not axis of BACK",
70 2, Block::Axis(Block::FACE_BACK)
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)
79 CPPUNIT_ASSERT_EQUAL_MESSAGE(
80 "[ 0, -1, 0 ] not normal of DOWN",
81 glm::ivec3(0, -1, 0), Block::FaceNormal(Block::FACE_DOWN)
83 CPPUNIT_ASSERT_EQUAL_MESSAGE(
84 "[ 1, 0, 0 ] not normal of RIGHT",
85 glm::ivec3(1, 0, 0), Block::FaceNormal(Block::FACE_RIGHT)
87 CPPUNIT_ASSERT_EQUAL_MESSAGE(
88 "[ -1, 0, 0 ] not normal of LEFT",
89 glm::ivec3(-1, 0, 0), Block::FaceNormal(Block::FACE_LEFT)
91 CPPUNIT_ASSERT_EQUAL_MESSAGE(
92 "[ 0, 0, 1 ] not normal of FRONT",
93 glm::ivec3(0, 0, 1), Block::FaceNormal(Block::FACE_FRONT)
95 CPPUNIT_ASSERT_EQUAL_MESSAGE(
96 "[ 0, 0, -1 ] not normal of BACK",
97 glm::ivec3(0, 0, -1), Block::FaceNormal(Block::FACE_BACK)
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))
106 CPPUNIT_ASSERT_EQUAL_MESSAGE(
107 "DOWN not face of [ 0, -1, 0 ]",
108 Block::FACE_DOWN, Block::NormalFace(glm::vec3(0, -1, 0))
110 CPPUNIT_ASSERT_EQUAL_MESSAGE(
111 "RIGHT not face of [ 1, 0, 0 ]",
112 Block::FACE_RIGHT, Block::NormalFace(glm::vec3(1, 0, 0))
114 CPPUNIT_ASSERT_EQUAL_MESSAGE(
115 "LEFT not face of [ -1, 0, 0 ]",
116 Block::FACE_LEFT, Block::NormalFace(glm::vec3(-1, 0, 0))
118 CPPUNIT_ASSERT_EQUAL_MESSAGE(
119 "FRONT not face of [ 0, 0, 1 ]",
120 Block::FACE_FRONT, Block::NormalFace(glm::vec3(0, 0, 1))
122 CPPUNIT_ASSERT_EQUAL_MESSAGE(
123 "BACK not face of [ 0, 0, -1 ]",
124 Block::FACE_BACK, Block::NormalFace(glm::vec3(0, 0, -1))
129 void BlockTest::testFaceSet() {
131 CPPUNIT_ASSERT_MESSAGE(
132 "default faceset not empty",
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))
142 CPPUNIT_ASSERT_MESSAGE(
143 "not all set on filled faceset",
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))
153 CPPUNIT_ASSERT_MESSAGE(
154 "cleared faceset not empty",
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))
162 set.Set(Block::Face(i));
163 CPPUNIT_ASSERT_MESSAGE(
164 "face not set after setting",
165 set.IsSet(Block::Face(i))
168 CPPUNIT_ASSERT_MESSAGE(
169 "set not filled after setting all faces",
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))
177 set.Unset(Block::Face(i));
178 CPPUNIT_ASSERT_MESSAGE(
179 "face set after unsetting",
180 !set.IsSet(Block::Face(i))
183 CPPUNIT_ASSERT_MESSAGE(
184 "set not empty after unsetting all faces",
190 void BlockTest::testDefaultBlock() {
192 CPPUNIT_ASSERT_EQUAL_MESSAGE(
193 "0 type id of default block",
194 Block::Type(0), block.type
196 CPPUNIT_ASSERT_EQUAL_MESSAGE(
197 "identity transform of default block",
198 glm::mat4(1), block.Transform()
200 CPPUNIT_ASSERT_EQUAL_MESSAGE(
201 "no turn of default block",
202 Block::TURN_NONE, block.GetTurn()
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))