Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / ADT / SetVectorTest.cpp
bloba0114c0e3509c06c64ce82e48f5a12c5f48fb805
1 //===- llvm/unittest/ADT/SetVector.cpp ------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // SetVector unit tests.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 TEST(SetVector, EraseTest) {
20 SetVector<int> S;
21 S.insert(0);
22 S.insert(1);
23 S.insert(2);
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) {
36 SetVector<int> S;
37 S.insert(0);
38 S.insert(1);
39 S.insert(2);
41 EXPECT_TRUE(S.contains(0));
42 EXPECT_TRUE(S.contains(1));
43 EXPECT_TRUE(S.contains(2));
44 EXPECT_FALSE(S.contains(-1));
46 S.insert(2);
47 EXPECT_TRUE(S.contains(2));
49 S.remove(2);
50 EXPECT_FALSE(S.contains(2));
53 TEST(SetVector, ConstPtrKeyTest) {
54 SetVector<int *, SmallVector<int *, 8>, SmallPtrSet<const int *, 8>> S, T;
55 int i, j, k, m, n;
57 S.insert(&i);
58 S.insert(&j);
59 S.insert(&k);
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]));
73 S.remove(&k);
74 EXPECT_FALSE(S.contains(&k));
75 EXPECT_FALSE(S.contains((const int *)&k));
77 T.insert(&j);
78 T.insert(&m);
79 T.insert(&n);
81 EXPECT_TRUE(S.set_union(T));
82 EXPECT_TRUE(S.contains(&m));
83 EXPECT_TRUE(S.contains((const int *)&m));
85 S.set_subtract(T);
86 EXPECT_FALSE(S.contains(&j));
87 EXPECT_FALSE(S.contains((const int *)&j));