#include #include #include #include #include #include #include #include #include #include // custom include #include BOOST_AUTO_TEST_SUITE(test_flat_iterator) BOOST_AUTO_TEST_CASE(test_derive_inner_iterator_type) { using namespace LibFundament::Details; BOOST_STATIC_ASSERT(( boost::is_same< derive_inner_iterator_type >::iterator>::type, std::list::iterator >::value == true)); BOOST_STATIC_ASSERT(( boost::is_same< derive_inner_iterator_type >::iterator>::type, std::list::const_iterator >::value == false)); BOOST_STATIC_ASSERT(( boost::is_same< derive_inner_iterator_type >::const_iterator>::type, std::list::const_iterator >::value == true)); } BOOST_AUTO_TEST_CASE(test_derive_value_type) { using namespace LibFundament::Details; BOOST_STATIC_ASSERT(( boost::is_const< derive_value_type< std::vector::iterator, std::list::iterator >::type>::value == false)); BOOST_STATIC_ASSERT(( boost::is_const< derive_value_type< std::vector::const_iterator, std::list::iterator >::type>::value == true)); BOOST_STATIC_ASSERT(( boost::is_const< derive_value_type< std::vector::iterator, std::list::const_iterator >::type>::value == true)); BOOST_STATIC_ASSERT(( boost::is_const< derive_value_type< std::vector::const_iterator, std::list::const_iterator >::type>::value == true)); } BOOST_AUTO_TEST_CASE(test_flatten_single) { using namespace boost::assign; using namespace LibFundament; typedef std::list inner_container_type; typedef std::vector outer_container_type; outer_container_type elements(6); elements[1] += 1,2,3; elements[2] += 4,5; elements[4] += 6; BOOST_CHECK(std::equal( make_flat_iterator(elements.begin(), elements.end()), make_flat_iterator(elements.end(), elements.end()), list_of(1)(2)(3)(4)(5)(6).begin())); BOOST_CHECK(std::equal( boost::make_reverse_iterator(make_flat_iterator(elements.end(), elements.end())), boost::make_reverse_iterator(make_flat_iterator(elements.begin(), elements.end())), list_of(6)(5)(4)(3)(2)(1).begin())); inner_container_type transformed; std::transform( make_flat_iterator(elements.begin(), elements.end()), make_flat_iterator(elements.begin() + 2, elements.end()), std::back_inserter(transformed), std::bind2nd(std::multiplies(), 2)); BOOST_CHECK(transformed == list_of(2)(4)(6)); } BOOST_AUTO_TEST_CASE(test_flatten_multiple) { using namespace boost::assign; using namespace LibFundament; typedef std::list level_0; typedef std::vector level_1; typedef std::vector level_2; level_2 elements(10); elements[2] += list_of(1)(2); elements[4] += list_of(3)(4); typedef flat_iterator flat_iterator_outer; typedef flat_iterator flat_iterator_inner; flat_iterator_outer outer_begin(elements.begin(), elements.end()); flat_iterator_outer outer_end(elements.end(), elements.end()); flat_iterator_inner inner_begin(outer_begin, outer_end); flat_iterator_inner inner_end(outer_end, outer_end); BOOST_CHECK(std::equal(inner_begin, inner_end, list_of(1)(2)(3)(4).begin())); } BOOST_AUTO_TEST_SUITE_END()