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 gigaton string",
116 std::string("50.00Gt"), MassString(50000000000000.0)
120 void StringTest::testNumber() {
121 CPPUNIT_ASSERT_EQUAL_MESSAGE(
122 "bad format of number string",
123 std::string("0"), NumberString(0)
125 CPPUNIT_ASSERT_EQUAL_MESSAGE(
126 "bad format of negative number string",
127 std::string("-1500"), NumberString(-1500)
129 CPPUNIT_ASSERT_EQUAL_MESSAGE(
130 "bad format of large number string",
131 std::string("10000000"), NumberString(10000000)
135 void StringTest::testPercentage() {
136 CPPUNIT_ASSERT_EQUAL_MESSAGE(
137 "bad format of percentage string",
138 std::string("0.0%"), PercentageString(0.0)
140 CPPUNIT_ASSERT_EQUAL_MESSAGE(
141 "bad format of percentage string",
142 std::string("50.0%"), PercentageString(0.5)
144 CPPUNIT_ASSERT_EQUAL_MESSAGE(
145 "bad format of percentage string",
146 std::string("150.2%"), PercentageString(1.502)
148 CPPUNIT_ASSERT_EQUAL_MESSAGE(
149 "bad format of negative percentage string",
150 std::string("-10.0%"), PercentageString(-0.1)
154 void StringTest::testTime() {
155 CPPUNIT_ASSERT_EQUAL_MESSAGE(
156 "bad format of seconds string",
157 std::string("0s"), TimeString(0.0)
159 CPPUNIT_ASSERT_EQUAL_MESSAGE(
160 "bad format of seconds string",
161 std::string("10s"), TimeString(10.0)
163 CPPUNIT_ASSERT_EQUAL_MESSAGE(
164 "bad format of minutes string",
165 std::string("1m 00s"), TimeString(60.0)
167 CPPUNIT_ASSERT_EQUAL_MESSAGE(
168 "bad format of minutes string",
169 std::string("2m 05s"), TimeString(2.0 * 60.0 + 5.0)
171 CPPUNIT_ASSERT_EQUAL_MESSAGE(
172 "bad format of minutes string",
173 std::string("15m 20s"), TimeString(15.0 * 60.0 + 20.0)
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)
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)
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)
190 CPPUNIT_ASSERT_EQUAL_MESSAGE(
191 "bad format of vector string",
192 std::string("<0, 0>"), VectorString(glm::ivec2(0))
194 CPPUNIT_ASSERT_EQUAL_MESSAGE(
195 "bad format of vector string",
196 std::string("<-3, 4>"), VectorString(glm::ivec2(-3, 4))