forked from Alepha/Alepha
Function Composition helpers
This commit is contained in:
48
Functional/composition.test/0.cc
Normal file
48
Functional/composition.test/0.cc
Normal file
@ -0,0 +1,48 @@
|
||||
static_assert( __cplusplus >= 2023'02 );
|
||||
|
||||
#include <Alepha/Functional/composition.h>
|
||||
|
||||
#include <Alepha/Testing/test.h>
|
||||
|
||||
#include <Alepha/Utility/enroll.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace Alepha::Testing::exports;
|
||||
|
||||
|
||||
auto init= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
"smoke test"_test <=[]( Environment test )
|
||||
{
|
||||
using namespace Alepha::Functional::exports::composition_m;
|
||||
|
||||
auto i= ident * ident;
|
||||
|
||||
auto add_two= []( const int x )
|
||||
{
|
||||
return x + 2;
|
||||
};
|
||||
|
||||
auto mult_two= []( const int x ) { return x * 2; };
|
||||
|
||||
auto add_two_then_mult_two= mult_two * add_two;
|
||||
|
||||
test.expect( add_two_then_mult_two( 1 ) == 6 );
|
||||
};
|
||||
|
||||
"compose test"_test <=[]( Environment test )
|
||||
{
|
||||
using namespace Alepha::Functional::exports::composition_m;
|
||||
|
||||
auto add= []( const int x, const int y )
|
||||
{
|
||||
return x + y;
|
||||
};
|
||||
|
||||
auto mult3= []( const int x ) { return x * 3; };
|
||||
|
||||
test.expect( ( add >> mult3 )( 2, 1 ) == 9 );
|
||||
};
|
||||
};
|
||||
}
|
||||
1
Functional/composition.test/CMakeLists.txt
Normal file
1
Functional/composition.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
unit_test( 0 )
|
||||
Reference in New Issue
Block a user