From 9c95106af2fbaa9f5f8f605ee7df54cc90356df6 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 31 Dec 2019 16:54:49 +0100 Subject: new_type: implement addition via nt::Arithmetic --- test/include/arithmetic_suite.hpp | 11 ++++++++ test/src/arithmetic_suite.cpp | 53 +++++++++++++++++++++++++++++++++++++++ test/src/driver.cpp | 2 ++ 3 files changed, 66 insertions(+) create mode 100644 test/include/arithmetic_suite.hpp create mode 100644 test/src/arithmetic_suite.cpp (limited to 'test') diff --git a/test/include/arithmetic_suite.hpp b/test/include/arithmetic_suite.hpp new file mode 100644 index 0000000..1eb4af8 --- /dev/null +++ b/test/include/arithmetic_suite.hpp @@ -0,0 +1,11 @@ +#ifndef NEWTYPE_TEST_ARITHMETIC_SUITE_HPP +#define NEWTYPE_TEST_ARITHMETIC_SUITE_HPP + +#include + +#include +#include + +auto arithmetic_suite() -> std::pair; + +#endif \ No newline at end of file diff --git a/test/src/arithmetic_suite.cpp b/test/src/arithmetic_suite.cpp new file mode 100644 index 0000000..4541125 --- /dev/null +++ b/test/src/arithmetic_suite.cpp @@ -0,0 +1,53 @@ +#include "conversion_suite.hpp" +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/new_type.hpp" + +#include + +#include + +inline namespace addition_tests +{ + + auto a_new__type_not_deriving_arithmetic_is_not_addable_with_instances_of_itself() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::is_addable_v)); + } + + auto a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::is_addable_v); + } + + auto addition_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 addition_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 addition_tests + +auto arithmetic_suite() -> std::pair +{ + return {{ + /// Addition Tests + KAWAII(a_new__type_not_deriving_arithmetic_is_not_addable_with_instances_of_itself), + 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), + }, + "Arithmetic Operators Tests"}; +} \ No newline at end of file diff --git a/test/src/driver.cpp b/test/src/driver.cpp index c650dda..c93f157 100644 --- a/test/src/driver.cpp +++ b/test/src/driver.cpp @@ -1,3 +1,4 @@ +#include "arithmetic_suite.hpp" #include "conversion_suite.hpp" #include "derivation_clause_suite.hpp" #include "equality_comparison_suite.hpp" @@ -57,6 +58,7 @@ int main(int argc, char ** argv) equality_comparison_suite(), relational_operators_suite(), io_operators_suite(), + arithmetic_suite(), }; auto selectors = get_test_selectors(suites); -- cgit v1.2.3