#include "iterator/recursive_iterator.hpp" #include #include #include TEST(RecursiveIteratorMapVectorTest, IterDistanceIsSumOfInnerContainerSizes) { std::map> 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> const obj{ {1, {1, 2}}, {2, {3, 4, 5}} }; std::vector> 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> 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> 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> const obj{ {{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}} }; std::vector> 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> 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>> const obj{ {1, { {{1, 1}, {2, 2}} }} }; std::vector> 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>> const obj{ {1, { {{1, 1}, {2, 2}} }} }; std::vector> 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>> 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>> 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>> const obj{ { {1, {1, 2}}, {2, {3, 4, 5}} }, { {1, {3, 4}} } }; std::vector> 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>> 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); }