From cdab2b8d87db346a8f965b1e446ce52f50b3c294 Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Sat, 2 Nov 2024 22:15:13 +0700 Subject: [PATCH] kagi --- include/tcframe/validator/core.hpp | 23 +++++++++++++++++++ .../tcframe/validator/CoreValidatorTests.cpp | 12 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/tcframe/validator/core.hpp b/include/tcframe/validator/core.hpp index 5a89b05..3050cfb 100644 --- a/include/tcframe/validator/core.hpp +++ b/include/tcframe/validator/core.hpp @@ -134,4 +134,27 @@ inline StringElementValidator eachCharacterOf(const string& val) { return StringElementValidator(val); } +template> +struct MatrixElementValidator { +private: + const vector>& val; + +public: + explicit MatrixElementValidator(const vector>& _val) : val(_val) {} + + bool isBetween(T minVal, T maxVal) { + for (const vector& v : val) { + if (!eachElementOf(v).isBetween(minVal, maxVal)) { + return false; + } + } + return true; + } +}; + +template> +inline MatrixElementValidator eachElementOf(const vector>& val) { + return MatrixElementValidator(val); +} + } diff --git a/test/unit/tcframe/validator/CoreValidatorTests.cpp b/test/unit/tcframe/validator/CoreValidatorTests.cpp index c3cf87f..19920fd 100644 --- a/test/unit/tcframe/validator/CoreValidatorTests.cpp +++ b/test/unit/tcframe/validator/CoreValidatorTests.cpp @@ -24,6 +24,18 @@ TEST_F(CoreValidatorTests, eachElementOf_isBetween) { EXPECT_FALSE(eachElementOf(vector{2, 3, 1, 5, 4}).isBetween(2, 4)); EXPECT_TRUE(eachElementOf(vector{2, 3, 1, 5, 4}).isBetween(1, 5)); EXPECT_TRUE(eachElementOf(vector{2, 3, 1, 5, 4}).isBetween(0, 6)); + + EXPECT_TRUE(eachElementOf(vector{}).isBetween(0, 6)); + + EXPECT_FALSE(eachElementOf(vector>{ + vector{1, 2}, + vector{3, 4}}).isBetween(2, 4)); + EXPECT_FALSE(eachElementOf(vector>{ + vector{1, 2}, + vector{3, 4}}).isBetween(1, 5)); + EXPECT_TRUE(eachElementOf(vector>{ + vector{1, 2}, + vector{3, 4}}).isBetween(1, 4)); } TEST_F(CoreValidatorTests, elementsOf_areAscending) {