Skip to content

Commit 4c64c2e

Browse files
Chilleesimonlindholm
authored andcommitted
Standardized tests for data structures (#84)
1 parent 80932ba commit 4c64c2e

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

fuzz-tests/data-structures/FenwickTree2d.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ int main() {
4141
}
4242
}
4343
}
44+
cout<<"Tests passed!"<<endl;
4445
}

fuzz-tests/data-structures/LazySegmentTree.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ typedef pair<int, int> pii;
1111
typedef vector<int> vi;
1212

1313
#include "../../content/data-structures/LazySegmentTree.h"
14-
// #include "../../content/data-structures/old.h"
1514

1615
static unsigned R;
1716
int ra() {
@@ -53,5 +52,5 @@ int main() {
5352
rep(k,i,j) v[k] = x;
5453
}
5554
}
56-
exit(0);
55+
cout<<"Tests passed"<<endl;
5756
}

fuzz-tests/data-structures/LineContainer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct HullDynamic : public multiset<Line> { // will maintain upper hull for max
5151
};
5252
}
5353

54-
int main2() {
54+
int test2() {
5555
LineContainer mh;
5656
const int K = 10;
5757
ll x[K], v[K];
@@ -102,4 +102,6 @@ int main() {
102102
assert(mh.query(x) == mh2.query(x));
103103
}
104104
}
105+
test2();
106+
cout<<"Tests passed!"<<endl;
105107
}

fuzz-tests/data-structures/LinkCutTree.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,38 @@ typedef vector<int> vi;
1414
#include "../../content/data-structures/UnionFind.h"
1515

1616
int main() {
17-
int s = (int)time(0);
18-
cout << s << endl;
19-
srand(s);
20-
for (;;) {
17+
srand(2);
18+
LinkCut lczero(0);
19+
rep(it,0,10000) {
2120
int N = rand() % 20 + 1;
22-
rep(it,0,1000) {
23-
LinkCut lc(N);
24-
UF uf(N);
25-
vector<pii> edges;
26-
rep(it2,0,1000) {
27-
int v = (rand() >> 4) & 3;
28-
if (v == 0 && !edges.empty()) { // remove
29-
int r = (rand() >> 4) % sz(edges);
30-
pii ed = edges[r];
31-
swap(edges[r], edges.back());
32-
edges.pop_back();
33-
if (rand() & 16)
34-
lc.cut(ed.first, ed.second);
35-
else
36-
lc.cut(ed.second, ed.first);
21+
LinkCut lc(N);
22+
UF uf(N);
23+
vector<pii> edges;
24+
rep(it2,0,1000) {
25+
int v = (rand() >> 4) & 3;
26+
if (v == 0 && !edges.empty()) { // remove
27+
int r = (rand() >> 4) % sz(edges);
28+
pii ed = edges[r];
29+
swap(edges[r], edges.back());
30+
edges.pop_back();
31+
if (rand() & 16)
32+
lc.cut(ed.first, ed.second);
33+
else
34+
lc.cut(ed.second, ed.first);
35+
} else {
36+
int a = (rand() >> 4) % N;
37+
int b = (rand() >> 4) % N;
38+
uf.e.assign(N, -1);
39+
trav(ed, edges) uf.join(ed.first, ed.second);
40+
bool c = uf.same_set(a, b);
41+
if (!c && v != 1) {
42+
lc.link(a, b);
43+
edges.emplace_back(a, b);
3744
} else {
38-
int a = (rand() >> 4) % N;
39-
int b = (rand() >> 4) % N;
40-
uf.e.assign(N, -1);
41-
trav(ed, edges) uf.join(ed.first, ed.second);
42-
bool c = uf.same_set(a, b);
43-
if (!c && v != 1) {
44-
lc.link(a, b);
45-
edges.emplace_back(a, b);
46-
} else {
47-
assert(lc.connected(a, b) == c);
48-
}
45+
assert(lc.connected(a, b) == c);
4946
}
5047
}
5148
}
52-
clog << '.';
5349
}
50+
cout<<"Tests passed!"<<endl;
5451
}

fuzz-tests/data-structures/RMQ.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ int main() {
2525
assert(n == m);
2626
}
2727
}
28+
cout<<"Tests passed!"<<endl;
2829
}

fuzz-tests/data-structures/SegmentTree.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,5 @@ int main() {
120120
}
121121
}
122122
}
123-
124-
exit(0);
123+
cout<<"Tests passed!"<<endl;
125124
}

fuzz-tests/data-structures/Treap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ int main() {
8383
});
8484
// cerr << endl;
8585
}
86+
cout<<"Tests passed!"<<endl;
8687
}

0 commit comments

Comments
 (0)