llvm.org GIT mirror llvm / 1721b61
Remove SmallMap unittests, unbreaking the build. I don't know how useful these are for SmallDenseMap, I'll leave that decision to Chandler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158646 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
1 changed file(s) with 0 addition(s) and 162 deletion(s). Raw diff Collapse all Expand all
+0
-162
unittests/ADT/SmallMapTest.cpp less more
None //===- llvm/unittest/ADT/SmallMapTest.cpp ------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // SmallMap unit tests.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "gtest/gtest.h"
14 #include "llvm/ADT/SmallMap.h"
15
16 using namespace llvm;
17
18 // SmallMap test.
19 TEST(SmallMapTest, GeneralTest) {
20
21 int buf[10];
22
23 SmallMap a;
24 SmallMap b;
25 SmallMap::iterator found;
26 std::pair::iterator, bool> insRes;
27 SmallMap::const_iterator foundc;
28
29 a.insert(std::make_pair(&buf[0], 0));
30 insRes = a.insert(std::make_pair(&buf[1], 1));
31 EXPECT_TRUE(insRes.second);
32
33 // Check insertion, looking up, and data editing in small mode.
34 insRes = a.insert(std::make_pair(&buf[1], 6));
35 EXPECT_FALSE(insRes.second);
36 EXPECT_EQ(insRes.first->second, 1);
37 insRes.first->second = 5;
38 found = a.find(&buf[1]);
39 EXPECT_NE(found, a.end());
40 EXPECT_EQ(found->second, 5);
41 a[&buf[1]] = 10;
42 EXPECT_EQ(found->second, 10);
43 // Check "not found" case.
44 found = a.find(&buf[8]);
45 EXPECT_EQ(found, a.end());
46
47 b.insert(std::make_pair(&buf[2], 2));
48
49 std::swap(a, b);
50 a.swap(b);
51 std::swap(a, b);
52
53 EXPECT_EQ(1U, a.size());
54 EXPECT_EQ(2U, b.size());
55 EXPECT_TRUE(a.count(&buf[2]));
56 EXPECT_TRUE(b.count(&buf[0]));
57 EXPECT_TRUE(b.count(&buf[1]));
58
59 insRes = b.insert(std::make_pair(&buf[3], 3));
60 EXPECT_TRUE(insRes.second);
61
62 // Check insertion, looking up, and data editing in big mode.
63 insRes = b.insert(std::make_pair(&buf[3], 6));
64 EXPECT_FALSE(insRes.second);
65 EXPECT_EQ(insRes.first->second, 3);
66 insRes.first->second = 7;
67 found = b.find(&buf[3]);
68 EXPECT_EQ(found->second, 7);
69 b[&buf[3]] = 14;
70 EXPECT_EQ(found->second, 14);
71 // Check constant looking up.
72 foundc = b.find(&buf[3]);
73 EXPECT_EQ(foundc->first, &buf[3]);
74 EXPECT_EQ(foundc->second, 14);
75 // Check not found case.
76 found = b.find(&buf[8]);
77 EXPECT_EQ(found, b.end());
78
79 std::swap(a, b);
80 a.swap(b);
81 std::swap(a, b);
82
83 EXPECT_EQ(3U, a.size());
84 EXPECT_EQ(1U, b.size());
85 EXPECT_TRUE(a.count(&buf[0]));
86 EXPECT_TRUE(a.count(&buf[1]));
87 EXPECT_TRUE(a.count(&buf[3]));
88 EXPECT_TRUE(b.count(&buf[2]));
89 EXPECT_EQ(b.find(&buf[2])->second, 2);
90
91 std::swap(a, b);
92 a.swap(b);
93 std::swap(a, b);
94
95 EXPECT_EQ(1U, a.size());
96 EXPECT_EQ(3U, b.size());
97 EXPECT_TRUE(a.count(&buf[2]));
98 EXPECT_TRUE(b.count(&buf[0]));
99 EXPECT_TRUE(b.count(&buf[1]));
100 EXPECT_TRUE(b.count(&buf[3]));
101
102 a.insert(std::make_pair(&buf[4], 4));
103 a.insert(std::make_pair(&buf[5], 5));
104 a.insert(std::make_pair(&buf[6], 6));
105
106 std::swap(b, a);
107
108 EXPECT_EQ(3U, a.size());
109 EXPECT_EQ(4U, b.size());
110 EXPECT_TRUE(b.count(&buf[2]));
111 EXPECT_TRUE(b.count(&buf[4]));
112 EXPECT_TRUE(b.count(&buf[5]));
113 EXPECT_TRUE(b.count(&buf[6]));
114 EXPECT_TRUE(a.count(&buf[0]));
115 EXPECT_TRUE(a.count(&buf[1]));
116 EXPECT_TRUE(a.count(&buf[3]));
117
118 // Check findAndConstruct
119 SmallMap::value_type Buf7;
120 Buf7 = a.FindAndConstruct(&buf[7]);
121 EXPECT_EQ(Buf7.second, 0);
122
123 // Check increments
124
125 SmallMap c;
126 c.insert(std::make_pair(&buf[0], 0));
127 c.insert(std::make_pair(&buf[1], 1));
128
129 // For small mode we know that flat array map is used and we know the
130 // order of items.
131 unsigned ii = 0;
132 for (SmallMap::iterator i = c.begin(), e = c.end();
133 i != e; ++i, ++ii) {
134 EXPECT_TRUE((i->first == &buf[0] && i->second == 0 && ii == 0) ||
135 (i->first == &buf[1] && i->second == 1 && ii == 1));
136 }
137
138 // For big mode DenseMap is used and final order of items is undefined.
139 c.insert(std::make_pair(&buf[2], 2));
140 for (SmallMap::iterator i = c.begin(), e = c.end();
141 i != e; ++i) {
142 EXPECT_TRUE((i->first == &buf[0] && i->second == 0) ||
143 (i->first == &buf[1] && i->second == 1) ||
144 (i->first == &buf[2] && i->second == 2));
145 }
146
147 // Check that iteration only visits elements that actually exist.
148 SmallMap d;
149 d[0] = 2;
150 d[1] = 3;
151 int counts[2] = { 0, 0 };
152 for (SmallMap::iterator I = d.begin(), E = d.end(); I != E;
153 ++I) {
154 EXPECT_TRUE(I->first == 0 || I->first == 1);
155 EXPECT_TRUE(I->second == 2 || I->second == 3);
156 EXPECT_EQ(I->second, I->first + 2);
157 ++counts[I->first];
158 }
159 EXPECT_EQ(counts[0], 1);
160 EXPECT_EQ(counts[1], 1);
161 }