Skip to content

Commit

Permalink
Merge branch 'master' into validator-vector
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelGunawan authored Oct 20, 2024
2 parents b839ee6 + 9b6b82c commit 7f34580
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)

Expand Down
8 changes: 8 additions & 0 deletions include/tcframe/validator/number.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace tcframe {

template<typename T>
bool isBetween(T N, T mn, T mx) {
return N >= mn && N <= mx;
}

}
21 changes: 21 additions & 0 deletions test/unit/tcframe/validator/NumberValidatorTests.cpp
Original file line number Diff line number Diff line change
@@ -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));
}

}

0 comments on commit 7f34580

Please sign in to comment.