// // recursive_iterator_mixed_container.t.h // iterator // // Created by Sam Jaffe on 2/18/17. // #pragma once #include #include "recursive_iterator.hpp" class recursive_iterator_mixed_container_TestSuite : public CxxTest::TestSuite { public: void test_map_vector_iterator_matches_size() { std::map> const obj{{1, {1, 2}}, {2, {3, 4, 5}}}; std::vector> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}}; auto rit = make_recursive_iterator(obj); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), expected.size()); } void test_map_vector_iterator_matches_data() { std::map> const obj{{1, {1, 2}}, {2, {3, 4, 5}}}; std::vector> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}}; auto rit = make_recursive_iterator(obj); for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } void test_map_vector_iterator_can_edit_data() { std::map> obj{{1, {1, 2}}, {2, {3, 4, 5}}}; auto rit = make_recursive_iterator(obj); std::get<1>(*rit) = 6; TS_ASSERT_EQUALS(obj[1][0], 6); } void test_vector_map_iterator_matches_size() { std::vector> const obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}}; std::vector> const expected{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}; auto rit = make_recursive_iterator(obj); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), expected.size()); } void test_vector_map_iterator_matches_data() { std::vector> const obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}}; std::vector> const expected{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}; auto rit = make_recursive_iterator(obj); for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } void test_vector_map_iterator_can_edit_data() { std::vector> obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}}; auto rit = make_recursive_iterator(obj); std::get<1>(*rit) = 6; TS_ASSERT_EQUALS(obj[0][1], 6); } void test_map_vector_map_iterator_matches_size() { std::map>> const obj{{1, {{{1, 1}, {2, 2}}}}}; std::vector> const expected{{1, 1, 1}, {1, 2, 2}}; auto rit = make_recursive_iterator(obj); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), expected.size()); } void test_map_vector_map_iterator_matches_data() { std::map>> const obj{{1, {{{1, 1}, {2, 2}}}}}; std::vector> const expected{{1, 1, 1}, {1, 2, 2}}; auto rit = make_recursive_iterator(obj); for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } void test_map_vector_map_iterator_can_edit_data() { std::map>> obj{{1, {{{1, 1}, {2, 2}}}}}; auto rit = make_recursive_iterator(obj); std::get<2>(*rit) = 4; TS_ASSERT_EQUALS(obj[1][0][1], 4); } void test_vector_map_vector_iterator_matches_size() { std::vector>> const obj{{{1, {1, 2}}, {2, {3, 4, 5}}}, {{1, {3, 4}}}}; std::vector> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {1, 3}, {1, 4}}; auto rit = make_recursive_iterator(obj); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), expected.size()); } void test_vector_map_vector_iterator_matches_data() { std::vector>> const obj{{{1, {1, 2}}, {2, {3, 4, 5}}}, {{1, {3, 4}}}}; std::vector> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {1, 3}, {1, 4}}; auto rit = make_recursive_iterator(obj); for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } void test_vector_map_vector_iterator_can_edit_data() { std::vector>> obj{{{1, {1, 2}}, {2, {3, 4, 5}}}, {{1, {3, 4}}}}; auto rit = make_recursive_iterator(obj); std::get<1>(*rit) = 6; TS_ASSERT_EQUALS(obj[0][1][0], 6); } };