-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
56 lines (40 loc) · 1.35 KB
/
test.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
#include <iostream>
#include "disjoint_set.hpp"
namespace DisjointSetTests {
auto disjoint_set_init_test() {
constexpr auto disjoint_set_size = 100;
auto a = DisjointSet<disjoint_set_size>();
if (a.get_size() != disjoint_set_size) return false;
for (auto i = 0; i < disjoint_set_size; i++) {
auto set = a.find(i);
if (set != i) {
return false;
}
}
return true;
}
auto disjoint_set_union_test() {
constexpr auto disjoint_set_size = 100;
auto a = DisjointSet<disjoint_set_size>();
if (a.are_same_set(1, 0)) return false;
a.unify(0, 1);
if (!a.are_same_set(1, 0)) return false;
if (a.are_same_set(1, 2)) return false;
a.unify(1, 2);
if (!a.are_same_set(1, 2)) return false;
if (!a.are_same_set(0, 2)) return false;
a.unify(50, 2);
if (!a.are_same_set(1, 2)) return false;
if (!a.are_same_set(0, 2)) return false;
if (!a.are_same_set(0, 50)) return false;
return true;
}
auto run() {
std::cout << "disjoint_set_init_test: " << (disjoint_set_init_test() ? "PASS ✅" : "FAIL ❌") << '\n';
std::cout << "disjoint_set_union_test: " << (disjoint_set_union_test() ? "PASS ✅" : "FAIL ❌") << '\n';
}
} // namespace DisjointSetTests
int main() {
DisjointSetTests::run();
return 0;
}