]> git.localhorst.tv Git - blobs.git/blob - tst/world/PlanetTest.cpp
1ab0bf4373ab4d7c5708042acca8fae1756ed29e
[blobs.git] / tst / world / PlanetTest.cpp
1 #include "PlanetTest.hpp"
2
3 #include "../assert.hpp"
4
5 #include "world/Planet.hpp"
6
7 #include <limits>
8
9 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::world::test::PlanetTest);
10
11 using blobs::test::AssertEqual;
12
13
14 namespace blobs {
15 namespace world {
16 namespace test {
17
18 void PlanetTest::setUp() {
19 }
20
21 void PlanetTest::tearDown() {
22 }
23
24
25 void PlanetTest::testPositionConversion() {
26         Planet p(5);
27
28         CPPUNIT_ASSERT_EQUAL_MESSAGE(
29                 "wrong sidelength of planet",
30                 5, p.SideLength());
31         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
32                 "wrong radius of planet",
33                 2.5, p.Radius(), std::numeric_limits<double>::epsilon());
34
35         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
36                 "wrong scalar conversion",
37                 -2.5, p.TileToPosition(0), std::numeric_limits<double>::epsilon());
38         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
39                 "wrong scalar conversion",
40                 -0.5, p.TileToPosition(2), std::numeric_limits<double>::epsilon());
41         CPPUNIT_ASSERT_EQUAL_MESSAGE(
42                 "wrong scalar conversion",
43                 2, p.PositionToTile(0.1));
44         CPPUNIT_ASSERT_EQUAL_MESSAGE(
45                 "wrong scalar conversion",
46                 2, p.PositionToTile(-0.1));
47         CPPUNIT_ASSERT_EQUAL_MESSAGE(
48                 "wrong scalar conversion",
49                 1, p.PositionToTile(-0.6));
50         CPPUNIT_ASSERT_EQUAL_MESSAGE(
51                 "wrong scalar conversion",
52                 4, p.PositionToTile(2.0));
53
54         AssertEqual(
55                 "wrong surface position",
56                 glm::ivec2(2, 2), p.SurfacePosition(0, glm::dvec3(0.0, 0.0, 2.5))
57         );
58         AssertEqual(
59                 "wrong surface position",
60                 glm::ivec2(2, 2), p.SurfacePosition(0, glm::dvec3(0.1, 0.1, 2.5))
61         );
62         AssertEqual(
63                 "wrong surface position",
64                 glm::ivec2(2, 2), p.SurfacePosition(0, glm::dvec3(-0.1, -0.1, 2.5))
65         );
66         AssertEqual(
67                 "wrong surface position",
68                 glm::ivec2(3, 1), p.SurfacePosition(0, glm::dvec3(1.0, -1.0, 2.5))
69         );
70
71         AssertEqual(
72                 "wrong tile center",
73                 glm::dvec3(0.0, 0.0, 2.5), p.TileCenter(0, 2, 2)
74         );
75 }
76
77 }
78 }
79 }