-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_2pset.cpp
65 lines (49 loc) · 2.15 KB
/
test_2pset.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "2pset.h"
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
TwoPhaseSet<int> first, second, third;
TwoPhaseSet<int> joined, op_joined, rejoined;
first.insert(5);
first.insert(10);
first.insert(15);
bool in = first.in(5) && first.in(10) && first.in(15);
std::cout << "insert test: " << (in ? "passed" : "failed") << std::endl;
first.insert(10);
first.remove(15);
bool rm = first.in(5) && first.in(10) && !first.in(15);
std::cout << "remove test: " << (rm ? "passed" : "failed") << std::endl;
second.insert(15); // cannot be re-added when joinning
second.insert(20);
third.insert(25);
third.insert(30);
std::vector<int> expected({5, 10, 20, 25, 30});
joined.join(first, second, third);
bool j = std::is_permutation(expected.begin(), expected.end(),
joined.elements().begin());
std::cout << "join test: " << (j ? "passed" : "failed") << std::endl;
op_joined = first + second + third;
bool add = std::is_permutation(expected.begin(), expected.end(),
op_joined.elements().begin());
std::cout << "union test: " << (add ? "passed" : "failed") << std::endl;
std::vector<TwoPhaseSet<int>> joinable_sets({first, second, third});
joined.join(joinable_sets);
bool rj = std::is_permutation(expected.begin(), expected.end(),
joined.elements().begin());
std::cout << "rejoin test: " << (rj ? "passed" : "failed") << std::endl;
auto joinable_sets2 = joined.split();
rejoined.join(joinable_sets2);
std::clog << "joined: " << joined << '\n'
<< "rejoined: " << rejoined << std::endl;
std::cout << "equality test: " << (joined == rejoined ? "passed" : "failed")
<< std::endl;
auto first_and_second = rejoined - third;
bool s = (first_and_second + third) == rejoined;
std::clog << "first and second: " << first_and_second << std::endl;
std::cout << "split test: " << (s ? "passed" : "failed") << std::endl;
auto none = first_and_second - first - second;
bool empty = none.elements().empty();
std::cout << "empty test: " << (empty ? "passed" : "failed") << std::endl;
return 0;
}