recursive_iterator_mixed_container.t.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // recursive_iterator_mixed_container.t.h
  3. // iterator
  4. //
  5. // Created by Sam Jaffe on 2/18/17.
  6. //
  7. #pragma once
  8. #include <cxxtest/TestSuite.h>
  9. #include "recursive_iterator.hpp"
  10. class recursive_iterator_mixed_container_TestSuite : public CxxTest::TestSuite {
  11. public:
  12. void test_map_vector_iterator_matches_size() {
  13. std::map<int, std::vector<int>> const obj{{1, {1, 2}}, {2, {3, 4, 5}}};
  14. std::vector<std::tuple<int, int>> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}};
  15. auto rit = make_recursive_iterator(obj);
  16. decltype(rit) end{ };
  17. TS_ASSERT_EQUALS(std::distance(rit, end), expected.size());
  18. }
  19. void test_map_vector_iterator_matches_data() {
  20. std::map<int, std::vector<int>> const obj{{1, {1, 2}}, {2, {3, 4, 5}}};
  21. std::vector<std::tuple<int, int>> const expected{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}};
  22. auto rit = make_recursive_iterator(obj);
  23. for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
  24. TS_ASSERT_EQUALS(*it, *rit);
  25. }
  26. }
  27. void test_map_vector_iterator_can_edit_data() {
  28. std::map<int, std::vector<int>> obj{{1, {1, 2}}, {2, {3, 4, 5}}};
  29. auto rit = make_recursive_iterator(obj);
  30. std::get<1>(*rit) = 6;
  31. TS_ASSERT_EQUALS(obj[1][0], 6);
  32. }
  33. void test_vector_map_iterator_matches_size() {
  34. std::vector<std::map<int, int>> const obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}};
  35. std::vector<std::tuple<int, int>> const expected{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
  36. auto rit = make_recursive_iterator(obj);
  37. decltype(rit) end{ };
  38. TS_ASSERT_EQUALS(std::distance(rit, end), expected.size());
  39. }
  40. void test_vector_map_iterator_matches_data() {
  41. std::vector<std::map<int, int>> const obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}};
  42. std::vector<std::tuple<int, int>> const expected{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
  43. auto rit = make_recursive_iterator(obj);
  44. for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
  45. TS_ASSERT_EQUALS(*it, *rit);
  46. }
  47. }
  48. void test_vector_map_iterator_can_edit_data() {
  49. std::vector<std::map<int, int>> obj{{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}, {5, 5}}};
  50. auto rit = make_recursive_iterator(obj);
  51. std::get<1>(*rit) = 6;
  52. TS_ASSERT_EQUALS(obj[0][1], 6);
  53. }
  54. void test_map_vector_map_iterator() {
  55. std::map<int, std::vector<std::map<int, int>>> const obj{{1, {{{1, 1}, {2, 2}}}}};
  56. std::vector<std::tuple<int, int, int>> const expected{{1, 1, 1}, {1, 2, 2}};
  57. auto rit = make_recursive_iterator(obj);
  58. decltype(rit) end{ };
  59. TS_ASSERT_EQUALS(std::distance(rit, end), expected.size());
  60. }
  61. };