| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // recursive_iterator_nested_map.t.h
- // iterator
- //
- // Created by Sam Jaffe on 2/18/17.
- //
- #pragma once
- #include <cxxtest/TestSuite.h>
- #include "recursive_iterator.hpp"
- class recursive_iterator_nested_map_TestSuite : public CxxTest::TestSuite {
- public:
- void test_map_iterator_matches_size() {
- std::map<int, int> 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<int, int> 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<int, int> 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<int, std::map<int, int>> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
- std::vector<std::tuple<int, int, int>> 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<int, std::map<int, int>> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
- std::vector<std::tuple<int, int, int>> 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<int, std::map<int, int>> 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<int, std::map<int, int>> 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<int, std::map<int, int>> 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);
- }
- }
- };
|