| 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. |
| 10 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 13 |
#include "llvm/ADT/SetVector.h" |
| 14 |
#include "gtest/gtest.h" |
| 15 |
|
| 16 |
using namespace llvm; |
| 17 |
|
| 18 |
TEST(SetVector, EraseTest) { |
| 19 |
SetVector<int> S; |
| 20 |
S.insert(0); |
| 21 |
S.insert(1); |
| 22 |
S.insert(2); |
| 23 |
|
| 24 |
auto I = S.erase(std::next(S.begin())); |
| 25 |
|
| 26 |
// Test that the returned iterator is the expected one-after-erase |
| 27 |
// and the size/contents is the expected sequence {0, 2}. |
| 28 |
EXPECT_EQ(std::next(S.begin()), I); |
| 29 |
EXPECT_EQ(2u, S.size()); |
| 30 |
EXPECT_EQ(0, *S.begin()); |
| 31 |
EXPECT_EQ(2, *std::next(S.begin())); |
| 32 |
} |
| 33 |
|
| 34 |
TEST(SetVector, ContainsTest) { |
| 35 |
SetVector<int> S; |
| 36 |
S.insert(0); |
| 37 |
S.insert(1); |
| 38 |
S.insert(2); |
| 39 |
|
| 40 |
EXPECT_TRUE(S.contains(0)); |
| 41 |
EXPECT_TRUE(S.contains(1)); |
| 42 |
EXPECT_TRUE(S.contains(2)); |
| 43 |
EXPECT_FALSE(S.contains(-1)); |
| 44 |
|
| 45 |
S.insert(2); |
| 46 |
EXPECT_TRUE(S.contains(2)); |
| 47 |
|
| 48 |
S.remove(2); |
| 49 |
EXPECT_FALSE(S.contains(2)); |
| 50 |
} |