diff --git a/cpp/Platform.Setters.Tests/SetterExtensionsTests.cpp b/cpp/Platform.Setters.Tests/SetterExtensionsTests.cpp new file mode 100644 index 0000000..77cb581 --- /dev/null +++ b/cpp/Platform.Setters.Tests/SetterExtensionsTests.cpp @@ -0,0 +1,54 @@ +using TLinkAddress = std::int32_t; + +namespace Platform::Setters::Tests +{ + TEST(SetterExtensionsTests, SetFirstFromFirstListAndReturnTrue) + { + TLinkAddress list1[] { 1,2,3 }; + TLinkAddress list2[] { 4,5,6 }; + Setter setter {}; + bool decision { SetterExtensions::SetFirstFromFirstListAndReturnTrue(setter, list1, list2) }; + ASSERT_EQ(setter.GetTrue(), decision); + ASSERT_EQ(list1[0], setter.Result()); + } + + TEST(SetterExtensionsTests, SetSecondFromFirstListAndReturnTrue) + { + TLinkAddress list1[] { 1,2,3 }; + TLinkAddress list2[] { 4,5,6 }; + Setter setter {}; + bool decision { SetterExtensions::SetSecondFromFirstListAndReturnTrue(setter, list1, list2) }; + ASSERT_EQ(setter.GetTrue(), decision); + ASSERT_EQ(list1[1], setter.Result()); + } + + TEST(SetterExtensionsTests, SetFirstFromSecondListAndReturnTrue) + { + TLinkAddress list1[] { 1,2,3 }; + TLinkAddress list2[] { 4,5,6 }; + Setter setter {}; + bool decision { SetterExtensions::SetFirstFromSecondListAndReturnTrue(setter, list1, list2) }; + ASSERT_EQ(setter.GetTrue(), decision); + ASSERT_EQ(list2[0], setter.Result()); + } + + TEST(SetterExtensionsTests, SetSecondFromSecondListAndReturnTrue) + { + TLinkAddress list1[] { 1,2,3 }; + TLinkAddress list2[] { 4,5,6 }; + Setter setter {}; + bool decision { SetterExtensions::SetSecondFromSecondListAndReturnTrue(setter, list1, list2) }; + ASSERT_EQ(setter.GetTrue(), decision); + ASSERT_EQ(list2[1], setter.Result()); + } + + TEST(SetterExtensionsTests, SetThirdFromSecondListAndReturnTrue) + { + TLinkAddress list1[] { 1,2,3 }; + TLinkAddress list2[] { 4,5,6 }; + Setter setter {}; + bool decision { SetterExtensions::SetThirdFromSecondListAndReturnTrue(setter, list1, list2) }; + ASSERT_EQ(setter.GetTrue(), decision); + ASSERT_EQ(list2[2], setter.Result()); + } +} diff --git a/cpp/Platform.Setters.Tests/SetterTests.cpp b/cpp/Platform.Setters.Tests/SetterTests.cpp index d3079f0..85e41f0 100644 --- a/cpp/Platform.Setters.Tests/SetterTests.cpp +++ b/cpp/Platform.Setters.Tests/SetterTests.cpp @@ -1,5 +1,6 @@ #include #include +#include "SetterExtensionsTests.cpp" namespace Platform::Setters::Tests { diff --git a/cpp/Platform.Setters/Platform.Setters.h b/cpp/Platform.Setters/Platform.Setters.h index 4d52f5a..9a3b150 100644 --- a/cpp/Platform.Setters/Platform.Setters.h +++ b/cpp/Platform.Setters/Platform.Setters.h @@ -5,3 +5,4 @@ #include "SetterBase.h" #include "Setter[TResult].h" #include "Setter[TResult, TDecision].h" +#include "SetterExtensions.h" diff --git a/cpp/Platform.Setters/SetterBase.h b/cpp/Platform.Setters/SetterBase.h index bcf380b..af98428 100644 --- a/cpp/Platform.Setters/SetterBase.h +++ b/cpp/Platform.Setters/SetterBase.h @@ -15,6 +15,6 @@ public: void Set(TResult value) { _result = value; } - public: ~SetterBase() requires Interfaces::ISetter = default; + public: ~SetterBase() requires Interfaces::CSetter = default; }; } diff --git a/cpp/Platform.Setters/SetterExtensions.h b/cpp/Platform.Setters/SetterExtensions.h new file mode 100644 index 0000000..ad61701 --- /dev/null +++ b/cpp/Platform.Setters/SetterExtensions.h @@ -0,0 +1,48 @@ +namespace Platform::Setters +{ + class SetterExtensions + { + public: + template + static TDecision SetFirstFromFirstListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list1[0]); + return setter.GetTrue(); + } + + template + static TDecision SetSecondFromFirstListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list1[1]); + return setter.GetTrue(); + } + + template + static TDecision SetThirdFromFirstListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list1[2]); + return setter.GetTrue(); + } + + template + static TDecision SetFirstFromSecondListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list2[0]); + return setter.GetTrue(); + } + + template + static TDecision SetSecondFromSecondListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list2[1]); + return setter.GetTrue(); + } + + template + static TDecision SetThirdFromSecondListAndReturnTrue(Setter& setter, Interfaces::CArray auto&& list1, Interfaces::CArray auto&& list2) + { + setter.Set(list2[2]); + return setter.GetTrue(); + } + }; +} diff --git a/cpp/Platform.Setters/Setter[TResult, TDecision].h b/cpp/Platform.Setters/Setter[TResult, TDecision].h index 4334692..c844ead 100644 --- a/cpp/Platform.Setters/Setter[TResult, TDecision].h +++ b/cpp/Platform.Setters/Setter[TResult, TDecision].h @@ -4,20 +4,32 @@ template class Setter : public SetterBase { using base = SetterBase; - private: TDecision _trueValue {}; - private: TDecision _falseValue {}; + private: + TDecision _trueValue {}; + TDecision _falseValue {}; - public: Setter(TDecision trueValue, TDecision falseValue, TResult defaultValue) - : _trueValue(trueValue), _falseValue(falseValue), base(defaultValue) + public: Setter(TDecision _trueValue, TDecision _falseValue, TResult defaultValue) + : _trueValue(_trueValue), _falseValue(_falseValue), base(defaultValue) { } - public: Setter(TDecision trueValue, TDecision falseValue) : Setter(trueValue, falseValue, {}) { } + public: Setter(TDecision _trueValue, TDecision _falseValue) : Setter(_trueValue, _falseValue, {}) { } public: explicit Setter(TResult defaultValue) : base(defaultValue) { } public: Setter() = default; + public: + TDecision GetTrue() + { + return _trueValue; + } + + TDecision GetFalse() + { + return _falseValue; + } + public: TDecision SetAndReturnTrue(TResult value) { base::_result = value; @@ -30,13 +42,13 @@ return _falseValue; } - public: TDecision SetFirstAndReturnTrue(Interfaces::IArray auto&& list) + public: TDecision SetFirstAndReturnTrue(Interfaces::CArray auto&& list) { base::_result = list[0]; return _trueValue; } - public: TDecision SetFirstAndReturnFalse(Interfaces::IArray auto&& list) + public: TDecision SetFirstAndReturnFalse(Interfaces::CArray auto&& list) { base::_result = list[0]; return _falseValue; diff --git a/cpp/conanfile.txt b/cpp/conanfile.txt index b888b68..354dd3c 100644 --- a/cpp/conanfile.txt +++ b/cpp/conanfile.txt @@ -1,6 +1,6 @@ [requires] gtest/cci.20210126 -platform.interfaces/0.1.3 +platform.interfaces/0.2.5 [generators] -cmake \ No newline at end of file +cmake