Browse Source

fixed erase, more complex test case

Kajetan Johannes Hammerle 3 years ago
parent
commit
f2614f4784
1 changed files with 20 additions and 11 deletions
  1. 20 11
      Main.cpp

+ 20 - 11
Main.cpp

@@ -177,7 +177,7 @@ public:
         T* move = to;
         T* stop = end();
         // fill the hole by moving following objects as long as possible
-        while(remove != to && move != stop) {
+        while(move != stop) {
             *remove = std::move(*move);
             remove++;
             move++;
@@ -286,17 +286,26 @@ void test() {
         }
     }
     {
-        V v;
-        v.push_back(A(20));
-        v.push_back(A(21));
-        v.push_back(A(22));
-        v.erase(v.begin() + 1);
-        if(v.size() != 2 || v[0].a != 20 || v[1].a != 22) {
-            printError(7);
+        std::vector<A> v1;
+        V v2;
+        for(int i = 0; i < 200; i++) {
+            v1.push_back(A(i));
+            v2.push_back(A(i));
         }
-        v.erase(v.begin(), v.end());
-        if(v.size() != 0) {
-            printError(8);
+        v1.erase(v1.begin());
+        v1.erase(v1.begin() + 4, v1.begin() + 8);
+        v1.erase(v1.begin() + 30, v1.begin() + 56);
+        v2.erase(v2.begin());
+        v2.erase(v2.begin() + 4, v2.begin() + 8);
+        v2.erase(v2.begin() + 30, v2.begin() + 56);
+        if(static_cast<int>(v1.size()) != static_cast<int>(v2.size())) {
+            printError(100);
+        } else {
+            for(unsigned int i = 0; i < v1.size(); i++) {
+                if(v1[i].a != v2[i].a) {
+                    printError(200);
+                }
+            }
         }
     }
     if(A::instances != 0) {