Add MapVector::rbegin(), MapVector::rend() to completment MapVector::begin(), MapVect...
[oota-llvm.git] / unittests / ADT / MapVectorTest.cpp
index 46cd36acea96b391fc7b71296c67478950120e7f..89197993467ae5073fc4410e9477567017813829 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "gtest/gtest.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/iterator_range.h"
 #include <utility>
 
 using namespace llvm;
@@ -97,3 +98,27 @@ TEST(MapVectorTest, remove_if) {
   ASSERT_EQ(MV[4], 14);
   ASSERT_EQ(MV[6], 16);
 }
+
+TEST(MapVectorTest, iteration_test) {
+  MapVector<int, int> MV;
+
+  MV.insert(std::make_pair(1, 11));
+  MV.insert(std::make_pair(2, 12));
+  MV.insert(std::make_pair(3, 13));
+  MV.insert(std::make_pair(4, 14));
+  MV.insert(std::make_pair(5, 15));
+  MV.insert(std::make_pair(6, 16));
+  ASSERT_EQ(MV.size(), 6u);
+
+  int count = 1;
+  for (auto P : make_range(MV.begin(), MV.end())) {
+    ASSERT_EQ(P.first, count);
+    count++;
+  }
+
+  count = 6;
+  for (auto P : make_range(MV.rbegin(), MV.rend())) {
+    ASSERT_EQ(P.first, count);
+    count--;
+  }
+}