Skip to content

Commit

Permalink
Adding more test
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Feb 26, 2024
1 parent 7f345a0 commit a0e3eb8
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/tools/std20/concepts/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
56 changes: 56 additions & 0 deletions src/tools/std20/concepts/test/common_reference_with.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// 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
56 changes: 56 additions & 0 deletions src/tools/std20/concepts/test/common_with.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// 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
4 changes: 2 additions & 2 deletions src/tools/std20/concepts/test/convertible_to.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 > );
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/tools/std20/concepts/test/derived_from.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a0e3eb8

Please sign in to comment.