// // recursive_iterator_nested_map.t.h // iterator // // Created by Sam Jaffe on 2/18/17. // #pragma once #include #include "recursive_iterator.hpp" class recursive_iterator_nested_map_TestSuite : public CxxTest::TestSuite { public: void test_map_iterator_matches_size() { std::map const map{{1, 1}, {2, 2}, {3, 3}}; auto rit = make_recursive_iterator(map); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), map.size()); } void test_map_iterator_matches_data() { std::map const map{{1, 1}, {2, 2}, {3, 3}}; auto rit = make_recursive_iterator(map); for (auto it = map.begin(), end = map.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } void test_map_iterator_can_edit_data() { std::map map{{1, 1}, {2, 2}, {3, 3}}; auto rit = make_recursive_iterator(map); std::get<1>(*rit) = 4; TS_ASSERT_EQUALS(map[1], 4); } void test_map_map_iterator_matches_size() { std::map> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}}; std::vector> const expected{{1, 1, 1}, {2, 2, 2}, {2, 3, 3}}; auto rit = make_recursive_iterator(map); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), expected.size()); } void test_map_map_iterator_matches_data() { std::map> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}}; std::vector> const expected{{1, 1, 1}, {2, 2, 2}, {2, 3, 3}}; auto rit = make_recursive_iterator(map); for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(std::tuple_cat(*it), *rit); } } void test_map_map_iterator_can_edit_data() { std::map> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}}; auto rit = make_recursive_iterator(map); std::get<2>(*rit) = 4; TS_ASSERT_EQUALS(map[1][1], 4); } void test_map_map_bounded_matches_size() { std::map> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}}; auto rit = make_recursive_iterator<1>(map); decltype(rit) end{ }; TS_ASSERT_EQUALS(std::distance(rit, end), map.size()); } void test_map_map_bounded_matches_data() { std::map> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}}; auto rit = make_recursive_iterator<1>(map); for (auto it = map.begin(), end = map.end(); it != end; ++it, ++rit) { TS_ASSERT_EQUALS(*it, *rit); } } };