summaryrefslogtreecommitdiff
path: root/datastructures/test/treap2.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-06-07 18:35:50 +0200
committerGloria Mundi <gloria@gloria-mundi.eu>2024-06-07 18:35:50 +0200
commitfd79fe020011ed552d8763339434458e9f1f10b6 (patch)
tree2a77ed7e46db6f6192bd53b2ae60ab4ab4989968 /datastructures/test/treap2.cpp
parent98141975f919f60b37d1cd54bb662afc9fa3fb20 (diff)
yeah maybe I should actually commit the test code
Diffstat (limited to 'datastructures/test/treap2.cpp')
-rw-r--r--datastructures/test/treap2.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/datastructures/test/treap2.cpp b/datastructures/test/treap2.cpp
new file mode 100644
index 0000000..1a435d3
--- /dev/null
+++ b/datastructures/test/treap2.cpp
@@ -0,0 +1,41 @@
+#include "../treap2.cpp"
+
+void test(int n) {
+ Treap treap;
+ vector<ll> dumb;
+ for (int i = 0; i < n; i++) {
+ assert(treap.getSize(treap.root) == ssize(dumb));
+ int j = util::randint(ssize(dumb) + 1);
+ ll x = util::randint();
+ treap.insert(j, x);
+ dumb.insert(begin(dumb) + j, x);
+ }
+ for (int i = 0; i < 5*n; i++) {
+ assert(treap.getSize(treap.root) == ssize(dumb));
+ {
+ int j = util::randint(ssize(dumb));
+ treap.remove(j);
+ dumb.erase(begin(dumb) + j);
+ }
+ {
+ int j = util::randint(ssize(dumb) + 1);
+ ll x = util::randint();
+ treap.insert(j, x);
+ dumb.insert(begin(dumb) + j, x);
+ }
+ }
+ for (int i = 0; i < n; i++) {
+ assert(treap.getSize(treap.root) == ssize(dumb));
+ int j = util::randint(ssize(dumb));
+ treap.remove(j);
+ dumb.erase(begin(dumb) + j);
+ }
+ assert(treap.root < 0);
+ assert(empty(dumb));
+}
+
+int main() {
+ test(1000);
+ test(1);
+ test(0);
+}