diff --git a/CMakeLists.txt b/CMakeLists.txt index 4beef06..66040d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,7 @@ set(INCLUDE include/tcframe/util.hpp include/tcframe/util/StringUtils.hpp include/tcframe/util/optional.hpp + include/tcframe/validator/number.hpp include/tcframe/validator/vector.hpp ) @@ -259,6 +260,7 @@ set(TEST_UNIT test/unit/tcframe/util/OptionalTests.cpp test/unit/tcframe/util/StringUtilsTests.cpp test/unit/tcframe/util/TestUtils.hpp + test/unit/tcframe/validator/NumberValidatorTests.cpp test/unit/tcframe/validator/VectorValidatorTests.cpp ) diff --git a/include/tcframe/validator/number.hpp b/include/tcframe/validator/number.hpp new file mode 100644 index 0000000..f26f7fa --- /dev/null +++ b/include/tcframe/validator/number.hpp @@ -0,0 +1,8 @@ +namespace tcframe { + +template +bool isBetween(T N, T mn, T mx) { + return N >= mn && N <= mx; +} + +} diff --git a/test/unit/tcframe/validator/NumberValidatorTests.cpp b/test/unit/tcframe/validator/NumberValidatorTests.cpp new file mode 100644 index 0000000..9d9bc91 --- /dev/null +++ b/test/unit/tcframe/validator/NumberValidatorTests.cpp @@ -0,0 +1,21 @@ +#include "gmock/gmock.h" + +#include "tcframe/validator/number.hpp" + +using ::testing::Eq; +using ::testing::Test; + +namespace tcframe { + +class NumberValidatorTests : public Test {}; + +TEST_F(NumberValidatorTests, isBetween) { + EXPECT_FALSE(isBetween(5, 1, 4)); + EXPECT_FALSE(isBetween(5, 6, 10)); + EXPECT_FALSE(isBetween(5, 100, -100)); + EXPECT_TRUE(isBetween(5, 1, 5)); + EXPECT_TRUE(isBetween(5, 5, 10)); + EXPECT_TRUE(isBetween(5, 0, 10)); +} + +}