2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2018-04-05 13:54:42 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tuple/value.hpp>
|
2018-04-05 13:54:42 +10:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2018-04-05 13:54:42 +10:00
|
|
|
|
|
|
|
{
|
|
|
|
auto tuple = std::make_tuple (1,2,3,4);
|
|
|
|
std::vector<int> expected {{ 1, 2, 3, 4 }};
|
|
|
|
|
|
|
|
std::vector<int> actual;
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::tuple::value::each ([&actual] (auto i) { actual.push_back (i); }, tuple);
|
2018-04-05 13:54:42 +10:00
|
|
|
|
|
|
|
tap.expect_eq (actual, expected, "value iteration");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::tuple a (1, 2);
|
|
|
|
std::array<char,2> b { 'a', 'b' };
|
|
|
|
std::tuple c (
|
|
|
|
std::tuple(1, 'a'),
|
|
|
|
std::tuple(2, 'b')
|
|
|
|
);
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (c, cruft::tuple::value::zip (a, b), "tuple zipping");
|
2018-04-05 13:54:42 +10:00
|
|
|
}
|
|
|
|
|
2018-04-05 16:06:09 +10:00
|
|
|
{
|
|
|
|
std::tuple a (1, 2);
|
2018-08-05 14:42:02 +10:00
|
|
|
auto result = cruft::tuple::value::reverse (a);
|
2018-04-05 16:06:09 +10:00
|
|
|
std::tuple expected (2, 1);
|
|
|
|
|
|
|
|
tap.expect_eq (result, expected, "tuple reverse");
|
|
|
|
}
|
|
|
|
|
2020-02-25 11:17:05 +11:00
|
|
|
tap.expect (
|
|
|
|
cruft::tuple::value::all (std::tuple<bool,int> { true, 3 }),
|
|
|
|
"tuple::all succeeds"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect (
|
2020-02-25 11:31:56 +11:00
|
|
|
!cruft::tuple::value::all (std::tuple<bool,int> (true, 0)),
|
2020-02-25 11:17:05 +11:00
|
|
|
"tuple::all fails"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect (
|
|
|
|
cruft::tuple::value::none (std::tuple<bool,int> (false, 0)),
|
|
|
|
"tuple::none succeeds"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect (
|
2020-02-25 11:31:56 +11:00
|
|
|
!cruft::tuple::value::none (std::tuple<bool,int> (false, 1)),
|
2020-02-25 11:17:05 +11:00
|
|
|
"tuple::none fails"
|
|
|
|
);
|
|
|
|
|
2018-04-05 13:54:42 +10:00
|
|
|
return tap.status ();
|
2020-02-25 11:31:56 +11:00
|
|
|
}
|