1 #include "StringTest.hpp"
3 #include "math/const.hpp"
4 #include "ui/string.hpp"
6 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::ui::test::StringTest);
13 void StringTest::setUp() {
16 void StringTest::tearDown() {
20 void StringTest::testAngle() {
21 CPPUNIT_ASSERT_EQUAL_MESSAGE(
22 "bad format of 0° angle",
23 std::string("0.00°"), AngleString(0.0)
25 CPPUNIT_ASSERT_EQUAL_MESSAGE(
26 "bad format of 30° angle",
27 std::string("30.00°"), AngleString(PI * (1.0 / 6.0))
29 CPPUNIT_ASSERT_EQUAL_MESSAGE(
30 "bad format of 45° angle",
31 std::string("45.00°"), AngleString(PI * 0.25)
33 CPPUNIT_ASSERT_EQUAL_MESSAGE(
34 "bad format of 60° angle",
35 std::string("60.00°"), AngleString(PI * (1.0 / 3.0))
37 CPPUNIT_ASSERT_EQUAL_MESSAGE(
38 "bad format of 90° angle",
39 std::string("90.00°"), AngleString(PI * 0.5)
41 CPPUNIT_ASSERT_EQUAL_MESSAGE(
42 "bad format of 180° angle",
43 std::string("180.00°"), AngleString(PI)
45 CPPUNIT_ASSERT_EQUAL_MESSAGE(
46 "bad format of -90° angle",
47 std::string("-90.00°"), AngleString(PI * -0.5)
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)
56 CPPUNIT_ASSERT_EQUAL_MESSAGE(
57 "bad format of single place decimal string",
58 std::string("1.2"), DecimalString(1.2, 1)
60 CPPUNIT_ASSERT_EQUAL_MESSAGE(
61 "bad format of negative decimal string",
62 std::string("-1.20"), DecimalString(-1.2, 2)
64 CPPUNIT_ASSERT_EQUAL_MESSAGE(
65 "bad format of long decimal string",
66 std::string("3141.593"), DecimalString(PI * 1000, 3)
70 void StringTest::testLength() {
71 CPPUNIT_ASSERT_EQUAL_MESSAGE(
72 "bad format of meter string",
73 std::string("1.500m"), LengthString(1.5)
75 CPPUNIT_ASSERT_EQUAL_MESSAGE(
76 "bad format of centimeter string",
77 std::string("23.00cm"), LengthString(0.23)
79 CPPUNIT_ASSERT_EQUAL_MESSAGE(
80 "bad format of millimeter string",
81 std::string("0.7000mm"), LengthString(0.0007)
83 CPPUNIT_ASSERT_EQUAL_MESSAGE(
84 "bad format of kilometer string",
85 std::string("2.560km"), LengthString(2560.0)
87 CPPUNIT_ASSERT_EQUAL_MESSAGE(
88 "bad format of megameter string",
89 std::string("6.371Mm"), LengthString(6371000.0)
91 CPPUNIT_ASSERT_EQUAL_MESSAGE(
92 "bad format of gigameter string",
93 std::string("147.2Gm"), LengthString(147200000000.0)
97 void StringTest::testMass() {
98 CPPUNIT_ASSERT_EQUAL_MESSAGE(
99 "bad format of kilogram string",
100 std::string("80.00kg"), MassString(80.0)
102 CPPUNIT_ASSERT_EQUAL_MESSAGE(
103 "bad format of gram string",
104 std::string("250.0g"), MassString(0.250)
106 CPPUNIT_ASSERT_EQUAL_MESSAGE(
107 "bad format of milligram string",
108 std::string("30.00mg"), MassString(0.000030)
110 CPPUNIT_ASSERT_EQUAL_MESSAGE(
111 "bad format of ton string",
112 std::string("18.00t"), MassString(18000.0)
114 CPPUNIT_ASSERT_EQUAL_MESSAGE(
115 "bad format of kiloton string",
116 std::string("50.00kt"), MassString(50000000.0)
118 CPPUNIT_ASSERT_EQUAL_MESSAGE(
119 "bad format of megaton string",
120 std::string("1400Mt"), MassString(1400000000000.0)
122 CPPUNIT_ASSERT_EQUAL_MESSAGE(
123 "bad format of gigaton string",
124 std::string("50.00Gt"), MassString(50000000000000.0)
128 void StringTest::testNumber() {
129 CPPUNIT_ASSERT_EQUAL_MESSAGE(
130 "bad format of number string",
131 std::string("0"), NumberString(0)
133 CPPUNIT_ASSERT_EQUAL_MESSAGE(
134 "bad format of negative number string",
135 std::string("-1500"), NumberString(-1500)
137 CPPUNIT_ASSERT_EQUAL_MESSAGE(
138 "bad format of large number string",
139 std::string("10000000"), NumberString(10000000)
143 void StringTest::testPercentage() {
144 CPPUNIT_ASSERT_EQUAL_MESSAGE(
145 "bad format of percentage string",
146 std::string("0.0%"), PercentageString(0.0)
148 CPPUNIT_ASSERT_EQUAL_MESSAGE(
149 "bad format of percentage string",
150 std::string("50.0%"), PercentageString(0.5)
152 CPPUNIT_ASSERT_EQUAL_MESSAGE(
153 "bad format of percentage string",
154 std::string("150.2%"), PercentageString(1.502)
156 CPPUNIT_ASSERT_EQUAL_MESSAGE(
157 "bad format of negative percentage string",
158 std::string("-10.0%"), PercentageString(-0.1)
162 void StringTest::testTime() {
163 CPPUNIT_ASSERT_EQUAL_MESSAGE(
164 "bad format of seconds string",
165 std::string("0s"), TimeString(0.0)
167 CPPUNIT_ASSERT_EQUAL_MESSAGE(
168 "bad format of seconds string",
169 std::string("10s"), TimeString(10.0)
171 CPPUNIT_ASSERT_EQUAL_MESSAGE(
172 "bad format of minutes string",
173 std::string("1m 00s"), TimeString(60.0)
175 CPPUNIT_ASSERT_EQUAL_MESSAGE(
176 "bad format of minutes string",
177 std::string("2m 05s"), TimeString(2.0 * 60.0 + 5.0)
179 CPPUNIT_ASSERT_EQUAL_MESSAGE(
180 "bad format of minutes string",
181 std::string("15m 20s"), TimeString(15.0 * 60.0 + 20.0)
183 CPPUNIT_ASSERT_EQUAL_MESSAGE(
184 "bad format of minutes string",
185 std::string("10h 05m 49s"), TimeString(10.0 * 60.0 * 60.0 + 5.0 * 60.0 + 49.0)
189 void StringTest::testVector() {
190 CPPUNIT_ASSERT_EQUAL_MESSAGE(
191 "bad format of vector string",
192 std::string("<0.00, 0.00, 0.00>"), VectorString(glm::dvec3(0.0), 2)
194 CPPUNIT_ASSERT_EQUAL_MESSAGE(
195 "bad format of vector string",
196 std::string("<1.0, -2.5, 1.0>"), VectorString(glm::dvec3(1.0, -2.5, 0.96), 1)
198 CPPUNIT_ASSERT_EQUAL_MESSAGE(
199 "bad format of vector string",
200 std::string("<0, 0>"), VectorString(glm::ivec2(0))
202 CPPUNIT_ASSERT_EQUAL_MESSAGE(
203 "bad format of vector string",
204 std::string("<-3, 4>"), VectorString(glm::ivec2(-3, 4))