Skip to content

Commit

Permalink
adding unit tests ;-) fix #14885
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed May 21, 2024
1 parent 8014334 commit 2f34f2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/complex/unit_tests/testcommon/output.complex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Running main() from ./googletest/src/gtest_main.cc
[==========] Running 44 tests from 5 test suites.
[==========] Running 46 tests from 5 test suites.
[----------] Global test environment set-up.
[----------] 10 tests from StringTokenizer
[ RUN ] StringTokenizer.test_split_with_whitechar
Expand Down Expand Up @@ -35,7 +35,7 @@ Running main() from ./googletest/src/gtest_main.cc
[ OK ] FileHelpers.test_method_fixRelative (0 ms)
[----------] 4 tests from FileHelpers (0 ms total)

[----------] 13 tests from StringUtils
[----------] 15 tests from StringUtils
[ RUN ] StringUtils.test_method_prune
[ OK ] StringUtils.test_method_prune (0 ms)
[ RUN ] StringUtils.test_method_to_lower_case
Expand All @@ -62,7 +62,11 @@ Running main() from ./googletest/src/gtest_main.cc
[ OK ] StringUtils.test_toDouble (0 ms)
[ RUN ] StringUtils.test_toBool
[ OK ] StringUtils.test_toBool (0 ms)
[----------] 13 tests from StringUtils (0 ms total)
[ RUN ] StringUtils.test_parseDist
[ OK ] StringUtils.test_parseDist (0 ms)
[ RUN ] StringUtils.test_parseSpeed
[ OK ] StringUtils.test_parseSpeed (0 ms)
[----------] 15 tests from StringUtils (0 ms total)

[----------] 7 tests from RGBColor
[ RUN ] RGBColor.test_parseColor_with_wrong_string
Expand Down Expand Up @@ -105,5 +109,5 @@ Running main() from ./googletest/src/gtest_main.cc
[----------] 10 tests from ValueTimeLine (0 ms total)

[----------] Global test environment tear-down
[==========] 44 tests from 5 test suites ran. (0 ms total)
[ PASSED ] 44 tests.
[==========] 46 tests from 5 test suites ran. (0 ms total)
[ PASSED ] 46 tests.
23 changes: 23 additions & 0 deletions unittest/src/utils/common/StringUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,26 @@ TEST(StringUtils, test_toBool) {
EXPECT_THROW(StringUtils::toBool("Trari"), BoolFormatException);
EXPECT_THROW(StringUtils::toBool("yessir"), BoolFormatException);
}

TEST(StringUtils, test_parseDist) {
EXPECT_EQ(0., StringUtils::parseDist("0"));
EXPECT_EQ(1., StringUtils::parseDist("1"));
EXPECT_EQ(1., StringUtils::parseDist("1m"));
EXPECT_EQ(1., StringUtils::parseDist("1 m"));
EXPECT_EQ(1000., StringUtils::parseDist("1 km"));
EXPECT_THROW(StringUtils::parseDist(""), EmptyData);
EXPECT_THROW(StringUtils::parseDist("1xm"), NumberFormatException);
}

TEST(StringUtils, test_parseSpeed) {
EXPECT_EQ(0., StringUtils::parseSpeed("0"));
EXPECT_EQ(1., StringUtils::parseSpeed("3.6"));
EXPECT_EQ(1., StringUtils::parseSpeed("1m/s"));
EXPECT_EQ(1., StringUtils::parseSpeed("1 m/s"));
EXPECT_EQ(1., StringUtils::parseSpeed("3.6 km/h"));
EXPECT_EQ(1., StringUtils::parseSpeed("3.6 kmh"));
EXPECT_EQ(1., StringUtils::parseSpeed("3.6 kmph"));
EXPECT_DOUBLE_EQ(1.609344 / 3.6, StringUtils::parseSpeed("1 mph"));
EXPECT_THROW(StringUtils::parseSpeed(""), EmptyData);
EXPECT_THROW(StringUtils::parseSpeed("1xm"), NumberFormatException);
}

0 comments on commit 2f34f2e

Please sign in to comment.