• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- unittest/ADT/MapVectorTest.cpp - MapVector unit tests ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/MapVector.h"
12 #include <utility>
13 
14 using namespace llvm;
15 
TEST(MapVectorTest,insert_pop)16 TEST(MapVectorTest, insert_pop) {
17   MapVector<int, int> MV;
18   std::pair<MapVector<int, int>::iterator, bool> R;
19 
20   R = MV.insert(std::make_pair(1, 2));
21   ASSERT_EQ(R.first, MV.begin());
22   EXPECT_EQ(R.first->first, 1);
23   EXPECT_EQ(R.first->second, 2);
24   EXPECT_TRUE(R.second);
25 
26   R = MV.insert(std::make_pair(1, 3));
27   ASSERT_EQ(R.first, MV.begin());
28   EXPECT_EQ(R.first->first, 1);
29   EXPECT_EQ(R.first->second, 2);
30   EXPECT_FALSE(R.second);
31 
32   R = MV.insert(std::make_pair(4, 5));
33   ASSERT_NE(R.first, MV.end());
34   EXPECT_EQ(R.first->first, 4);
35   EXPECT_EQ(R.first->second, 5);
36   EXPECT_TRUE(R.second);
37 
38   EXPECT_EQ(MV.size(), 2u);
39   EXPECT_EQ(MV[1], 2);
40   EXPECT_EQ(MV[4], 5);
41 
42   MV.pop_back();
43   EXPECT_EQ(MV.size(), 1u);
44   EXPECT_EQ(MV[1], 2);
45 
46   R = MV.insert(std::make_pair(4, 7));
47   ASSERT_NE(R.first, MV.end());
48   EXPECT_EQ(R.first->first, 4);
49   EXPECT_EQ(R.first->second, 7);
50   EXPECT_TRUE(R.second);
51 
52   EXPECT_EQ(MV.size(), 2u);
53   EXPECT_EQ(MV[1], 2);
54   EXPECT_EQ(MV[4], 7);
55 }
56