#ifndef SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP #define SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP #include #include #include namespace testspr { static void tuple_test() { using namespace sprout; { SPROUT_STATIC_CONSTEXPR auto tup1 = sprout::tuples::tuple(1, 1.0); SPROUT_STATIC_CONSTEXPR auto tup2 = sprout::tuples::tuple(); // constructor { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 0); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(tup1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(1, 1.0); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(1l); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(1l, 1.0f); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(1l, 1.0f, '-'); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(sprout::tuples::tuple(1l)); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(sprout::tuples::tuple(1l, 1.0f)); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple(sprout::tuples::tuple(1l, 1.0f, '-')); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } // operator= { auto tup3 = tup2; tup3 = sprout::tuples::tuple(1, 1.0); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { auto tup3 = tup2; tup3 = sprout::tuples::tuple(1l); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); } { auto tup3 = tup2; tup3 = sprout::tuples::tuple(1l, 1.0f); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } { auto tup3 = tup2; tup3 = sprout::tuples::tuple(1l, 1.0f, '-'); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } // swap { auto tup3 = tup1; auto tup4 = tup2; tup3.swap(tup4); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 0); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); TESTSPR_ASSERT(sprout::tuples::get<0>(tup4) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup4) == 1.0); } { auto tup3 = tup1; auto tup4 = tup2; swap(tup3, tup4); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 0); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0); TESTSPR_ASSERT(sprout::tuples::get<0>(tup4) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup4) == 1.0); } // std::tuple_size TESTSPR_BOTH_ASSERT(std::tuple_size::value == 2); // std::tuple_element TESTSPR_BOTH_ASSERT((std::is_same::type, int const>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, double const>::value)); // operator== TESTSPR_BOTH_ASSERT(!(tup1 == tup2)); TESTSPR_BOTH_ASSERT((tup1 == sprout::tuples::tuple(1, 1.0))); TESTSPR_BOTH_ASSERT((!(tup1 == sprout::tuples::tuple()))); TESTSPR_BOTH_ASSERT((tup1 == sprout::tuples::tuple(1l, 1.0f))); // operator!= TESTSPR_BOTH_ASSERT(tup1 != tup2); TESTSPR_BOTH_ASSERT((!(tup1 != sprout::tuples::tuple(1, 1.0)))); TESTSPR_BOTH_ASSERT((tup1 != sprout::tuples::tuple())); TESTSPR_BOTH_ASSERT((!(tup1 != sprout::tuples::tuple(1l, 1.0f)))); // operator< TESTSPR_BOTH_ASSERT(!(tup1 < tup2)); TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple(1, -1.0)))); TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple(1, 1.0)))); TESTSPR_BOTH_ASSERT((tup1 < sprout::tuples::tuple(1, 2.0))); TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple()))); TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple(1l, -1.0f)))); TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple(1l, 1.0f)))); TESTSPR_BOTH_ASSERT((tup1 < sprout::tuples::tuple(1l, 2.0f))); // operator> TESTSPR_BOTH_ASSERT(tup1 > tup2); TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple(1, -1.0))); TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple(1, 1.0)))); TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple(1, 2.0)))); TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple())); TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple(1l, -1.0f))); TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple(1l, 1.0f)))); TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple(1l, 2.0f)))); // operator<= TESTSPR_BOTH_ASSERT(!(tup1 <= tup2)); TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple(1, -1.0)))); TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple(1, 1.0))); TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple(1, 2.0))); TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple()))); TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple(1l, -1.0f)))); TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple(1l, 1.0f))); TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple(1l, 2.0f))); // operator>= TESTSPR_BOTH_ASSERT(tup1 >= tup2); TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple(1, -1.0))); TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple(1, 1.0))); TESTSPR_BOTH_ASSERT((!(tup1 >= sprout::tuples::tuple(1, 2.0)))); TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple())); TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple(1l, -1.0f))); TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple(1l, 1.0f))); TESTSPR_BOTH_ASSERT((!(tup1 >= sprout::tuples::tuple(1l, 2.0f)))); // get TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup1) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup1) == 1.0); { auto tup3 = tup1; TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } // tuple_size TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 2); // tuple_element TESTSPR_BOTH_ASSERT((std::is_same::type, int const>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, double const>::value)); // make_tuple TESTSPR_BOTH_ASSERT(sprout::tuples::make_tuple(1, 1.0) == tup1); // forward_as_tuple TESTSPR_BOTH_ASSERT(sprout::tuples::forward_as_tuple(1, 1.0) == tup1); // tie { auto v1 = 0; auto v2 = 0.0; TESTSPR_ASSERT(sprout::tuples::tie(v1, v2) == tup2); sprout::tuples::tie(v1, v2) = tup1; TESTSPR_ASSERT(v1 == 1); TESTSPR_ASSERT(v2 == 1.0); } // tuple_cat { typedef sprout::tuples::result_of::tuple_cat::type concatenated_type; TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 4); TESTSPR_BOTH_ASSERT((std::is_same::type, int>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, double>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, int>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, double>::value)); } { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple_cat(tup1, tup2); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); TESTSPR_BOTH_ASSERT(sprout::tuples::get<2>(tup3) == 0); TESTSPR_BOTH_ASSERT(sprout::tuples::get<3>(tup3) == 0.0); } // is_tuple TESTSPR_BOTH_ASSERT(sprout::tuples::is_tuple::value); TESTSPR_BOTH_ASSERT(!sprout::tuples::is_tuple::value); // sprout::to_hash, sprout::hash { typedef sprout::tuples::tuple type; TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1, 2)) == sprout::hash()(type(1, 2))); TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1, 2)) != sprout::to_hash(type())); } } } } // namespace testspr #ifndef TESTSPR_CPP_INCLUDE # define TESTSPR_TEST_FUNCTION testspr::tuple_test # include #endif #endif // #ifndef SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP