141 lines
3.2 KiB
C++
141 lines
3.2 KiB
C++
#include "Test.h"
|
|
#include "StringAlgorithm.h"
|
|
#include <Logging.h>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <vector>
|
|
|
|
|
|
namespace Utilities {
|
|
namespace Test {
|
|
|
|
bool TestSplitInstance(const std::string& subject, const char& delimiter, unsigned expectedSize)
|
|
{
|
|
std::stringstream ss;
|
|
std::vector<std::string> vector = StringAlgorithm::split(subject, delimiter);
|
|
ss << "Vector Size - " << vector.size() << std::endl;
|
|
|
|
for (auto& item : vector)
|
|
ss << item << std::endl;
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
if (vector.size() != expectedSize)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
bool TestSplitInstance(const std::string& subject, const std::string& delimiters, unsigned expectedSize)
|
|
{
|
|
std::stringstream ss;
|
|
std::vector<std::string> vector = StringAlgorithm::split(subject, delimiters);
|
|
ss << "Vector Size - " << vector.size() << std::endl;
|
|
|
|
for (auto& item : vector)
|
|
ss << item << std::endl;
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
if (vector.size() != expectedSize)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
bool TestSplit()
|
|
{
|
|
bool success = true;
|
|
std::string testString = "a/b/c/d";
|
|
success = success && TestSplitInstance(testString, '/', 4);
|
|
|
|
testString = "a/ /c/ e";
|
|
success = success && TestSplitInstance(testString, '/', 4);
|
|
|
|
testString = "a//c/";
|
|
success = success && TestSplitInstance(testString, '/', 4);
|
|
|
|
testString = "a/.b/";
|
|
success = success && TestSplitInstance(testString, "/.", 4);
|
|
|
|
return success;
|
|
}
|
|
|
|
bool TestIsNumeric()
|
|
{
|
|
std::stringstream ss;
|
|
|
|
ss << "\"Test\" != Numeric";
|
|
if (StringAlgorithm::is_numeric("Test"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
ss << std::endl << "\"1\" == Numeric";
|
|
if (!StringAlgorithm::is_numeric("1"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
ss << std::endl << "\"1.43\" == Numeric";
|
|
if (!StringAlgorithm::is_numeric("1.43"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
ss << std::endl << "\"0\" == Numeric";
|
|
if (!StringAlgorithm::is_numeric("0"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
ss << std::endl << "\"034dfj\" != Numeric";
|
|
if (StringAlgorithm::is_numeric("034dfj"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
ss << std::endl << "\"dfj354\" != Numeric";
|
|
if (StringAlgorithm::is_numeric("dfj354"))
|
|
{
|
|
ss << " -> FAIL";
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return false;
|
|
}
|
|
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
return true;
|
|
}
|
|
|
|
bool TestStringAlgorithm()
|
|
{
|
|
std::stringstream ss;
|
|
ss << "----------------------------------" << std::endl;
|
|
ss << "| TestStringAlgorithm |" << std::endl;
|
|
ss << "----------------------------------" << std::endl;
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
bool success = TestSplit();
|
|
|
|
ss.str("");
|
|
ss << "----------------------------------" << std::endl;
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
success = TestIsNumeric() && success;
|
|
|
|
ss.str("");
|
|
ss << "==================================" << std::endl << std::endl;
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
return success;
|
|
}
|
|
|
|
} // namespace Test
|
|
} // namespace Utilities
|