1 //===- llvm/unittest/ADT/SmallPtrSetTest.cpp ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // SmallPtrSet unit tests.
12 //===----------------------------------------------------------------------===//
14 #include "gtest/gtest.h"
15 #include "llvm/ADT/SmallPtrSet.h"
19 // SmallPtrSet swapping test.
20 TEST(SmallPtrSetTest, GrowthTest) {
23 for(i=0; i<8; ++i) buf[i]=0;
26 SmallPtrSet<int *, 4> s;
27 typedef SmallPtrSet<int *, 4>::iterator iter;
33 EXPECT_EQ(4U, s.size());
36 for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
40 EXPECT_EQ(i<4?1:0,buf[i]);
48 for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
55 EXPECT_EQ(4U, s.size());
58 for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
62 EXPECT_EQ(i<4?3:1,buf[i]);
65 for(i=0; i<8; ++i) buf[i]=0;
66 for(i=0; i<128; ++i) s.insert(&buf[i%8]); // test repeated entires
67 EXPECT_EQ(8U, s.size());
68 for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
74 TEST(SmallPtrSetTest, CopyAndMoveTest) {
76 for (int i = 0; i < 8; ++i)
79 SmallPtrSet<int *, 4> s1;
84 EXPECT_EQ(4U, s1.size());
85 for (int i = 0; i < 8; ++i)
87 EXPECT_TRUE(s1.count(&buf[i]));
89 EXPECT_FALSE(s1.count(&buf[i]));
91 SmallPtrSet<int *, 4> s2(s1);
92 EXPECT_EQ(4U, s2.size());
93 for (int i = 0; i < 8; ++i)
95 EXPECT_TRUE(s2.count(&buf[i]));
97 EXPECT_FALSE(s2.count(&buf[i]));
100 EXPECT_EQ(4U, s1.size());
101 for (int i = 0; i < 8; ++i)
103 EXPECT_TRUE(s1.count(&buf[i]));
105 EXPECT_FALSE(s1.count(&buf[i]));
107 SmallPtrSet<int *, 4> s3(llvm_move(s1));
108 EXPECT_EQ(4U, s3.size());
109 for (int i = 0; i < 8; ++i)
111 EXPECT_TRUE(s3.count(&buf[i]));
113 EXPECT_FALSE(s3.count(&buf[i]));
116 EXPECT_EQ(4U, s1.size());
117 for (int i = 0; i < 8; ++i)
119 EXPECT_TRUE(s1.count(&buf[i]));
121 EXPECT_FALSE(s1.count(&buf[i]));
124 TEST(SmallPtrSetTest, SwapTest) {
127 SmallPtrSet<int *, 2> a;
128 SmallPtrSet<int *, 2> b;
136 EXPECT_EQ(1U, a.size());
137 EXPECT_EQ(2U, b.size());
138 EXPECT_TRUE(a.count(&buf[2]));
139 EXPECT_TRUE(b.count(&buf[0]));
140 EXPECT_TRUE(b.count(&buf[1]));
145 EXPECT_EQ(3U, a.size());
146 EXPECT_EQ(1U, b.size());
147 EXPECT_TRUE(a.count(&buf[0]));
148 EXPECT_TRUE(a.count(&buf[1]));
149 EXPECT_TRUE(a.count(&buf[3]));
150 EXPECT_TRUE(b.count(&buf[2]));
154 EXPECT_EQ(1U, a.size());
155 EXPECT_EQ(3U, b.size());
156 EXPECT_TRUE(a.count(&buf[2]));
157 EXPECT_TRUE(b.count(&buf[0]));
158 EXPECT_TRUE(b.count(&buf[1]));
159 EXPECT_TRUE(b.count(&buf[3]));
167 EXPECT_EQ(3U, a.size());
168 EXPECT_EQ(4U, b.size());
169 EXPECT_TRUE(b.count(&buf[2]));
170 EXPECT_TRUE(b.count(&buf[4]));
171 EXPECT_TRUE(b.count(&buf[5]));
172 EXPECT_TRUE(b.count(&buf[6]));
173 EXPECT_TRUE(a.count(&buf[0]));
174 EXPECT_TRUE(a.count(&buf[1]));
175 EXPECT_TRUE(a.count(&buf[3]));