summaryrefslogtreecommitdiff
path: root/datastructures/test
diff options
context:
space:
mode:
Diffstat (limited to 'datastructures/test')
-rw-r--r--datastructures/test/segmentTree.cpp30
-rw-r--r--datastructures/test/segmentTree2.cpp26
2 files changed, 56 insertions, 0 deletions
diff --git a/datastructures/test/segmentTree.cpp b/datastructures/test/segmentTree.cpp
new file mode 100644
index 0000000..79c16e6
--- /dev/null
+++ b/datastructures/test/segmentTree.cpp
@@ -0,0 +1,30 @@
+#include "segmentTree.tmp.cpp"
+
+void test(int n) {
+ vector<ll> a(n);
+ for (ll &x: a) x = util::randint();
+ SegTree seg(a);
+ for (int i = 0; i < 5*n; i++) {
+ {
+ int j = util::randint(n);
+ ll v = util::randint();
+ a[j] = v;
+ seg.update(j, v);
+ }
+ {
+ int l = util::randint(n+1);
+ int r = util::randint(n+1);
+ if (l > r) swap(l, r);
+ assert(
+ seg.query(l, r)
+ ==
+ accumulate(a.begin() + l, a.begin() + r, 0ll)
+ );
+ }
+ }
+}
+
+int main() {
+ test(1000);
+ test(1);
+}
diff --git a/datastructures/test/segmentTree2.cpp b/datastructures/test/segmentTree2.cpp
new file mode 100644
index 0000000..f403a1d
--- /dev/null
+++ b/datastructures/test/segmentTree2.cpp
@@ -0,0 +1,26 @@
+#include "segmentTree2.tmp.cpp"
+
+void test(int n) {
+ vector<ll> a(n);
+ for (ll &x: a) x = util::randint();
+ SegTree seg(a);
+ for (int i = 0; i < 5*n; i++) {
+ {
+ int l = util::randint(n+1);
+ int r = util::randint(n+1);
+ if (l > r) swap(l, r);
+ ll v = util::randint();
+ for (int i = l; i < r; i++) a[i] += v;
+ seg.modify(l, r, v);
+ }
+ {
+ int j = util::randint(n);
+ assert(seg.query(j) == a[j]);
+ }
+ }
+}
+
+int main() {
+ test(1000);
+ test(1);
+}