recursive_iterator_nested_map.t.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // recursive_iterator_nested_map.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_nested_map_TestSuite : public CxxTest::TestSuite {
  11. public:
  12. void test_map_iterator_matches_size() {
  13. std::map<int, int> const map{{1, 1}, {2, 2}, {3, 3}};
  14. auto rit = make_recursive_iterator(map);
  15. decltype(rit) end{ };
  16. TS_ASSERT_EQUALS(std::distance(rit, end), map.size());
  17. }
  18. void test_map_iterator_matches_data() {
  19. std::map<int, int> const map{{1, 1}, {2, 2}, {3, 3}};
  20. auto rit = make_recursive_iterator(map);
  21. for (auto it = map.begin(), end = map.end(); it != end; ++it, ++rit) {
  22. TS_ASSERT_EQUALS(*it, *rit);
  23. }
  24. }
  25. void test_map_iterator_can_edit_data() {
  26. std::map<int, int> map{{1, 1}, {2, 2}, {3, 3}};
  27. auto rit = make_recursive_iterator(map);
  28. std::get<1>(*rit) = 4;
  29. TS_ASSERT_EQUALS(map[1], 4);
  30. }
  31. void test_map_map_iterator_matches_size() {
  32. std::map<int, std::map<int, int>> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
  33. std::vector<std::tuple<int, int, int>> const expected{{1, 1, 1}, {2, 2, 2}, {2, 3, 3}};
  34. auto rit = make_recursive_iterator(map);
  35. decltype(rit) end{ };
  36. TS_ASSERT_EQUALS(std::distance(rit, end), expected.size());
  37. }
  38. void test_map_map_iterator_matches_data() {
  39. std::map<int, std::map<int, int>> const map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
  40. std::vector<std::tuple<int, int, int>> const expected{{1, 1, 1}, {2, 2, 2}, {2, 3, 3}};
  41. auto rit = make_recursive_iterator(map);
  42. for (auto it = expected.begin(), end = expected.end(); it != end; ++it, ++rit) {
  43. TS_ASSERT_EQUALS(std::tuple_cat(*it), *rit);
  44. }
  45. }
  46. void test_map_map_iterator_can_edit_data() {
  47. std::map<int, std::map<int, int>> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
  48. auto rit = make_recursive_iterator(map);
  49. std::get<2>(*rit) = 4;
  50. TS_ASSERT_EQUALS(map[1][1], 4);
  51. }
  52. void test_map_map_bounded_matches_size() {
  53. std::map<int, std::map<int, int>> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
  54. auto rit = make_recursive_iterator<1>(map);
  55. decltype(rit) end{ };
  56. TS_ASSERT_EQUALS(std::distance(rit, end), map.size());
  57. }
  58. void test_map_map_bounded_matches_data() {
  59. std::map<int, std::map<int, int>> map{{1, {{1, 1}}}, {2, {{2, 2}, {3, 3}}}};
  60. auto rit = make_recursive_iterator<1>(map);
  61. for (auto it = map.begin(), end = map.end(); it != end; ++it, ++rit) {
  62. TS_ASSERT_EQUALS(*it, *rit);
  63. }
  64. }
  65. };