diff --git a/src/tools/std20/concepts/test/CMakeLists.txt b/src/tools/std20/concepts/test/CMakeLists.txt index 65b93b7..326271c 100644 --- a/src/tools/std20/concepts/test/CMakeLists.txt +++ b/src/tools/std20/concepts/test/CMakeLists.txt @@ -1,5 +1,8 @@ -add_cpp_test( std20.concepts.convertible_to convertible_to.test.cpp ) -add_cpp_test( std20.concepts.derived_from derived_from.test.cpp ) -add_cpp_test( std20.concepts.equality_comparable equality_comparable.test.cpp ) -add_cpp_test( std20.concepts.same_as same_as.test.cpp ) -add_cpp_test( std20.concepts.totally_ordered totally_ordered.test.cpp ) +add_cpp_test( std20.concepts.same_as same_as.test.cpp ) +add_cpp_test( std20.concepts.derived_from derived_from.test.cpp ) +add_cpp_test( std20.concepts.convertible_to convertible_to.test.cpp ) +add_cpp_test( std20.concepts.common_reference_with common_reference_with.test.cpp ) +add_cpp_test( std20.concepts.common_with common_with.test.cpp ) + +add_cpp_test( std20.concepts.equality_comparable equality_comparable.test.cpp ) +add_cpp_test( std20.concepts.totally_ordered totally_ordered.test.cpp ) diff --git a/src/tools/std20/concepts/test/common_reference_with.test.cpp b/src/tools/std20/concepts/test/common_reference_with.test.cpp new file mode 100644 index 0000000..71b9b5f --- /dev/null +++ b/src/tools/std20/concepts/test/common_reference_with.test.cpp @@ -0,0 +1,56 @@ +// include Catch2 +#include + +// what we are testing +#include "tools/std20/concepts.hpp" + +// other includes + +// convenience typedefs +//using namespace njoy::tools; +namespace std20 = nano::ranges; + +// test code +struct Foo {}; + +struct Bar : public Foo {}; + +struct AlsoBar : private Foo {}; + +SCENARIO( "common_reference_with" ) { + + CHECK( std20::common_reference_with< Foo, Foo > ); + CHECK( std20::common_reference_with< Bar, Foo > ); + CHECK( std20::common_reference_with< Foo, Bar > ); + CHECK( std20::common_reference_with< Bar, Bar > ); + CHECK( std20::common_reference_with< int, double > ); + CHECK( std20::common_reference_with< double, int > ); + CHECK( std20::common_reference_with< void, void > ); + + CHECK( std20::common_reference_with< int&, int& > ); + CHECK( std20::common_reference_with< const int&, int& > ); + CHECK( std20::common_reference_with< int&, const int& > ); + CHECK( std20::common_reference_with< int&&, int& > ); + CHECK( std20::common_reference_with< int&&, const int& > ); + CHECK( std20::common_reference_with< int&, int&& > ); + CHECK( std20::common_reference_with< const int&, int&& > ); + CHECK( std20::common_reference_with< int&&, int&& > ); + CHECK( std20::common_reference_with< const int&&, int&& > ); + CHECK( std20::common_reference_with< int&&, const int&& > ); + + CHECK( std20::common_reference_with< volatile int&, int& > ); + CHECK( std20::common_reference_with< volatile int&, const int& > ); + CHECK( std20::common_reference_with< const volatile int&, int& > ); + CHECK( std20::common_reference_with< int&, volatile int& > ); + CHECK( std20::common_reference_with< const int&, volatile int& > ); + CHECK( std20::common_reference_with< int&, const volatile int& > ); + + CHECK( std20::common_reference_with< Foo&, Bar& > ); + CHECK( std20::common_reference_with< Foo&&, Bar&& > ); + CHECK( std20::common_reference_with< Foo&, Bar&& > ); + CHECK( std20::common_reference_with< Foo&&, Bar& > ); + CHECK( std20::common_reference_with< Foo&&, Bar&& > ); + + CHECK( ! std20::common_reference_with< AlsoBar, Foo > ); // private inheritance from Foo + CHECK( ! std20::common_reference_with< Foo, AlsoBar > ); // private inheritance from Foo +} // SCENARIO diff --git a/src/tools/std20/concepts/test/common_with.test.cpp b/src/tools/std20/concepts/test/common_with.test.cpp new file mode 100644 index 0000000..cea7f99 --- /dev/null +++ b/src/tools/std20/concepts/test/common_with.test.cpp @@ -0,0 +1,56 @@ +// include Catch2 +#include + +// what we are testing +#include "tools/std20/concepts.hpp" + +// other includes + +// convenience typedefs +//using namespace njoy::tools; +namespace std20 = nano::ranges; + +// test code +struct Foo {}; + +struct Bar : public Foo {}; + +struct AlsoBar : private Foo {}; + +SCENARIO( "common_with" ) { + + CHECK( std20::common_with< Foo, Foo > ); + CHECK( std20::common_with< Bar, Foo > ); + CHECK( std20::common_with< Foo, Bar > ); + CHECK( std20::common_with< Bar, Bar > ); + CHECK( std20::common_with< int, double > ); + CHECK( std20::common_with< double, int > ); + CHECK( std20::common_with< void, void > ); + + CHECK( std20::common_with< int&, int& > ); + CHECK( std20::common_with< const int&, int& > ); + CHECK( std20::common_with< int&, const int& > ); + CHECK( std20::common_with< int&&, int& > ); + CHECK( std20::common_with< int&&, const int& > ); + CHECK( std20::common_with< int&, int&& > ); + CHECK( std20::common_with< const int&, int&& > ); + CHECK( std20::common_with< int&&, int&& > ); + CHECK( std20::common_with< const int&&, int&& > ); + CHECK( std20::common_with< int&&, const int&& > ); + + CHECK( std20::common_with< volatile int&, int& > ); + CHECK( std20::common_with< volatile int&, const int& > ); + CHECK( std20::common_with< const volatile int&, int& > ); + CHECK( std20::common_with< int&, volatile int& > ); + CHECK( std20::common_with< const int&, volatile int& > ); + CHECK( std20::common_with< int&, const volatile int& > ); + + CHECK( std20::common_with< Foo&, Bar& > ); + CHECK( std20::common_with< Foo&&, Bar&& > ); + CHECK( std20::common_with< Foo&, Bar&& > ); + CHECK( std20::common_with< Foo&&, Bar& > ); + CHECK( std20::common_with< Foo&&, Bar&& > ); + + CHECK( ! std20::common_with< AlsoBar, Foo > ); // private inheritance from Foo + CHECK( ! std20::common_with< Foo, AlsoBar > ); // private inheritance from Foo +} // SCENARIO diff --git a/src/tools/std20/concepts/test/convertible_to.test.cpp b/src/tools/std20/concepts/test/convertible_to.test.cpp index ea5bf8a..5813458 100644 --- a/src/tools/std20/concepts/test/convertible_to.test.cpp +++ b/src/tools/std20/concepts/test/convertible_to.test.cpp @@ -17,7 +17,7 @@ struct Bar : public Foo {}; struct AlsoBar : private Foo {}; -SCENARIO( "derived_from" ) { +SCENARIO( "convertible_to" ) { CHECK( std20::convertible_to< Foo, Foo > ); CHECK( std20::convertible_to< Bar, Foo > ); @@ -26,5 +26,5 @@ SCENARIO( "derived_from" ) { CHECK( std20::convertible_to< void, void > ); CHECK( ! std20::convertible_to< Foo, Bar > ); // Foo is not derived from Bar - CHECK( ! std20::convertible_to< AlsoBar, Foo > ); // private inheritance from Bar + CHECK( ! std20::convertible_to< AlsoBar, Foo > ); // private inheritance from Foo } // SCENARIO diff --git a/src/tools/std20/concepts/test/derived_from.test.cpp b/src/tools/std20/concepts/test/derived_from.test.cpp index 9559837..9103c11 100644 --- a/src/tools/std20/concepts/test/derived_from.test.cpp +++ b/src/tools/std20/concepts/test/derived_from.test.cpp @@ -26,5 +26,5 @@ SCENARIO( "derived_from" ) { CHECK( ! std20::derived_from< int, int > ); // same primitive types CHECK( ! std20::derived_from< double, double > ); // same primitive types CHECK( ! std20::derived_from< Foo, Bar > ); // Foo is not derived from Bar - CHECK( ! std20::derived_from< AlsoBar, Foo > ); // private inheritance from Bar + CHECK( ! std20::derived_from< AlsoBar, Foo > ); // private inheritance from Foo } // SCENARIO