diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2024-08-04 15:58:47 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2024-08-04 15:58:47 +0200 |
| commit | 1ad495344f764e979e93f394f76716cf527c2940 (patch) | |
| tree | d5810ece067e94123fd0ffa5659e752755da2616 /test | |
| parent | e46ead1681b24c75624c33f167c530e633e40440 (diff) | |
more tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/datastructures/lichao.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/datastructures/lichao.cpp b/test/datastructures/lichao.cpp new file mode 100644 index 0000000..acd048f --- /dev/null +++ b/test/datastructures/lichao.cpp @@ -0,0 +1,73 @@ +#include "../util.h" +constexpr ll inf = LL::INF; +#include <datastructures/lichao.cpp> + +void stress_test() { + ll queries = 0; + for (int tries = 0; tries < 1000; tries++) { + int n = Random::integer<int>(1, 100); + xs = Random::distinct<ll>(n, -1000, 1000); + sort(all(xs)); + + vector<ll> naive(n, inf); + Lichao tree; + + for (int operations = 0; operations < 1000; operations++) { + { + ll m = Random::integer<ll>(-100, 100); + ll c = Random::integer<ll>(-1000, 1000); + ll l = Random::integer<ll>(-1000, 1000); + ll r = Random::integer<ll>(-1000, 1000); + Fun f{m, c}; + + tree.segmentInsert(f, l, r); + for (int i = 0; i < n; i++) { + if (l <= xs[i] && xs[i] < r) naive[i] = min(naive[i], f(i)); + } + } + { + queries++; + int i = Random::integer<int>(0, n); + ll got = tree.query(xs[i]); + ll expected = naive[i]; + if (got != expected) cerr << xs[i] << endl; + if (got != expected) cerr << " got: " << got << ", expected: " << expected << FAIL; + } + } + } + cerr << " tested random queries: " << queries << endl; +} + +constexpr int N = 200'000; +void performance_test() { + timer t; + xs = Random::distinct<ll>(N, -1'000'000'000, 1'000'000'000); + sort(all(xs)); + + t.start(); + Lichao tree; + t.stop(); + + hash_t hash = 0; + for (int operations = 0; operations < N; operations++) { + + ll m = Random::integer<ll>(-1'000'000, 1'000'000); + ll c = Random::integer<ll>(-1'000'000, 1'000'000); + ll l = Random::integer<ll>(-1'000'000'000, 1'000'000'000); + ll r = Random::integer<ll>(-1'000'000'000, 1'000'000'000); + ll x = xs[Random::integer<int>(N)]; + Fun f{m, c}; + + t.start(); + tree.segmentInsert(f, l, r); + hash ^= tree.query(x); + t.stop(); + } + if (t.time > 1000) cerr << " too slow: " << t.time << FAIL; + cerr << " tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; +} + +int main() { + stress_test(); + performance_test(); +} |
