| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // 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::pair<int const, 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::pair<int const, 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_matches_size() {
- 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());
- }
- void test_map_vector_map_iterator_matches_data() {
- 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);
- 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<int, std::vector<std::map<int, int>>> 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<std::map<int, std::vector<int>>> const obj{{{1, {1, 2}}, {2, {3, 4, 5}}}, {{1, {3, 4}}}};
- std::vector<std::tuple<int, int>> 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<std::map<int, std::vector<int>>> const obj{{{1, {1, 2}}, {2, {3, 4, 5}}}, {{1, {3, 4}}}};
- std::vector<std::tuple<int, int>> 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<std::map<int, std::vector<int>>> 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);
- }
- };
|