]> git.localhorst.tv Git - blobs.git/blob - tst/ui/StringTest.cpp
5e781ca4acdc23cab16af5f5115bc8cfa7ae021b
[blobs.git] / tst / ui / StringTest.cpp
1 #include "StringTest.hpp"
2
3 #include "math/const.hpp"
4 #include "ui/string.hpp"
5
6 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::ui::test::StringTest);
7
8
9 namespace blobs {
10 namespace ui {
11 namespace test {
12
13 void StringTest::setUp() {
14 }
15
16 void StringTest::tearDown() {
17 }
18
19
20 void StringTest::testAngle() {
21         CPPUNIT_ASSERT_EQUAL_MESSAGE(
22                 "bad format of 0° angle",
23                 std::string("0.00°"), AngleString(0.0)
24         );
25         CPPUNIT_ASSERT_EQUAL_MESSAGE(
26                 "bad format of 30° angle",
27                 std::string("30.00°"), AngleString(PI * (1.0 / 6.0))
28         );
29         CPPUNIT_ASSERT_EQUAL_MESSAGE(
30                 "bad format of 45° angle",
31                 std::string("45.00°"), AngleString(PI * 0.25)
32         );
33         CPPUNIT_ASSERT_EQUAL_MESSAGE(
34                 "bad format of 60° angle",
35                 std::string("60.00°"), AngleString(PI * (1.0 / 3.0))
36         );
37         CPPUNIT_ASSERT_EQUAL_MESSAGE(
38                 "bad format of 90° angle",
39                 std::string("90.00°"), AngleString(PI * 0.5)
40         );
41         CPPUNIT_ASSERT_EQUAL_MESSAGE(
42                 "bad format of 180° angle",
43                 std::string("180.00°"), AngleString(PI)
44         );
45         CPPUNIT_ASSERT_EQUAL_MESSAGE(
46                 "bad format of -90° angle",
47                 std::string("-90.00°"), AngleString(PI * -0.5)
48         );
49 }
50
51 void StringTest::testDecimal() {
52         CPPUNIT_ASSERT_EQUAL_MESSAGE(
53                 "bad format of zero places decimal string",
54                 std::string("0"), DecimalString(0.0, 0)
55         );
56         CPPUNIT_ASSERT_EQUAL_MESSAGE(
57                 "bad format of single place decimal string",
58                 std::string("1.2"), DecimalString(1.2, 1)
59         );
60         CPPUNIT_ASSERT_EQUAL_MESSAGE(
61                 "bad format of negative decimal string",
62                 std::string("-1.20"), DecimalString(-1.2, 2)
63         );
64         CPPUNIT_ASSERT_EQUAL_MESSAGE(
65                 "bad format of long decimal string",
66                 std::string("3141.593"), DecimalString(PI * 1000, 3)
67         );
68 }
69
70 void StringTest::testLength() {
71         CPPUNIT_ASSERT_EQUAL_MESSAGE(
72                 "bad format of meter string",
73                 std::string("1.500m"), LengthString(1.5)
74         );
75         CPPUNIT_ASSERT_EQUAL_MESSAGE(
76                 "bad format of centimeter string",
77                 std::string("23.00cm"), LengthString(0.23)
78         );
79         CPPUNIT_ASSERT_EQUAL_MESSAGE(
80                 "bad format of millimeter string",
81                 std::string("0.7000mm"), LengthString(0.0007)
82         );
83         CPPUNIT_ASSERT_EQUAL_MESSAGE(
84                 "bad format of kilometer string",
85                 std::string("2.560km"), LengthString(2560.0)
86         );
87         CPPUNIT_ASSERT_EQUAL_MESSAGE(
88                 "bad format of megameter string",
89                 std::string("6.371Mm"), LengthString(6371000.0)
90         );
91         CPPUNIT_ASSERT_EQUAL_MESSAGE(
92                 "bad format of gigameter string",
93                 std::string("147.2Gm"), LengthString(147200000000.0)
94         );
95 }
96
97 void StringTest::testMass() {
98         CPPUNIT_ASSERT_EQUAL_MESSAGE(
99                 "bad format of kilogram string",
100                 std::string("80.00kg"), MassString(80.0)
101         );
102         CPPUNIT_ASSERT_EQUAL_MESSAGE(
103                 "bad format of gram string",
104                 std::string("250.0g"), MassString(0.250)
105         );
106         CPPUNIT_ASSERT_EQUAL_MESSAGE(
107                 "bad format of milligram string",
108                 std::string("30.00mg"), MassString(0.000030)
109         );
110         CPPUNIT_ASSERT_EQUAL_MESSAGE(
111                 "bad format of ton string",
112                 std::string("18.00t"), MassString(18000.0)
113         );
114         CPPUNIT_ASSERT_EQUAL_MESSAGE(
115                 "bad format of gigaton string",
116                 std::string("50.00Gt"), MassString(50000000000000.0)
117         );
118 }
119
120 void StringTest::testNumber() {
121         CPPUNIT_ASSERT_EQUAL_MESSAGE(
122                 "bad format of number string",
123                 std::string("0"), NumberString(0)
124         );
125         CPPUNIT_ASSERT_EQUAL_MESSAGE(
126                 "bad format of negative number string",
127                 std::string("-1500"), NumberString(-1500)
128         );
129         CPPUNIT_ASSERT_EQUAL_MESSAGE(
130                 "bad format of large number string",
131                 std::string("10000000"), NumberString(10000000)
132         );
133 }
134
135 void StringTest::testPercentage() {
136         CPPUNIT_ASSERT_EQUAL_MESSAGE(
137                 "bad format of percentage string",
138                 std::string("0.0%"), PercentageString(0.0)
139         );
140         CPPUNIT_ASSERT_EQUAL_MESSAGE(
141                 "bad format of percentage string",
142                 std::string("50.0%"), PercentageString(0.5)
143         );
144         CPPUNIT_ASSERT_EQUAL_MESSAGE(
145                 "bad format of percentage string",
146                 std::string("150.2%"), PercentageString(1.502)
147         );
148         CPPUNIT_ASSERT_EQUAL_MESSAGE(
149                 "bad format of negative percentage string",
150                 std::string("-10.0%"), PercentageString(-0.1)
151         );
152 }
153
154 void StringTest::testTime() {
155         CPPUNIT_ASSERT_EQUAL_MESSAGE(
156                 "bad format of seconds string",
157                 std::string("0s"), TimeString(0.0)
158         );
159         CPPUNIT_ASSERT_EQUAL_MESSAGE(
160                 "bad format of seconds string",
161                 std::string("10s"), TimeString(10.0)
162         );
163         CPPUNIT_ASSERT_EQUAL_MESSAGE(
164                 "bad format of minutes string",
165                 std::string("1m 00s"), TimeString(60.0)
166         );
167         CPPUNIT_ASSERT_EQUAL_MESSAGE(
168                 "bad format of minutes string",
169                 std::string("2m 05s"), TimeString(2.0 * 60.0 + 5.0)
170         );
171         CPPUNIT_ASSERT_EQUAL_MESSAGE(
172                 "bad format of minutes string",
173                 std::string("15m 20s"), TimeString(15.0 * 60.0 + 20.0)
174         );
175         CPPUNIT_ASSERT_EQUAL_MESSAGE(
176                 "bad format of minutes string",
177                 std::string("10h 05m 49s"), TimeString(10.0 * 60.0 * 60.0 + 5.0 * 60.0 + 49.0)
178         );
179 }
180
181 void StringTest::testVector() {
182         CPPUNIT_ASSERT_EQUAL_MESSAGE(
183                 "bad format of vector string",
184                 std::string("<0.00, 0.00, 0.00>"), VectorString(glm::dvec3(0.0), 2)
185         );
186         CPPUNIT_ASSERT_EQUAL_MESSAGE(
187                 "bad format of vector string",
188                 std::string("<1.0, -2.5, 1.0>"), VectorString(glm::dvec3(1.0, -2.5, 0.96), 1)
189         );
190         CPPUNIT_ASSERT_EQUAL_MESSAGE(
191                 "bad format of vector string",
192                 std::string("<0, 0>"), VectorString(glm::ivec2(0))
193         );
194         CPPUNIT_ASSERT_EQUAL_MESSAGE(
195                 "bad format of vector string",
196                 std::string("<-3, 4>"), VectorString(glm::ivec2(-3, 4))
197         );
198 }
199
200 }
201 }
202 }