summaryrefslogtreecommitdiff
path: root/test/datastructures/persistentArray.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
commit72bd993483453ed8ebc462f1a33385cd355d486f (patch)
treec5592ba1ed2fed79e26ba6158d097c9ceb43f061 /test/datastructures/persistentArray.cpp
parent98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (diff)
parent35d485bcf6a9ed0a9542628ce4aa94a3326d0884 (diff)
merge mzuenni changes
Diffstat (limited to 'test/datastructures/persistentArray.cpp')
-rw-r--r--test/datastructures/persistentArray.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/datastructures/persistentArray.cpp b/test/datastructures/persistentArray.cpp
new file mode 100644
index 0000000..6712089
--- /dev/null
+++ b/test/datastructures/persistentArray.cpp
@@ -0,0 +1,48 @@
+#include "../util.h"
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <datastructures/persistent.cpp>
+#include <datastructures/persistentArray.cpp>
+
+void stress_test() {
+ ll queries = 0;
+ for (int tries = 0; tries < 2'000; tries++) {
+ int n = Random::integer<int>(1, 30)*1000;
+ int m = Random::integer<int>(1, 30);
+
+ persistentArray<double> got(m);
+ vector<double> cur(m);
+ vector<pair<int, vector<double>>> expected;
+ for (int i = 0; i < n; i++) {
+ int op = Random::integer<int>(0, 20);
+ if (op <= 10) {
+ int j = Random::integer<int>(0, m);
+ double x = Random::real<double>(-1'000, 1'000);
+
+ auto t = got.set(j, x);
+ if (!expected.empty() && t <= expected.rbegin()->first) cerr << "error: time travel" << FAIL;
+
+ cur[j] = x;
+ expected.emplace_back(t, cur);
+ } else if (op <= 16) {
+ if (sz(expected) < 1) continue;
+ int j = Random::integer<int>(0, sz(expected));
+ for (int k = 0; k < m; k++) {
+ if (got.get(k, expected[j].first) != expected[j].second[k]) cerr << "got: " << got.get(k, expected[j].first) << ", expected: " << expected[j].second[k] << FAIL;
+ }
+ } else {
+ if (sz(expected) < 1) continue;
+ int j = Random::integer<int>(0, sz(expected));
+ got.reset(expected[j].first);
+ expected.resize(j + 1);
+ cur = expected.back().second;
+ }
+
+ }
+ queries += n;
+ }
+ cerr << "tested random queries: " << queries << endl;
+}
+
+int main() {
+ stress_test();
+}