Changeset View
Changeset View
Standalone View
Standalone View
source/ps/tests/test_CStr.h
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | void test_parse() | ||||
CStr8 str1("1.234"); | CStr8 str1("1.234"); | ||||
TS_ASSERT_DELTA(str1.ToFloat(), 1.234f, 0.0001f); | TS_ASSERT_DELTA(str1.ToFloat(), 1.234f, 0.0001f); | ||||
TS_ASSERT_DELTA(str1.ToDouble(), 1.234, 0.0001); | TS_ASSERT_DELTA(str1.ToDouble(), 1.234, 0.0001); | ||||
TS_ASSERT_EQUALS(str1.ToInt(), 1); | TS_ASSERT_EQUALS(str1.ToInt(), 1); | ||||
TS_ASSERT_EQUALS(str1.ToUInt(), 1u); | TS_ASSERT_EQUALS(str1.ToUInt(), 1u); | ||||
TS_ASSERT_EQUALS(str1.ToLong(), 1); | TS_ASSERT_EQUALS(str1.ToLong(), 1); | ||||
TS_ASSERT_EQUALS(str1.ToULong(), 1u); | TS_ASSERT_EQUALS(str1.ToULong(), 1u); | ||||
CStr8 str2("bogus"); | CStr8 str2("+1,234"); | ||||
TS_ASSERT_EQUALS(str2.ToFloat(), 0.0f); | TS_ASSERT_DELTA(str2.ToFloat(), 1.f, 0.0001f); | ||||
TS_ASSERT_EQUALS(str2.ToDouble(), 0.0); | TS_ASSERT_DELTA(str2.ToDouble(), 1., 0.0001); | ||||
TS_ASSERT_EQUALS(str2.ToInt(), 0); | TS_ASSERT_EQUALS(str2.ToInt(), 1); | ||||
TS_ASSERT_EQUALS(str2.ToUInt(), 0u); | TS_ASSERT_EQUALS(str2.ToUInt(), 1u); | ||||
TS_ASSERT_EQUALS(str2.ToLong(), 0); | TS_ASSERT_EQUALS(str2.ToLong(), 1); | ||||
TS_ASSERT_EQUALS(str2.ToULong(), 0u); | TS_ASSERT_EQUALS(str2.ToULong(), 1u); | ||||
CStr8 str3("3bogus"); | CStr8 str3("bogus"); | ||||
TS_ASSERT_EQUALS(str3.ToFloat(), 3.0f); | TS_ASSERT_EQUALS(str3.ToFloat(), 0.0f); | ||||
TS_ASSERT_EQUALS(str3.ToDouble(), 3.0); | TS_ASSERT_EQUALS(str3.ToDouble(), 0.0); | ||||
TS_ASSERT_EQUALS(str3.ToInt(), 3); | TS_ASSERT_EQUALS(str3.ToInt(), 0); | ||||
TS_ASSERT_EQUALS(str3.ToUInt(), 3u); | TS_ASSERT_EQUALS(str3.ToUInt(), 0u); | ||||
TS_ASSERT_EQUALS(str3.ToLong(), 3); | TS_ASSERT_EQUALS(str3.ToLong(), 0); | ||||
TS_ASSERT_EQUALS(str3.ToULong(), 3u); | TS_ASSERT_EQUALS(str3.ToULong(), 0u); | ||||
CStr8 str4("3bogus"); | |||||
TS_ASSERT_DELTA(str4.ToFloat(), 3.0f, 0.0001f); | |||||
TS_ASSERT_DELTA(str4.ToDouble(), 3.0, 0.0001); | |||||
TS_ASSERT_EQUALS(str4.ToInt(), 3); | |||||
TS_ASSERT_EQUALS(str4.ToUInt(), 3u); | |||||
TS_ASSERT_EQUALS(str4.ToLong(), 3); | |||||
TS_ASSERT_EQUALS(str4.ToULong(), 3u); | |||||
CStr8 str5("-3bogus"); | |||||
TS_ASSERT_DELTA(str5.ToFloat(), -3.0f, 0.0001f); | |||||
TS_ASSERT_DELTA(str5.ToDouble(), -3.0, 0.0001); | |||||
TS_ASSERT_EQUALS(str5.ToInt(), -3); | |||||
TS_ASSERT_EQUALS(str5.ToLong(), -3); | |||||
setlocale(LC_NUMERIC, old); | setlocale(LC_NUMERIC, old); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator