Skip to content

Commit 885a6a5

Browse files
committed
fixup! [ADT] Add more useful methods to SmallSet API
1 parent f0dd57a commit 885a6a5

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

llvm/include/llvm/ADT/SmallSet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ class SmallSet {
152152
SmallSet(SmallSet &&) = default;
153153

154154
template <typename IterT> SmallSet(IterT Begin, IterT End) {
155-
this->insert(Begin, End);
155+
insert(Begin, End);
156156
}
157157

158158
template <typename RangeT>
159159
explicit SmallSet(const iterator_range<RangeT> &R) {
160-
this->insert(R.begin(), R.end());
160+
insert(R.begin(), R.end());
161161
}
162162

163163
SmallSet(std::initializer_list<T> L) { this->insert(L.begin(), L.end()); }

llvm/unittests/ADT/SmallSetTest.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,61 @@
1212

1313
#include "llvm/ADT/SmallSet.h"
1414
#include "llvm/ADT/STLExtras.h"
15+
#include "gmock/gmock.h"
1516
#include "gtest/gtest.h"
1617
#include <string>
1718

1819
using namespace llvm;
1920

2021
TEST(SmallSetTest, ConstructorIteratorPair) {
21-
auto L = {1, 2, 3, 4, 5};
22+
std::initializer_list<int> L = {1, 2, 3, 4, 5};
2223
SmallSet<int, 4> S(std::begin(L), std::end(L));
23-
for (int Value : L)
24-
EXPECT_TRUE(S.contains(Value));
24+
EXPECT_THAT(S, testing::UnorderedElementsAreArray(L));
2525
}
2626

2727
TEST(SmallSet, ConstructorRange) {
28-
auto L = {1, 2, 3, 4, 5};
28+
std::initializer_list<int> L = {1, 2, 3, 4, 5};
2929

3030
SmallSet<int, 4> S(llvm::make_range(std::begin(L), std::end(L)));
31-
for (int Value : L)
32-
EXPECT_TRUE(S.contains(Value));
31+
EXPECT_THAT(S, testing::UnorderedElementsAreArray(L));
3332
}
3433

3534
TEST(SmallSet, ConstructorInitializerList) {
36-
auto L = {1, 2, 3, 4, 5};
35+
std::initializer_list<int> L = {1, 2, 3, 4, 5};
3736
SmallSet<int, 4> S = {1, 2, 3, 4, 5};
38-
for (int Value : L)
39-
EXPECT_TRUE(S.contains(Value));
37+
EXPECT_THAT(S, testing::UnorderedElementsAreArray(L));
4038
}
4139

4240
TEST(SmallSet, CopyConstructor) {
4341
SmallSet<int, 4> S = {1, 2, 3};
4442
SmallSet<int, 4> T = S;
4543

46-
EXPECT_EQ(S, T);
44+
EXPECT_THAT(S, testing::ContainerEq(T));
4745
}
4846

4947
TEST(SmallSet, MoveConstructor) {
50-
auto L = {1, 2, 3};
48+
std::initializer_list<int> L = {1, 2, 3};
5149
SmallSet<int, 4> S = L;
5250
SmallSet<int, 4> T = std::move(S);
5351

54-
EXPECT_TRUE(T.size() == L.size());
55-
for (int Value : L) {
56-
EXPECT_TRUE(T.contains(Value));
57-
}
52+
EXPECT_THAT(T, testing::UnorderedElementsAreArray(L));
5853
}
5954

6055
TEST(SmallSet, CopyAssignment) {
6156
SmallSet<int, 4> S = {1, 2, 3};
6257
SmallSet<int, 4> T;
6358
T = S;
6459

65-
EXPECT_EQ(S, T);
60+
EXPECT_THAT(S, testing::ContainerEq(T));
6661
}
6762

6863
TEST(SmallSet, MoveAssignment) {
69-
auto L = {1, 2, 3};
64+
std::initializer_list<int> L = {1, 2, 3};
7065
SmallSet<int, 4> S = L;
7166
SmallSet<int, 4> T;
7267
T = std::move(S);
7368

74-
EXPECT_TRUE(T.size() == L.size());
75-
for (int Value : L) {
76-
EXPECT_TRUE(T.contains(Value));
77-
}
69+
EXPECT_THAT(T, testing::UnorderedElementsAreArray(L));
7870
}
7971

8072
TEST(SmallSetTest, Insert) {

0 commit comments

Comments
 (0)