From 2fd8b9c88c00c6385c8113afa94ebd447e0a7e8b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 07:43:07 +0200 Subject: tests: port derivation_clause tests --- source/tests/CMakeLists.txt | 2 +- source/tests/src/derivation_clause.cpp | 179 +++++++++++++++ source/tests/src/derivation_clause_suite.cpp | 312 --------------------------- 3 files changed, 180 insertions(+), 313 deletions(-) create mode 100644 source/tests/src/derivation_clause.cpp delete mode 100644 source/tests/src/derivation_clause_suite.cpp diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 7840739..f2c39e0 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -9,7 +9,7 @@ include("Catch") add_executable("${PROJECT_NAME}_tests" "src/arithmetic.cpp" "src/conversion.cpp" - # "src/derivation_clause_suite.cpp" + "src/derivation_clause.cpp" # "src/equality_comparison_suite.cpp" # "src/hash_suite.cpp" # "src/io_operators_suite.cpp" diff --git a/source/tests/src/derivation_clause.cpp b/source/tests/src/derivation_clause.cpp new file mode 100644 index 0000000..dd1edb9 --- /dev/null +++ b/source/tests/src/derivation_clause.cpp @@ -0,0 +1,179 @@ +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" + +#include + +#include + +SCENARIO("Derivation Clause", "[infrastructure]") +{ + GIVEN("An empty derivation clause") + { + auto clause = nt::deriving(); + + THEN("it doesn't contain any derivable") + { + REQUIRE_FALSE(clause(nt::Show)); + } + } + + GIVEN("A derivation clause containing only nt::Show") + { + auto clause = deriving(nt::Show); + + THEN("it doesn't contain nt::EqBase") + { + REQUIRE_FALSE(clause(nt::EqBase)); + } + + THEN("it contains nt::Show") + { + REQUIRE(clause(nt::Show)); + } + + THEN("it copares less-than one containing nt::Show and nt::EqBase") + { + REQUIRE(clause < deriving(nt::Show, nt::EqBase)); + } + + THEN("it does not compare less-than one conataining only nt::EqBase") + { + REQUIRE_FALSE(clause < deriving(nt::EqBase)); + } + + THEN("it does not compare greater-than one conataining only nt::EqBase") + { + REQUIRE_FALSE(clause > deriving(nt::EqBase)); + } + + THEN("it does not compare equal-to one containiing only nt::Arithmetic") + { + REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); + } + + THEN("it compares not-equal-to one containing only nt::Arithmetic") + { + REQUIRE(clause != deriving(nt::Arithmetic)); + } + + THEN("it compares less-than-equal to one containing both nt::Show and nt::EqBase") + { + REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); + } + } + + GIVEN("A derivation clause containing only nt::Show and nt::EqBase") + { + auto clause = deriving(nt::Show, nt::EqBase); + + THEN("it contains nt::EqBase") + { + REQUIRE(clause(nt::EqBase)); + } + + THEN("it contains nt::Show") + { + REQUIRE(clause(nt::Show)); + } + + THEN("it contains both nt::Show and nt::EqBase") + { + REQUIRE(clause(nt::Show, nt::EqBase)); + } + + THEN("it does not contain nt::Arithmetic") + { + REQUIRE_FALSE(clause(nt::Arithmetic)); + } + + THEN("it does not contain both nt::Arithmetic and nt::Show") + { + REQUIRE_FALSE(clause(nt::Arithmetic, nt::Show)); + } + + THEN("it does not compare less-than one containing nt::Show and nt::EqBase") + { + REQUIRE_FALSE(clause < deriving(nt::Show, nt::EqBase)); + } + + THEN("it does not compare less-than one containing nt::EqBase and nt::Show") + { + REQUIRE_FALSE(clause < deriving(nt::EqBase, nt::Show)); + } + + THEN("it compares greater-than one containing only nt::Show") + { + REQUIRE(clause > deriving(nt::Show)); + } + + THEN("it does not compare greater-than one containing both nt::Show and nt::EqBase") + { + REQUIRE_FALSE(clause > deriving(nt::Show, nt::EqBase)); + } + + THEN("it does not compare greater-than one containing both nt::EqBase and nt::Show") + { + REQUIRE_FALSE(clause > deriving(nt::EqBase, nt::Show)); + } + + THEN("it compares equal-to one containing both nt::Show and nt::EqBase") + { + REQUIRE(clause == deriving(nt::Show, nt::EqBase)); + } + + THEN("it compares equal-to one containing both nt::EqBase and nt::Show") + { + REQUIRE(clause == deriving(nt::EqBase, nt::Show)); + } + + THEN("it does not compare equal-to one containiing only nt::Arithmetic") + { + REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); + } + + THEN("it does not compare equal-to one containiing all nt::Show, nt::EqBase, and nt::Arithmetic") + { + REQUIRE_FALSE(clause == deriving(nt::Show, nt::EqBase, nt::Arithmetic)); + } + + THEN("it does not compare not-equal-to one containing both nt::Show and nt::EqBase") + { + REQUIRE_FALSE(clause != deriving(nt::Show, nt::EqBase)); + } + + THEN("it does not compare not-equal-to one containing both nt::Show and nt::EqBase") + { + REQUIRE_FALSE(clause != deriving(nt::EqBase, nt::Show)); + } + + THEN("it compares not-equal-to one containing only nt::Arithmetic") + { + REQUIRE(clause != deriving(nt::Arithmetic)); + } + + THEN("it compares less-than-equal to one containing both nt::Show and nt::EqBase") + { + REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); + } + + THEN("a derivation clause containing only nt::Arithmetic does not compare less-than-equal to it") + { + REQUIRE_FALSE(deriving(nt::Arithmetic) <= clause); + } + + THEN("it compares greather-than-equal to one containing only nt::Show") + { + REQUIRE(clause >= deriving(nt::Show)); + } + + THEN("it compares greather-than-equal to one containing both nt::Show and nt::EqBase") + { + REQUIRE(clause >= deriving(nt::Show, nt::EqBase)); + } + + THEN("it does not compare greather-than-eqaul to one containing only nt::Arithmetic") + { + REQUIRE_FALSE(clause >= deriving(nt::Arithmetic)); + } + } +} diff --git a/source/tests/src/derivation_clause_suite.cpp b/source/tests/src/derivation_clause_suite.cpp deleted file mode 100644 index 86a34ab..0000000 --- a/source/tests/src/derivation_clause_suite.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include "derivation_clause_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" - -#include - -#include - -inline namespace subset_tests -{ - - auto an_empty_derivation_clause_does_not_contain_any_derivable() -> void - { - auto derivation_clause = nt::deriving(); - ASSERT(!derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_does_not_contain_eqbase() -> void - { - auto derivation_clause = deriving(nt::Show); - ASSERT(!derivation_clause(nt::EqBase)); - } - - auto a_derivation_clause_containing_only_show_does_contain_show() -> void - { - auto derivation_clause = deriving(nt::Show); - ASSERT(derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_show() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(derivation_clause(nt::Show, nt::EqBase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(!derivation_clause(nt::Arithmetic)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(!derivation_clause(nt::Show, nt::Arithmetic)); - } - -} // namespace subset_tests - -inline namespace less_than_tests -{ - - auto a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(only_show < show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase < also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase < eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase() -> void - { - auto show = deriving(nt::Show); - auto eqbase = deriving(nt::EqBase); - - ASSERT(!(show < eqbase)); - } - -} // namespace less_than_tests - -inline namespace greater_than_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto show = deriving(nt::Show); - - ASSERT(show_and_eqbase > show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase > also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase > eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase() -> void - { - auto show = deriving(nt::Show); - auto eqbase = deriving(nt::EqBase); - - ASSERT(!(show > eqbase)); - } - -} // namespace greater_than_tests - -inline namespace eqbaseuals_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT_EQUAL(show_and_eqbase, also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT_EQUAL(show_and_eqbase, eqbase_and_show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(!(show_and_eqbase == arithmetic)); - } - - auto a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto show = deriving(nt::Show); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(!(show == arithmetic)); - } - -} // namespace eqbaseuals_tests - -inline namespace not_eqbaseuals_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase != also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase != eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(eqbase_and_show != arithmetic); - } - - auto a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto eqbase = deriving(nt::EqBase); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(eqbase != arithmetic); - } - -} // namespace not_eqbaseuals_tests - -inline namespace less_than_or_eqbaseual_tests -{ - - auto a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(only_show <= show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase <= also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase() -> void - { - auto arithmetic = deriving(nt::Arithmetic); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(arithmetic <= show_and_eqbase)); - } - -} // namespace less_than_or_eqbaseual_tests - -inline namespace greater_than_or_eqbaseual_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase >= only_show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase >= also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic() -> void - { - auto arithmetic = deriving(nt::Arithmetic); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase >= arithmetic)); - } - -} // namespace greater_than_or_eqbaseual_tests - -auto derivation_clause_suite() -> std::pair -{ - return { - { - /// Subset tests - KAWAII(an_empty_derivation_clause_does_not_contain_any_derivable), - KAWAII(a_derivation_clause_containing_only_show_does_not_contain_eqbase), - KAWAII(a_derivation_clause_containing_only_show_does_contain_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic), - - /// Less-than tests - KAWAII(a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase), - - /// Greater-than tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase), - - /// Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), - KAWAII(a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic), - - /// Not-Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic), - KAWAII(a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), - - /// Less-than or Equals tests - KAWAII(a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase), - - /// Greater-than or Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic), - }, - "Derivation Clause Tests"}; -} \ No newline at end of file -- cgit v1.2.3