Home | History | Annotate | Download | only in ADT
      1 //===- llvm/unittest/ADT/SmallPtrSetTest.cpp ------------------------------===//
      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 // SmallPtrSet unit tests.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "gtest/gtest.h"
     15 #include "llvm/ADT/SmallPtrSet.h"
     16 
     17 using namespace llvm;
     18 
     19 // SmallPtrSet swapping test.
     20 TEST(SmallPtrSetTest, SwapTest) {
     21   int buf[10];
     22 
     23   SmallPtrSet<int *, 2> a;
     24   SmallPtrSet<int *, 2> b;
     25 
     26   a.insert(&buf[0]);
     27   a.insert(&buf[1]);
     28   b.insert(&buf[2]);
     29 
     30   std::swap(a, b);
     31 
     32   EXPECT_EQ(1U, a.size());
     33   EXPECT_EQ(2U, b.size());
     34   EXPECT_TRUE(a.count(&buf[2]));
     35   EXPECT_TRUE(b.count(&buf[0]));
     36   EXPECT_TRUE(b.count(&buf[1]));
     37 
     38   b.insert(&buf[3]);
     39   std::swap(a, b);
     40 
     41   EXPECT_EQ(3U, a.size());
     42   EXPECT_EQ(1U, b.size());
     43   EXPECT_TRUE(a.count(&buf[0]));
     44   EXPECT_TRUE(a.count(&buf[1]));
     45   EXPECT_TRUE(a.count(&buf[3]));
     46   EXPECT_TRUE(b.count(&buf[2]));
     47 
     48   std::swap(a, b);
     49 
     50   EXPECT_EQ(1U, a.size());
     51   EXPECT_EQ(3U, b.size());
     52   EXPECT_TRUE(a.count(&buf[2]));
     53   EXPECT_TRUE(b.count(&buf[0]));
     54   EXPECT_TRUE(b.count(&buf[1]));
     55   EXPECT_TRUE(b.count(&buf[3]));
     56 
     57   a.insert(&buf[4]);
     58   a.insert(&buf[5]);
     59   a.insert(&buf[6]);
     60 
     61   std::swap(b, a);
     62 
     63   EXPECT_EQ(3U, a.size());
     64   EXPECT_EQ(4U, b.size());
     65   EXPECT_TRUE(b.count(&buf[2]));
     66   EXPECT_TRUE(b.count(&buf[4]));
     67   EXPECT_TRUE(b.count(&buf[5]));
     68   EXPECT_TRUE(b.count(&buf[6]));
     69   EXPECT_TRUE(a.count(&buf[0]));
     70   EXPECT_TRUE(a.count(&buf[1]));
     71   EXPECT_TRUE(a.count(&buf[3]));
     72 }
     73