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