Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Feb 26, 2024
1 parent 2d4415b commit 831c2cc
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/tools/std20/concepts/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ add_cpp_test( std20.concepts.integral integral.test.cpp )
add_cpp_test( std20.concepts.signed_integral signed_integral.test.cpp )
add_cpp_test( std20.concepts.unsigned_integral unsigned_integral.test.cpp )
add_cpp_test( std20.concepts.floating_point floating_point.test.cpp )

#add_cpp_test( std20.concepts.assignable_from assignable_from.test.cpp )
#add_cpp_test( std20.concepts.swappable swappable.test.cpp )
add_cpp_test( std20.concepts.destructible destructible.test.cpp )
add_cpp_test( std20.concepts.constructible_from constructible_from.test.cpp )
add_cpp_test( std20.concepts.default_initializable default_initializable.test.cpp )
#add_cpp_test( std20.concepts.move_constructible move_constructible.test.cpp )
#add_cpp_test( std20.concepts.copy_constructible copy_constructible.test.cpp )
add_cpp_test( std20.concepts.equality_comparable equality_comparable.test.cpp )
add_cpp_test( std20.concepts.totally_ordered totally_ordered.test.cpp )
#add_cpp_test( std20.concepts.movable movable.test.cpp )
#add_cpp_test( std20.concepts.copyable copyable.test.cpp )
#add_cpp_test( std20.concepts.semiregular semiregular.test.cpp )
#add_cpp_test( std20.concepts.regular regular.test.cpp )
#add_cpp_test( std20.concepts.invocable invocable.test.cpp )
#add_cpp_test( std20.concepts.regular_invocable regular_invocable.test.cpp )
#add_cpp_test( std20.concepts.predicate predicate.test.cpp )
#add_cpp_test( std20.concepts.relation relation.test.cpp )
#add_cpp_test( std20.concepts.equivalence_relation equivalence_relation.test.cpp )
#add_cpp_test( std20.concepts.strict_weak_order strict_weak_order.test.cpp )
93 changes: 93 additions & 0 deletions src/tools/std20/concepts/test/constructible_from.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/std20/concepts.hpp"

// other includes
#include <string>

// convenience typedefs
//using namespace njoy::tools;
namespace std20 = nano::ranges;

// test code
struct Foo {

~Foo() noexcept {};
};

struct NonDefaultConstructableFoo {

NonDefaultConstructableFoo() = delete;
~NonDefaultConstructableFoo() noexcept {};
};

struct Bar {

Bar() = default;
explicit Bar( int );
~Bar() = default;
};

