-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_set.cpp
More file actions
40 lines (29 loc) · 750 Bytes
/
test_set.cpp
File metadata and controls
40 lines (29 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "common.h"
TEST(Set, Difference)
{
using Strs = vector<string>;
Strs s1 = {"leech1", "leech2", "leech3" },
s2 = {"leech1" },
s3;
set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
back_inserter(s3));
ASSERT_THAT(s3, Eq(vector<string>{"leech2", "leech3"}));
ASSERT_THAT(s3, ElementsAre("leech2", "leech3"));
}
TEST(Set, RemoveDuplicate)
{
struct data
{
string name;
int age;
bool operator<(data const& rhs) const { return name < rhs.name; }
};
set<data> s;
data a0{"leech", 39}, a1{"kamin", 37}, a2{"kamin", 39};
s.insert(a0);
s.insert(a1);
s.insert(a2);
vector<string> v;
for (auto e:s) v.push_back(e.name);
ASSERT_THAT(v, ElementsAre("kamin", "leech"));
}