summaryrefslogtreecommitdiff
path: root/test/datastructures/persistent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/datastructures/persistent.cpp')
-rw-r--r--test/datastructures/persistent.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/datastructures/persistent.cpp b/test/datastructures/persistent.cpp
new file mode 100644
index 0000000..4e304fa
--- /dev/null
+++ b/test/datastructures/persistent.cpp
@@ -0,0 +1,35 @@
+#include "../util.h"
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <datastructures/persistent.cpp>
+
+void stress_test() {
+ ll queries = 0;
+ for (int tries = 0; tries < 100'000; tries++) {
+ int n = Random::integer<int>(1, 30);
+
+ int timeRef = Random::integer<int>(1, 30);
+ persistent<double> got(timeRef);
+ map<int, double> expected;
+
+ for (int i = 0; i < n; i++) {
+ timeRef += Random::integer<int>(1, 30);
+ double x = Random::real<double>(-1'000, 1'000);
+ auto t = got.set(x);
+
+ if (!expected.empty() && t <= expected.rbegin()->first) cerr << "error: time travel" << FAIL;
+ expected[t] = x;
+ }
+
+ double tmp = 0;
+ for (int i = expected.begin()->first; i < expected.rbegin()->first + 10; i++) {
+ if (expected.find(i) != expected.end()) tmp = expected[i];
+ if (got.get(i) != tmp) cerr << "got: " << got.get(i) << ", " << "expected: " << tmp << FAIL;
+ }
+ queries += n;
+ }
+ cerr << "tested random queries: " << queries << endl;
+}
+
+int main() {
+ stress_test();
+}