| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #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
|