From 55b0c65814beaac0e68b9c2b99bf42f9327ec61a Mon Sep 17 00:00:00 2001 From: mzuenni Date: Sat, 17 Aug 2024 16:05:00 +0200 Subject: further tests --- test/datastructures/monotonicConvexHull.cpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test') diff --git a/test/datastructures/monotonicConvexHull.cpp b/test/datastructures/monotonicConvexHull.cpp index 4dafbd4..9edfb4b 100644 --- a/test/datastructures/monotonicConvexHull.cpp +++ b/test/datastructures/monotonicConvexHull.cpp @@ -42,6 +42,38 @@ void stress_test(ll range) { cerr << "tested random queries: " << queries << endl; } +void stress_test_independent(ll range) { + ll queries = 0; + for (int tries = 0; tries < 1000; tries++) { + int n = Random::integer(1, 100); + auto ms = Random::distinct(n, -range, range); + sort(all(ms), greater<>{}); + + vector naive; + + MCH mch; + for (ll m : ms) { + ll c = Random::integer(-range, range); + mch.add(m, c); + naive.emplace_back(m, c); + + auto xs = Random::distinct(100, -range, range); + sort(all(xs)); + auto tmp = mch; + + for (auto x : xs) { + ll got = tmp.query(x); + ll expected = naive[0](x); + for (auto l : naive) expected = min(expected, l(x)); + + if (got != expected) cerr << "got: " << got << ", expected: " << expected << FAIL; + queries++; + } + } + } + cerr << "tested random independent queries: " << queries << endl; +} + constexpr int N = 1'000'000; void performance_test() { timer t; @@ -70,5 +102,8 @@ int main() { stress_test(100); stress_test(1'000); stress_test(1'000'000); + stress_test_independent(100); + stress_test_independent(1'000); + stress_test_independent(1'000'000); performance_test(); } -- cgit v1.2.3