| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include "iterator/recursive_iterator.hpp"
- #include <map>
- #include <vector>
- #include <gmock/gmock.h>
- TEST(RecursiveIteratorMapVectorTest, IterDistanceIsSumOfInnerContainerSizes) {
- std::map<int, std::vector<int>> const obj{
- {1, {1, 2}},
- {2, {3, 4, 5}}
- };
- auto rit = make_recursive_iterator(obj);
- decltype(rit) end{ };
- // TODO: Actually perform the summation?
- EXPECT_THAT(std::distance(rit, end), 5);
- }
- TEST(RecursiveIteratorMapVectorTest, ElementsAreUnwrappedAsATuple) {
- 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}};
- // TODO: Collapse into a container instead
- auto rit = make_recursive_iterator(obj);
- for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
- EXPECT_THAT(*it, *rit);
- }
- }
- TEST(RecursiveIteratorMapVectorTest, CanMutatePointedToData) {
- 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;
- EXPECT_THAT(obj[1][0], 6);
- }
- TEST(RecursiveIteratorVectorMapTest, IterDistanceIsSumOfInnerContainerSizes) {
- std::vector<std::map<int, int>> const obj{
- {{1, 1}, {2, 2}},
- {{3, 3}, {4, 4}, {5, 5}}
- };
- auto rit = make_recursive_iterator(obj);
- decltype(rit) end{ };
- // TODO: Actually perform the summation?
- EXPECT_THAT(std::distance(rit, end), 5);
- }
- TEST(RecursiveIteratorVectorMapTest, ElementsAreUnwrappedAsATuple) {
- 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);
- // TODO: Collapse into a container instead
- for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
- EXPECT_THAT(*it, *rit);
- }
- }
- TEST(RecursiveIteratorVectorMapTest, CanMutatePointedToData) {
- 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;
- EXPECT_THAT(obj[0][1], 6);
- }
- TEST(RecursiveIteratorMapVecMapTest, IterDistanceIsSumOfInnerContainerSizes) {
- 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{ };
- EXPECT_THAT(std::distance(rit, end), expected.size());
- }
- TEST(RecursiveIteratorMapVecMapTest, ElementsAreUnwrappedAsATuple) {
- 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);
- // TODO: Collapse into a container instead
- for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
- EXPECT_THAT(*it, *rit);
- }
- }
- TEST(RecursiveIteratorMapVecMapTest, CanMutatePointedToData) {
- 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;
- EXPECT_THAT(obj[1][0][1], 4);
- }
- TEST(RecursiveIteratorVecMapVecTest, IterDistanceIsSumOfInnerContainerSizes) {
- std::vector<std::map<int, std::vector<int>>> const obj{
- {
- {1, {1, 2}},
- {2, {3, 4, 5}}
- },
- {
- {1, {3, 4}}
- }
- };
- auto rit = make_recursive_iterator(obj);
- decltype(rit) end{ };
- // TODO: Actually perform the summation?
- EXPECT_THAT(std::distance(rit, end), 7);
- }
- TEST(RecursiveIteratorVecMapVecTest, ElementsAreUnwrappedAsATuple) {
- 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);
- // TODO: Collapse into a container instead
- for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
- EXPECT_THAT(*it, *rit);
- }
- }
- TEST(RecursiveIteratorVecMapVecTest, CanMutatePointedToData) {
- 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;
- EXPECT_THAT(obj[0][1][0], 6);
- }
|