1 //===- llvm/unittest/ADT/SetVector.cpp ------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // SetVector unit tests.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "gtest/gtest.h"
19 TEST(SetVector
, EraseTest
) {
25 auto I
= S
.erase(std::next(S
.begin()));
27 // Test that the returned iterator is the expected one-after-erase
28 // and the size/contents is the expected sequence {0, 2}.
29 EXPECT_EQ(std::next(S
.begin()), I
);
30 EXPECT_EQ(2u, S
.size());
31 EXPECT_EQ(0, *S
.begin());
32 EXPECT_EQ(2, *std::next(S
.begin()));
35 TEST(SetVector
, ContainsTest
) {
41 EXPECT_TRUE(S
.contains(0));
42 EXPECT_TRUE(S
.contains(1));
43 EXPECT_TRUE(S
.contains(2));
44 EXPECT_FALSE(S
.contains(-1));
47 EXPECT_TRUE(S
.contains(2));
50 EXPECT_FALSE(S
.contains(2));
53 TEST(SetVector
, ConstPtrKeyTest
) {
54 SetVector
<int *, SmallVector
<int *, 8>, SmallPtrSet
<const int *, 8>> S
, T
;
61 EXPECT_TRUE(S
.contains(&i
));
62 EXPECT_TRUE(S
.contains(&j
));
63 EXPECT_TRUE(S
.contains(&k
));
65 EXPECT_TRUE(S
.contains((const int *)&i
));
66 EXPECT_TRUE(S
.contains((const int *)&j
));
67 EXPECT_TRUE(S
.contains((const int *)&k
));
69 EXPECT_TRUE(S
.contains(S
[0]));
70 EXPECT_TRUE(S
.contains(S
[1]));
71 EXPECT_TRUE(S
.contains(S
[2]));
74 EXPECT_FALSE(S
.contains(&k
));
75 EXPECT_FALSE(S
.contains((const int *)&k
));
81 EXPECT_TRUE(S
.set_union(T
));
82 EXPECT_TRUE(S
.contains(&m
));
83 EXPECT_TRUE(S
.contains((const int *)&m
));
86 EXPECT_FALSE(S
.contains(&j
));
87 EXPECT_FALSE(S
.contains((const int *)&j
));