From 2d09c91b8e3a4482ed94fab44ec1aab42ab72da9 Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sun, 28 Apr 2024 19:44:14 +0200 Subject: remove all() and sz() from segment tree and add tests --- datastructures/test/segmentTree.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 datastructures/test/segmentTree.cpp (limited to 'datastructures/test/segmentTree.cpp') 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 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); +} -- cgit v1.2.3