Skip to content

Commit

Permalink
More tests for concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Feb 26, 2024
1 parent 43382a3 commit 7f345a0
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tools/std20/concepts/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
30 changes: 30 additions & 0 deletions src/tools/std20/concepts/test/convertible_to.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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( "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
30 changes: 30 additions & 0 deletions src/tools/std20/concepts/test/derived_from.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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( "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
30 changes: 30 additions & 0 deletions src/tools/std20/concepts/test/same_as.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 {};

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

0 comments on commit 7f345a0

Please sign in to comment.