diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1da4cdc8..fcc701b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,6 +48,12 @@ set_target_properties( AUTOUIC ON AUTORCC ON) +# --- condition-logic --- # + +target_sources( + ${PROJECT_NAME} PRIVATE test-condition-logic.cpp + ${ADVSS_SOURCE_DIR}/lib/utils/condition-logic.cpp) + # --- json --- # target_sources( diff --git a/tests/test-condition-logic.cpp b/tests/test-condition-logic.cpp new file mode 100644 index 00000000..0f1c4f96 --- /dev/null +++ b/tests/test-condition-logic.cpp @@ -0,0 +1,173 @@ +#include "catch.hpp" + +#include + +TEST_CASE("Get and set", "[conditon-logic]") +{ + auto logic = advss::Logic(advss::Logic::Type::ROOT_NONE); + REQUIRE(logic.GetType() == advss::Logic::Type::ROOT_NONE); + + logic.SetType(advss::Logic::Type::ROOT_NOT); + REQUIRE(logic.GetType() == advss::Logic::Type::ROOT_NOT); + + logic.SetType(advss::Logic::Type::AND_NOT); + REQUIRE(logic.GetType() == advss::Logic::Type::AND_NOT); +} + +TEST_CASE("Root test", "[conditon-logic]") +{ + auto logic = advss::Logic(advss::Logic::Type::ROOT_NONE); + REQUIRE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::ROOT_NOT); + REQUIRE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::ROOT_LAST); + REQUIRE(logic.IsRootType()); + + logic.SetType(advss::Logic::Type::NONE); + REQUIRE_FALSE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::AND); + REQUIRE_FALSE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::OR); + REQUIRE_FALSE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::AND_NOT); + REQUIRE_FALSE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::OR_NOT); + REQUIRE_FALSE(logic.IsRootType()); + logic.SetType(advss::Logic::Type::LAST); + REQUIRE_FALSE(logic.IsRootType()); +} + +TEST_CASE("Negation test", "[conditon-logic]") +{ + REQUIRE_FALSE( + advss::Logic::IsNegationType(advss::Logic::Type::ROOT_NONE)); + REQUIRE(advss::Logic::IsNegationType(advss::Logic::Type::ROOT_NOT)); + REQUIRE_FALSE( + advss::Logic::IsNegationType(advss::Logic::Type::ROOT_LAST)); + REQUIRE_FALSE(advss::Logic::IsNegationType(advss::Logic::Type::NONE)); + REQUIRE_FALSE(advss::Logic::IsNegationType(advss::Logic::Type::AND)); + REQUIRE_FALSE(advss::Logic::IsNegationType(advss::Logic::Type::OR)); + REQUIRE(advss::Logic::IsNegationType(advss::Logic::Type::AND_NOT)); + REQUIRE(advss::Logic::IsNegationType(advss::Logic::Type::OR_NOT)); + REQUIRE_FALSE(advss::Logic::IsNegationType(advss::Logic::Type::LAST)); +} + +TEST_CASE("Validation", "[conditon-logic]") +{ + auto logic = advss::Logic(static_cast(-1)); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); + + logic = advss::Logic(static_cast( + static_cast(advss::Logic::Type::LAST) + 1)); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); + + logic.SetType(advss::Logic::Type::ROOT_NONE); + REQUIRE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::ROOT_NOT); + REQUIRE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); + + logic.SetType(advss::Logic::Type::NONE); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::AND); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::OR); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::AND_NOT); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::OR_NOT); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE(logic.IsValidSelection(false)); + + logic.SetType(advss::Logic::Type::ROOT_LAST); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); + logic.SetType(advss::Logic::Type::LAST); + REQUIRE_FALSE(logic.IsValidSelection(true)); + REQUIRE_FALSE(logic.IsValidSelection(false)); +} + +TEST_CASE("Logic", "[conditon-logic]") +{ + // These logic types should have no effect on the initial provided value + + auto logic = + advss::Logic(static_cast(-1)).GetType(); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::NONE; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::LAST; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + // These logic types should have an effect on the initial provided value + + logic = advss::Logic::Type::ROOT_NONE; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::ROOT_NOT; + REQUIRE(advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE_FALSE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::AND; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::OR; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::AND_NOT; + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE_FALSE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); + + logic = advss::Logic::Type::OR_NOT; + REQUIRE(advss::Logic::ApplyConditionLogic(logic, false, false, "")); + REQUIRE_FALSE( + advss::Logic::ApplyConditionLogic(logic, false, true, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, false, "")); + REQUIRE(advss::Logic::ApplyConditionLogic(logic, true, true, "")); +}