Tests for Ord method
This commit is contained in:
35
Test/Ord.cpp
35
Test/Ord.cpp
@@ -1,6 +1,7 @@
|
||||
#include <GeneralUtility.h>
|
||||
#include "Catch2.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Tests that the Ord method works with characters in a string
|
||||
TEST_CASE(__FILE__"/WorksWithCharsInString", "[Ord]")
|
||||
@@ -24,3 +25,37 @@ TEST_CASE(__FILE__"/WorksWithCharsInString", "[Ord]")
|
||||
REQUIRE(GeneralUtility::Ord('e', set) == 14);
|
||||
REQUIRE(GeneralUtility::Ord('f', set) == 15);
|
||||
}
|
||||
|
||||
// Tests that, if an object is not found, -1 is returned
|
||||
TEST_CASE(__FILE__"/ReturnsNeg1IfNotFound", "[Ord]")
|
||||
{
|
||||
const std::string set = "0123456789abcdef";
|
||||
|
||||
REQUIRE(GeneralUtility::Ord('z', set) == -1);
|
||||
}
|
||||
|
||||
// Tests that Ord works with vectors <string>
|
||||
TEST_CASE(__FILE__"/WorksWithVector_String", "[Ord]")
|
||||
{
|
||||
const std::vector<std::string> vec = { "Apple", "Banana", "Tomato", "Olives" };
|
||||
|
||||
REQUIRE(GeneralUtility::Ord(std::string("Apple"), vec) == 0);
|
||||
REQUIRE(GeneralUtility::Ord(std::string("Banana"), vec) == 1);
|
||||
REQUIRE(GeneralUtility::Ord(std::string("Tomato"), vec) == 2);
|
||||
REQUIRE(GeneralUtility::Ord(std::string("Olives"), vec) == 3);
|
||||
|
||||
INFO("Now testing that unknown is -1");
|
||||
REQUIRE(GeneralUtility::Ord(std::string("Pepper"), vec) == -1);
|
||||
}
|
||||
|
||||
// Tests that Ord works with vectors <int>
|
||||
TEST_CASE(__FILE__"/WorksWithVector_Int", "[Ord]")
|
||||
{
|
||||
const std::vector<int> vec = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
for (std::size_t i = 0 ; i < 10; i++)
|
||||
REQUIRE(GeneralUtility::Ord((int)i, vec) == i);
|
||||
|
||||
INFO("Now testing that unknown is -1");
|
||||
REQUIRE(GeneralUtility::Ord((int)99, vec) == -1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user