tuple: split tests into separate units

This commit is contained in:
Danny Robson 2018-04-05 13:54:42 +10:00
parent 8f2f623520
commit 5f2b1a5c36
3 changed files with 46 additions and 39 deletions

View File

@ -537,7 +537,8 @@ if (TESTS)
thread/ticketlock
time/8601
traits
tuple
tuple/value
tuple/type
typeidx
uri
utf8

View File

@ -1,12 +1,8 @@
#include "tuple/type.hpp"
#include "tuple/value.hpp"
#include "tap.hpp"
#include <array>
#include <typeindex>
#include <vector>
#include "tuple/type.hpp"
#include <typeindex>
template <typename T>
struct int_mapper
@ -14,26 +10,15 @@ struct int_mapper
typedef int type;
};
int
main ()
main (void)
{
util::TAP::logger tap;
static_assert (
util::tuple::type::index<
std::tuple<float,int,void>,
int
>::value == 1
);
{
auto tuple = std::make_tuple (1,2,3,4);
std::vector<int> expected {{ 1, 2, 3, 4 }};
std::vector<int> actual;
util::tuple::value::each ([&actual] (auto i) { actual.push_back (i); }, tuple);
tap.expect_eq (actual, expected, "value iteration");
using tuple_t = std::tuple<float,int,void>;
tap.expect_eq (util::tuple::type::index<tuple_t,int>::value, 1u, "tuple index extraction");
}
{
@ -57,25 +42,13 @@ main ()
#endif
}
{
using src_t = std::tuple<std::string>;
using dst_t = typename util::tuple::type::map<src_t, int_mapper>::type;
tap.expect (std::is_same<dst_t, std::tuple<int>>::value, "tuple type mapping");
}
{
std::tuple a (1, 2);
std::array<char,2> b { 'a', 'b' };
std::tuple c (
std::tuple(1, 'a'),
std::tuple(2, 'b')
);
tap.expect_eq (c, util::tuple::value::zip (a, b), "tuple zipping");
}
return tap.status ();
}

33
test/tuple/value.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "tap.hpp"
#include "tuple/value.hpp"
int
main (void)
{
util::TAP::logger tap;
{
auto tuple = std::make_tuple (1,2,3,4);
std::vector<int> expected {{ 1, 2, 3, 4 }};
std::vector<int> actual;
util::tuple::value::each ([&actual] (auto i) { actual.push_back (i); }, tuple);
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')
);
tap.expect_eq (c, util::tuple::value::zip (a, b), "tuple zipping");
}
return tap.status ();
}