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)
75 TEST(SmallPtrSetTest, SwapTest) {
78 SmallPtrSet<int *, 2> a;
79 SmallPtrSet<int *, 2> b;
87 EXPECT_EQ(1U, a.size());
88 EXPECT_EQ(2U, b.size());
89 EXPECT_TRUE(a.count(&buf[2]));
90 EXPECT_TRUE(b.count(&buf[0]));
91 EXPECT_TRUE(b.count(&buf[1]));
96 EXPECT_EQ(3U, a.size());
97 EXPECT_EQ(1U, b.size());
98 EXPECT_TRUE(a.count(&buf[0]));
99 EXPECT_TRUE(a.count(&buf[1]));
100 EXPECT_TRUE(a.count(&buf[3]));
101 EXPECT_TRUE(b.count(&buf[2]));
105 EXPECT_EQ(1U, a.size());
106 EXPECT_EQ(3U, b.size());
107 EXPECT_TRUE(a.count(&buf[2]));
108 EXPECT_TRUE(b.count(&buf[0]));
109 EXPECT_TRUE(b.count(&buf[1]));
110 EXPECT_TRUE(b.count(&buf[3]));
118 EXPECT_EQ(3U, a.size());
119 EXPECT_EQ(4U, b.size());
120 EXPECT_TRUE(b.count(&buf[2]));
121 EXPECT_TRUE(b.count(&buf[4]));
122 EXPECT_TRUE(b.count(&buf[5]));
123 EXPECT_TRUE(b.count(&buf[6]));
124 EXPECT_TRUE(a.count(&buf[0]));
125 EXPECT_TRUE(a.count(&buf[1]));
126 EXPECT_TRUE(a.count(&buf[3]));