-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pathcopy.cpp
More file actions
86 lines (76 loc) · 2.48 KB
/
test_pathcopy.cpp
File metadata and controls
86 lines (76 loc) · 2.48 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "pathcopy.h"
#include <algorithm>
#include "doctest.h"
#include <iostream>
#include <random>
#include <set>
#include <vector>
using namespace std;
TEST_CASE("Insertions") {
mt19937 rng(69420);
for (int sz = 10; sz <= 100; sz++) {
vector<int> array(sz);
for (int i = 0; i < sz; i++) array[i] = i;
shuffle(array.begin(), array.end(), rng);
auto copy = [](set<int> &a, set<int> &b) {
for (auto el : b) a.insert(el);
};
set<int> cur;
treap<int> tree;
vector<set<int>> sets(sz);
for (int i = 0; i < sz; i++) {
cur.insert(array[i]);
tree.insert(array[i]);
copy(sets[i], cur);
}
for (int i = 0; i < sz; i++) {
int t = uniform_int_distribution<int>(0, sz-1)(rng);
int x = uniform_int_distribution<int>(0, sz-1)(rng);
if (tree.count(t, x) != sets[t].count(x)) {
printf("T: %d | X: %d\n", t, x);
tree.print(t);
for (auto el : sets[t]) printf("%d ", el);
printf("\n");
assert(false);
}
}
}
}
TEST_CASE("Insertions && Deletions ") {
mt19937 rng(69420);
for (int sz = 10; sz <= 100; sz++) {
vector<int> array(2*sz);
for (int i = 0; i < sz; i++) array[i] = i;
for (int i = 0; i < sz; i++) array[sz+i] = i;
shuffle(array.begin(), array.end(), rng);
auto copy = [](set<int> &a, set<int> &b) {
for (auto el : b) a.insert(el);
};
set<int> cur;
treap<int> tree;
vector<set<int>> sets(2*sz);
for (int i = 0; i < 2*sz; i++) {
if (!cur.count(array[i])) {
cur.insert(array[i]);
tree.insert(array[i]);
copy(sets[i], cur);
} else {
cur.erase(array[i]);
tree.erase(array[i]);
copy(sets[i], cur);
}
}
for (int i = 0; i < 2*sz; i++) {
int t = uniform_int_distribution<int>(0, 2*sz-1)(rng);
int x = uniform_int_distribution<int>(0, sz-1)(rng);
if (tree.count(t, x) != sets[t].count(x)) {
printf("T: %d | X: %d\n", t, x);
tree.print(t);
for (auto el : sets[t]) printf("%d ", el);
printf("\n");
assert(false);
}
}
}
}