summaryrefslogtreecommitdiff
path: root/test/datastructures/sparseTableDisjoint.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 01:24:14 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 01:24:14 +0100
commit98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch)
tree5113d5cc24d1ad5f93810b6442ce584a36950dc8 /test/datastructures/sparseTableDisjoint.cpp
parentad3856a6b766087df0036de0b556f4700a6498c9 (diff)
parent8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff)
mzuenni tests
Diffstat (limited to 'test/datastructures/sparseTableDisjoint.cpp')
-rw-r--r--test/datastructures/sparseTableDisjoint.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/datastructures/sparseTableDisjoint.cpp b/test/datastructures/sparseTableDisjoint.cpp
new file mode 100644
index 0000000..258f4db
--- /dev/null
+++ b/test/datastructures/sparseTableDisjoint.cpp
@@ -0,0 +1,48 @@
+#include "../util.h"
+#include <datastructures/sparseTableDisjoint.cpp>
+
+void stress_test() {
+ ll queries = 0;
+ for (int tries = 0; tries < 1000; tries++) {
+ int n = Random::integer<int>(1, 100);
+ vector<ll> naive = Random::integers<ll>(n, -1000, 1000);
+ DisjointST st;
+ st.init(naive);
+ for (int operations = 0; operations < 1000; operations++) {
+ queries++;
+ int l = Random::integer<int>(0, n+1);
+ int r = Random::integer<int>(0, n+1);
+
+ ll got = st.query(l, r);
+ ll expected = 0;
+ for (int j = l; j < r; j++) expected += naive[j];
+ if (got != expected) cerr << "got: " << got << ", expected: " << expected << FAIL;
+ }
+ }
+ cerr << "tested random queries: " << queries << endl;
+}
+
+constexpr int N = 1'250'000;
+void performance_test() {
+ timer t;
+ vector<ll> naive = Random::integers<ll>(N, -1000, 1000);
+ t.start();
+ DisjointST st;
+ st.init(naive);
+ t.stop();
+ hash_t hash = 0;
+ for (int operations = 0; operations < N; operations++) {
+ auto [l, r] = Random::pair<int>(0, N+1);
+
+ t.start();
+ hash += st.query(l, r);
+ t.stop();
+ }
+ if (t.time > 500) cerr << "too slow: " << t.time << FAIL;
+ cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
+}
+
+int main() {
+ stress_test();
+ performance_test();
+}