X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=unittests%2FADT%2FMapVectorTest.cpp;h=89197993467ae5073fc4410e9477567017813829;hp=92f0dc41910b2ff8c6924c3fb7f03f68d20bc12e;hb=86ec9c4081169d44637d08afc4c9d88c4dd7f410;hpb=c12ce2b66186404177a3a9f854df0272beb52d81 diff --git a/unittests/ADT/MapVectorTest.cpp b/unittests/ADT/MapVectorTest.cpp index 92f0dc41910..89197993467 100644 --- a/unittests/ADT/MapVectorTest.cpp +++ b/unittests/ADT/MapVectorTest.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/MapVector.h" +#include "llvm/ADT/iterator_range.h" #include using namespace llvm; @@ -67,6 +68,14 @@ TEST(MapVectorTest, erase) { ASSERT_EQ(MV.find(1), MV.end()); ASSERT_EQ(MV[3], 4); ASSERT_EQ(MV[5], 6); + + ASSERT_EQ(MV.erase(3), 1u); + ASSERT_EQ(MV.size(), 1u); + ASSERT_EQ(MV.find(3), MV.end()); + ASSERT_EQ(MV[5], 6); + + ASSERT_EQ(MV.erase(79), 0u); + ASSERT_EQ(MV.size(), 1u); } TEST(MapVectorTest, remove_if) { @@ -89,3 +98,27 @@ TEST(MapVectorTest, remove_if) { ASSERT_EQ(MV[4], 14); ASSERT_EQ(MV[6], 16); } + +TEST(MapVectorTest, iteration_test) { + MapVector 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--; + } +}