Parcourir la source

Adding test cases for three-layer systems of the for ABA.
In theory, these test cases (AA, AB, ABA) provide sufficient coverage to demonstrate solidity.

Samuel Jaffe il y a 9 ans
Parent
commit
ec1068b776
2 fichiers modifiés avec 45 ajouts et 5 suppressions
  1. 4 4
      recursive_iterator.hpp
  2. 41 1
      recursive_iterator_mixed_container.t.h

+ 4 - 4
recursive_iterator.hpp

@@ -288,20 +288,20 @@ namespace iterator {
 
 template <typename C>
 auto make_recursive_iterator(C & collect) -> iterator::recursive_iterator<decltype(std::begin(collect))> {
-  return {{ std::begin(collect), std::end(collect) }};
+  return { make_end_aware_iterator(collect)};
 }
 
 template <typename C>
 auto make_recursive_iterator(C const & collect) -> iterator::recursive_iterator<decltype(std::begin(collect))> {
-  return {{ std::begin(collect), std::end(collect) }};
+  return { make_end_aware_iterator(collect) };
 }
 
 template <std::size_t Max, typename C>
 auto make_recursive_iterator(C & collect) -> iterator::recursive_iterator_n<decltype(std::begin(collect)), Max> {
-  return {{ std::begin(collect), std::end(collect) }};
+  return { make_end_aware_iterator(collect) };
 }
 
 template <std::size_t Max, typename C>
 auto make_recursive_iterator(C const & collect) -> iterator::recursive_iterator_n<decltype(std::begin(collect)), Max> {
-  return {{ std::begin(collect), std::end(collect) }};
+  return { make_end_aware_iterator(collect) };
 }

+ 41 - 1
recursive_iterator_mixed_container.t.h

@@ -61,11 +61,51 @@ public:
     TS_ASSERT_EQUALS(obj[0][1], 6);
   }
   
-  void test_map_vector_map_iterator() {
+  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);
+  }
 };