From 7551a1def04b9302fef73ad5f1205bbfbaddde0d Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Wed, 11 Jan 2023 18:15:44 +0100 Subject: [PATCH] ADD: added UtilFcuntion class and a test function --- CMakeLists.txt | 7 +++++- include/SimCore/UtilFunctions.hpp | 18 +++++++++++++++ src/SimCore/UtilFunctions.cpp | 19 ++++++++++++++++ tests/test_UtilFunctions.cpp | 38 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 include/SimCore/UtilFunctions.hpp create mode 100644 src/SimCore/UtilFunctions.cpp create mode 100644 tests/test_UtilFunctions.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dacf89c..fed0d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,8 @@ add_library(SimCore STATIC include/SimCore/IdentifierMaker.hpp src/SimCore/IdentifierMaker.cpp - + include/SimCore/UtilFunctions.hpp + src/SimCore/UtilFunctions.cpp ) @@ -114,4 +115,8 @@ IF (${TEST_SIMCORE_LIBRARY}) target_link_libraries(test_IdentifierList Catch2::Catch2 SimCore loguru) catch_discover_tests(test_IdentifierList) + add_executable(test_UtilFunctions tests/test_UtilFunctions.cpp) + target_link_libraries(test_UtilFunctions Catch2::Catch2 SimCore loguru) + catch_discover_tests(test_UtilFunctions) + ENDIF() diff --git a/include/SimCore/UtilFunctions.hpp b/include/SimCore/UtilFunctions.hpp new file mode 100644 index 0000000..4eba591 --- /dev/null +++ b/include/SimCore/UtilFunctions.hpp @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include + + + +namespace SimCore { + + + class UtilFunctions + { + public: + static std::vector explode(std::string const & s, char delim); + + }; + +} \ No newline at end of file diff --git a/src/SimCore/UtilFunctions.cpp b/src/SimCore/UtilFunctions.cpp new file mode 100644 index 0000000..19ecffe --- /dev/null +++ b/src/SimCore/UtilFunctions.cpp @@ -0,0 +1,19 @@ +#include + +namespace SimCore { + + + std::vector UtilFunctions::explode(std::string const & s, char delim) + { + std::vector result; + std::istringstream iss(s); + + for (std::string token; std::getline(iss, token, delim); ) + { + result.push_back(std::move(token)); + } + + return result; + } + +} \ No newline at end of file diff --git a/tests/test_UtilFunctions.cpp b/tests/test_UtilFunctions.cpp new file mode 100644 index 0000000..5ca253c --- /dev/null +++ b/tests/test_UtilFunctions.cpp @@ -0,0 +1,38 @@ +#include +#include +#define CATCH_CONFIG_MAIN +#include + + + + +SCENARIO("Testing the SimCorePositionClass") +{ + GIVEN("different position in different forms") + { + + std::string s1 = "hello.world.guy"; + std::string s2 = "my;Name;is;henry"; + + + WHEN("constructing Position Object with data") + { + auto v1 = SimCore::UtilFunctions::explode(s1, '.'); + auto v2 = SimCore::UtilFunctions::explode(s2, ';'); + auto v3 = SimCore::UtilFunctions::explode(s2, '.'); + + + THEN("positions attributes are correct") + { + REQUIRE(v1.size() == 3); + REQUIRE(v1.begin()->compare("hello") == 0); + + REQUIRE(v2.size() == 4); + REQUIRE(v2[1].compare("Name") == 0); + + + + } //THEN + } // WHEN + } // GIVEN +} //SCENARIO \ No newline at end of file