From de5d0cbb9c58852ff0038be5495fa7e5d656dd1d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Jan 2020 11:43:54 +0100 Subject: new_type: implement subtraction --- test/src/arithmetic_suite.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test') diff --git a/test/src/arithmetic_suite.cpp b/test/src/arithmetic_suite.cpp index 4541125..57c06e8 100644 --- a/test/src/arithmetic_suite.cpp +++ b/test/src/arithmetic_suite.cpp @@ -40,6 +40,37 @@ inline namespace addition_tests } // namespace addition_tests +inline namespace subtraction_tests +{ + + auto a_new__type_not_deriving_arithmetic_is_not_subtractable_with_instances_of_itself() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::is_subtractable_v)); + } + + auto a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::is_subtractable_v); + } + + auto subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void + { + using type_alias = nt::new_type; + ASSERT((std::is_same_v() + std::declval())>)); + } + + auto subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() -> void + { + using type_alias = nt::new_type; + auto lhs = type_alias{24}; + auto rhs = type_alias{18}; + ASSERT_EQUAL(24 - 18, (lhs - rhs).decay()); + } + +} // namespace subtraction_tests + auto arithmetic_suite() -> std::pair { return {{ @@ -48,6 +79,12 @@ auto arithmetic_suite() -> std::pair KAWAII(a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself), KAWAII(addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), KAWAII(addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), + + /// Subtraction Tests + KAWAII(a_new__type_not_deriving_arithmetic_is_not_subtractable_with_instances_of_itself), + KAWAII(a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself), + KAWAII(subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), + KAWAII(subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), }, "Arithmetic Operators Tests"}; } \ No newline at end of file -- cgit v1.2.3