SCENARIO( "constructible_from" ) {

CHECK( std20::constructible_from< Foo > );
CHECK( std20::constructible_from< Bar > );
CHECK( std20::constructible_from< std::string > );
CHECK( std20::constructible_from< Bar, int > );

CHECK( ! std20::constructible_from< NonDefaultConstructableFoo > );

CHECK( std20::constructible_from< int > );
CHECK( std20::constructible_from< const int > );
CHECK( ! std20::constructible_from< const int& > );
CHECK( ! std20::constructible_from< int() > );
CHECK( ! std20::constructible_from< int (&)() > );
CHECK( ! std20::constructible_from< int[] > );
CHECK( std20::constructible_from< int[2] > );
CHECK( std20::constructible_from< int const (&)[2], int (&)[2] > );
CHECK( ! std20::constructible_from< int, int (&)[2] >);

CHECK( std20::constructible_from< int, int > );
CHECK( std20::constructible_from< int, int& > );
CHECK( std20::constructible_from< int, int&& > );
CHECK( std20::constructible_from< int, const int > );
CHECK( std20::constructible_from< int, const int& > );
CHECK( std20::constructible_from< int, const int&& > );

CHECK( std20::constructible_from< Foo, Foo > );
CHECK( std20::constructible_from< Foo, Foo& > );
CHECK( std20::constructible_from< Foo, Foo&& > );
CHECK( std20::constructible_from< Foo, const Foo > );
CHECK( std20::constructible_from< Foo, const Foo& > );
CHECK( std20::constructible_from< Foo, const Foo&&> );

CHECK( ! std20::constructible_from< int&, int > );
CHECK( std20::constructible_from< int&, int& > );
CHECK( ! std20::constructible_from< int&, int&& > );
CHECK( ! std20::constructible_from< int&, const int > );
CHECK( ! std20::constructible_from< int&, const int& > );
CHECK( ! std20::constructible_from< int&, const int&& > );

CHECK( std20::constructible_from< const int&, int > );
CHECK( std20::constructible_from< const int&, int& > );
CHECK( std20::constructible_from< const int&, int&& > );
CHECK( std20::constructible_from< const int&, const int > );
CHECK( std20::constructible_from< const int&, const int& > );
CHECK( std20::constructible_from< const int&, const int&& > );

CHECK( std20::constructible_from< int&&, int > );
CHECK( ! std20::constructible_from< int&&, int& > );
CHECK( std20::constructible_from< int&&, int&& > );
CHECK( ! std20::constructible_from< int&&, const int > );
CHECK( ! std20::constructible_from< int&&, const int& > );
CHECK( ! std20::constructible_from< int&&, const int&& > );

CHECK( std20::constructible_from< const int&&, int > );
CHECK(! std20::constructible_from< const int&&, int& > );
CHECK( std20::constructible_from< const int&&, int&& > );
CHECK( std20::constructible_from< const int&&, const int > );
CHECK(! std20::constructible_from< const int&&, const int& > );
CHECK( std20::constructible_from< const int&&, const int&& > );
} // SCENARIO
41 changes: 41 additions & 0 deletions src/tools/std20/concepts/test/default_initializable.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/std20/concepts.hpp"

// other includes
#include <string>

// convenience typedefs
//using namespace njoy::tools;
namespace std20 = nano::ranges;

// test code
struct Foo {

~Foo() noexcept {};
};

struct NonDefaultConstructableFoo {

NonDefaultConstructableFoo() = delete;
~NonDefaultConstructableFoo() noexcept {};
};

SCENARIO( "default_initializable" ) {

CHECK( std20::default_initializable< Foo > );
CHECK( ! std20::default_initializable< NonDefaultConstructableFoo > );

CHECK( std20::default_initializable< int > );
CHECK( ! std20::default_initializable< const int > );
CHECK( ! std20::default_initializable< int& > );
CHECK( ! std20::default_initializable< int() > );
CHECK( ! std20::default_initializable< int (&)() > );
CHECK( std20::default_initializable< double > );
CHECK( ! std20::default_initializable< void > );
CHECK( ! std20::default_initializable< int[] > );
CHECK( std20::constructible_from< int[2] > );
CHECK( std20::default_initializable< int[2] > );
} // SCENARIO
57 changes: 57 additions & 0 deletions src/tools/std20/concepts/test/destructible.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/std20/concepts.hpp"

// other includes
#include <string>

// convenience typedefs
//using namespace njoy::tools;
namespace std20 = nano::ranges;

// test code
struct Foo {

~Foo() noexcept {};
};

struct IndestructibleFoo {

~IndestructibleFoo() = delete;
};

struct ThrowingDestructorFoo {

~ThrowingDestructorFoo() noexcept(false);
};

struct Bar {

~Bar() = default;
};

SCENARIO( "destructible" ) {

CHECK( std20::destructible< Foo > );
CHECK( std20::destructible< Bar > );
CHECK( std20::destructible< std::string > );

CHECK( ! std20::destructible< IndestructibleFoo > );
CHECK( ! std20::destructible< ThrowingDestructorFoo > );

CHECK( std20::destructible< int > );
CHECK( std20::destructible< const int > );

CHECK( std20::destructible< int& > );
CHECK( std20::destructible< void (*)() > );
CHECK( std20::destructible< void (&)() > );
CHECK( std20::destructible< int[2] > );
CHECK( std20::destructible< int (*)[2] > );
CHECK( std20::destructible< int (&)[2] > );

CHECK( ! std20::destructible< void > );
CHECK( ! std20::destructible< void() > );
CHECK( ! std20::destructible< int[] > );
} // SCENARIO

0 comments on commit 831c2cc

Please sign in to comment.