-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dsu.cpp
More file actions
29 lines (24 loc) · 739 Bytes
/
test_dsu.cpp
File metadata and controls
29 lines (24 loc) · 739 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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "dsu.h"
#include <algorithm>
#include "doctest.h"
#include <random>
#include <vector>
using namespace std;
TEST_CASE("Connectivity") {
mt19937 rng(69420);
for (int sz = 10; sz <= 100; sz++) {
vector<int> permutation(sz);
for (int i = 0; i < sz; i++)
permutation[i] = i;
shuffle(permutation.begin(), permutation.end(), rng);
dsu ds(sz);
for (int i = 0; i < sz; i++) {
int l = uniform_int_distribution<int>(0, sz-1)(rng);
int r = uniform_int_distribution<int>(0, sz-1)(rng);
if (l > r) swap(l, r);
ds.merge(l, r);
CHECK(ds.find(l) == ds.find(r));
}
}
}