forked from Alepha/Alepha
I added the lens-based comparison code.
The metaprogramming is still based upon the angle-bracket type-form. Now to rewrite it in terms of the constexpr systems.
This commit is contained in:
85
comparisons.test/0.cc
Normal file
85
comparisons.test/0.cc
Normal file
@ -0,0 +1,85 @@
|
||||
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||
|
||||
#include <Alepha/comparisons.h>
|
||||
|
||||
#include <Alepha/Testing/test.h>
|
||||
#include <Alepha/Testing/TableTest.h>
|
||||
#include <Alepha/Utility/evaluation.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
using Alepha::Testing::argcnt_t;
|
||||
using Alepha::Testing::argvec_t;
|
||||
}
|
||||
|
||||
int
|
||||
main( const argcnt_t argcnt, const argvec_t argvec )
|
||||
{
|
||||
return Alepha::Testing::runAllTests( argcnt, argvec );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace Alepha::Testing::exports;
|
||||
using namespace Alepha::exports::comparisons;
|
||||
using namespace Alepha::exports::capabilities;
|
||||
|
||||
template< typename= int, typename= Capabilities< comparable >, typename= float, typename= Capabilities< short > >
|
||||
struct Date_core
|
||||
{
|
||||
int y;
|
||||
int m;
|
||||
int d;
|
||||
|
||||
auto value_lens() const { return std::tie( y, m, d ); }
|
||||
};
|
||||
|
||||
using Date= Date_core<>;
|
||||
static_assert( Alepha::has_capability_v< Date, comparable > );
|
||||
|
||||
template< template< typename > class op, typename T >
|
||||
constexpr bool
|
||||
comp( const T &lhs, const T &rhs )
|
||||
{
|
||||
return op< T >{}( lhs, rhs );
|
||||
}
|
||||
|
||||
auto tests= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
"smoke.lt"_test <=TableTest< comp< std::less, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, true },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, false },
|
||||
};
|
||||
|
||||
"smoke.gt"_test <=TableTest< comp< std::greater, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, false },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, true },
|
||||
};
|
||||
|
||||
"smoke.le"_test <=TableTest< comp< std::less_equal, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, true },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, false },
|
||||
};
|
||||
|
||||
"smoke.ge"_test <=TableTest< comp< std::greater_equal, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, false },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, true },
|
||||
};
|
||||
|
||||
"smoke.eq"_test <=TableTest< comp< std::equal_to, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, false },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, false },
|
||||
};
|
||||
|
||||
"smoke.ne"_test <=TableTest< comp< std::not_equal_to, Date > >::Cases
|
||||
{
|
||||
{ "smoke1", { { 1982, 12, 21 }, { 2020, 12, 15 } }, true },
|
||||
{ "smoke1", { { 2020, 12, 15 }, { 1982, 12, 21 } }, true },
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user