diff --git a/src/tools/std20/concepts/test/CMakeLists.txt b/src/tools/std20/concepts/test/CMakeLists.txt index 7bcf7d0..65b93b7 100644 --- a/src/tools/std20/concepts/test/CMakeLists.txt +++ b/src/tools/std20/concepts/test/CMakeLists.txt @@ -1,2 +1,5 @@ +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 ) diff --git a/src/tools/std20/concepts/test/convertible_to.test.cpp b/src/tools/std20/concepts/test/convertible_to.test.cpp new file mode 100644 index 0000000..ea5bf8a --- /dev/null +++ b/src/tools/std20/concepts/test/convertible_to.test.cpp @@ -0,0 +1,30 @@ +// 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( "derived_from" ) { + + CHECK( std20::convertible_to< Foo, Foo > ); + CHECK( std20::convertible_to< Bar, Foo > ); + CHECK( std20::convertible_to< int, double > ); + CHECK( std20::convertible_to< double, int > ); + 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 +} // SCENARIO diff --git a/src/tools/std20/concepts/test/derived_from.test.cpp b/src/tools/std20/concepts/test/derived_from.test.cpp new file mode 100644 index 0000000..9559837 --- /dev/null +++ b/src/tools/std20/concepts/test/derived_from.test.cpp @@ -0,0 +1,30 @@ +// 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( "derived_from" ) { + + CHECK( std20::derived_from< Foo, Foo > ); + CHECK( std20::derived_from< Bar, Foo > ); + + CHECK( ! std20::derived_from< int, double > ); // different primitive types + 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 +} // SCENARIO diff --git a/src/tools/std20/concepts/test/same_as.test.cpp b/src/tools/std20/concepts/test/same_as.test.cpp new file mode 100644 index 0000000..3d715bd --- /dev/null +++ b/src/tools/std20/concepts/test/same_as.test.cpp @@ -0,0 +1,30 @@ +// 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 {}; + +SCENARIO( "same_as" ) { + + CHECK( std20::same_as< int, int > ); + CHECK( std20::same_as< double, double > ); + CHECK( std20::same_as< Foo, Foo > ); + + CHECK( std20::same_as< std::common_type_t< int, int, int >, int > ); + CHECK( std20::same_as< std::common_type_t< int, float, double >, double > ); + + CHECK( ! std20::same_as< double, int > ); + CHECK( ! std20::same_as< int, double > ); + CHECK( ! std20::same_as< Foo, Bar > ); +} // SCENARIO