ADD: added UtilFcuntion class and a test function
This commit is contained in:
@@ -47,7 +47,8 @@ add_library(SimCore STATIC
|
|||||||
include/SimCore/IdentifierMaker.hpp
|
include/SimCore/IdentifierMaker.hpp
|
||||||
src/SimCore/IdentifierMaker.cpp
|
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)
|
target_link_libraries(test_IdentifierList Catch2::Catch2 SimCore loguru)
|
||||||
catch_discover_tests(test_IdentifierList)
|
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()
|
ENDIF()
|
||||||
|
|||||||
18
include/SimCore/UtilFunctions.hpp
Normal file
18
include/SimCore/UtilFunctions.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace SimCore {
|
||||||
|
|
||||||
|
|
||||||
|
class UtilFunctions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::vector<std::string> explode(std::string const & s, char delim);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
19
src/SimCore/UtilFunctions.cpp
Normal file
19
src/SimCore/UtilFunctions.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <SimCore/UtilFunctions.hpp>
|
||||||
|
|
||||||
|
namespace SimCore {
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> UtilFunctions::explode(std::string const & s, char delim)
|
||||||
|
{
|
||||||
|
std::vector<std::string> result;
|
||||||
|
std::istringstream iss(s);
|
||||||
|
|
||||||
|
for (std::string token; std::getline(iss, token, delim); )
|
||||||
|
{
|
||||||
|
result.push_back(std::move(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
tests/test_UtilFunctions.cpp
Normal file
38
tests/test_UtilFunctions.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include <SimCore/UtilFunctions.hpp>
|
||||||
|
#include <string>
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user