diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2025-07-10 17:40:18 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2025-07-10 17:40:18 +0200 |
| commit | 630a5bdf06d59b8340fb4bfc0e692cbcf094026a (patch) | |
| tree | adee732c8d2cdcb46e5f400611c370b4c2ec1947 /test | |
| parent | 609d5a3bf490cfa151b40e60cb62c8ff751bbe56 (diff) | |
run with sanitizer
Diffstat (limited to 'test')
127 files changed, 283 insertions, 271 deletions
diff --git a/test/datastructures/LCT.cpp b/test/datastructures/LCT.cpp index 58d76d7..a1e37eb 100644 --- a/test/datastructures/LCT.cpp +++ b/test/datastructures/LCT.cpp @@ -194,5 +194,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/dynamicConvexHull.cpp b/test/datastructures/dynamicConvexHull.cpp index e0345af..335dbae 100644 --- a/test/datastructures/dynamicConvexHull.cpp +++ b/test/datastructures/dynamicConvexHull.cpp @@ -63,5 +63,5 @@ int main() { stress_test(100); stress_test(1'000); stress_test(1'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/fenwickTree.cpp b/test/datastructures/fenwickTree.cpp index c1ef6bf..62e6392 100644 --- a/test/datastructures/fenwickTree.cpp +++ b/test/datastructures/fenwickTree.cpp @@ -54,5 +54,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/fenwickTree2.cpp b/test/datastructures/fenwickTree2.cpp index 89d5b0f..16caa1d 100644 --- a/test/datastructures/fenwickTree2.cpp +++ b/test/datastructures/fenwickTree2.cpp @@ -56,5 +56,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/lazyPropagation.cpp b/test/datastructures/lazyPropagation.cpp index feb07f0..22b75ba 100644 --- a/test/datastructures/lazyPropagation.cpp +++ b/test/datastructures/lazyPropagation.cpp @@ -57,5 +57,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/lichao.cpp b/test/datastructures/lichao.cpp index f4b797b..9cf770f 100644 --- a/test/datastructures/lichao.cpp +++ b/test/datastructures/lichao.cpp @@ -71,5 +71,5 @@ int main() { stress_test(100); stress_test(1'000); stress_test(1'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/monotonicConvexHull.cpp b/test/datastructures/monotonicConvexHull.cpp index 0415068..9490d7e 100644 --- a/test/datastructures/monotonicConvexHull.cpp +++ b/test/datastructures/monotonicConvexHull.cpp @@ -130,5 +130,5 @@ int main() { stress_test_independent(100); stress_test_independent(1'000); stress_test_independent(1'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/segmentTree.cpp b/test/datastructures/segmentTree.cpp index fbac13e..39cf20f 100644 --- a/test/datastructures/segmentTree.cpp +++ b/test/datastructures/segmentTree.cpp @@ -115,8 +115,8 @@ void performance_test2() { int main() { cerr << "point update + range query:" << endl; stress_test1(); - performance_test1(); + if (!sanitize) performance_test1(); cerr << "range update + point query" << endl; stress_test2(); - performance_test2(); + if (!sanitize) performance_test2(); } diff --git a/test/datastructures/sparseTable.cpp b/test/datastructures/sparseTable.cpp index 7577694..9a7fac5 100644 --- a/test/datastructures/sparseTable.cpp +++ b/test/datastructures/sparseTable.cpp @@ -47,5 +47,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/sparseTableDisjoint.cpp b/test/datastructures/sparseTableDisjoint.cpp index 77bb005..1147b42 100644 --- a/test/datastructures/sparseTableDisjoint.cpp +++ b/test/datastructures/sparseTableDisjoint.cpp @@ -44,5 +44,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/treap.cpp b/test/datastructures/treap.cpp index 2fc9d63..9a3527e 100644 --- a/test/datastructures/treap.cpp +++ b/test/datastructures/treap.cpp @@ -81,5 +81,5 @@ int main() { stress_test(10000, 10); stress_test(1000, 100); stress_test(100, 10000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/unionFind.cpp b/test/datastructures/unionFind.cpp index 2afdc86..50ad50d 100644 --- a/test/datastructures/unionFind.cpp +++ b/test/datastructures/unionFind.cpp @@ -105,5 +105,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/datastructures/waveletTree.cpp b/test/datastructures/waveletTree.cpp index d294835..4c51b60 100644 --- a/test/datastructures/waveletTree.cpp +++ b/test/datastructures/waveletTree.cpp @@ -71,5 +71,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/antipodalPoints.cpp b/test/geometry/antipodalPoints.cpp index d20dfb6..66f063b 100644 --- a/test/geometry/antipodalPoints.cpp +++ b/test/geometry/antipodalPoints.cpp @@ -66,5 +66,5 @@ void performance_test() { int main() { stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/closestPair.cpp b/test/geometry/closestPair.cpp index 5959b21..99f9d5e 100644 --- a/test/geometry/closestPair.cpp +++ b/test/geometry/closestPair.cpp @@ -65,5 +65,5 @@ void performance_test() { int main() { stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/closestPair.double.cpp b/test/geometry/closestPair.double.cpp index 2f8a1ab..427fcf8 100644 --- a/test/geometry/closestPair.double.cpp +++ b/test/geometry/closestPair.double.cpp @@ -62,5 +62,5 @@ void performance_test() { int main() { stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/convexHull.cpp b/test/geometry/convexHull.cpp index 788a634..8a5ad9b 100644 --- a/test/geometry/convexHull.cpp +++ b/test/geometry/convexHull.cpp @@ -75,5 +75,5 @@ void performance_test() { int main() { stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/delaunay.cpp b/test/geometry/delaunay.cpp index 5740b95..06ad6b5 100644 --- a/test/geometry/delaunay.cpp +++ b/test/geometry/delaunay.cpp @@ -69,9 +69,9 @@ bool inOutCirc(pt a, pt b, pt c, pt p) { } -void stress_test(ll range) { +void stress_test(ll LIM, ll range) { ll queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer<int>(3, 30); auto ps = Random::points<lll>(n, -range, range); bool skip = true; @@ -137,8 +137,14 @@ void performance_test() { } int main() { - stress_test(10); - stress_test(10'000); - stress_test(1'000'000'000); - performance_test(); + if (!sanitize) { + stress_test(100'000, 10); + stress_test(100'000, 10'000); + stress_test(100'000, 1'000'000'000); + performance_test(); + } else { + stress_test(10'000, 10); + stress_test(10'000, 10'000); + stress_test(10'000, 1'000'000'000); + } } diff --git a/test/geometry/polygon.cpp b/test/geometry/polygon.cpp index 643ea70..2653dbd 100644 --- a/test/geometry/polygon.cpp +++ b/test/geometry/polygon.cpp @@ -26,9 +26,9 @@ double distToSegment(pt a, pt b, pt p) { #include <geometry/polygon.cpp> #include "../geometry.h" -void test_area(ll range) { +void test_area(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 30); auto ps = Random::polygon(n, range); ps.push_back(ps[0]); @@ -49,9 +49,9 @@ bool ptLess(pt a, pt b) { return imag(a) < imag(b); } -void test_windingNumber(ll range) { +void test_windingNumber(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 8); auto ps = Random::polygon(n, range); ps.push_back(ps[0]); @@ -62,7 +62,7 @@ void test_windingNumber(ll range) { ll expected = 0; bool onBorder = false; for (int j = 0; j < n; j++) { - int cur = details::lineSegmentIntersection(p, p + pt(1, 2'000'000'007), ps[j], ps[j+1]); + int cur = details::lineSegmentIntersection(p, {real(p)+1, 1'000'000'007}, ps[j], ps[j+1]); if (ptLess(ps[j], ps[j+1])) expected -= cur; else expected += cur; onBorder |= pointOnSegment(ps[j], ps[j+1], p); @@ -79,9 +79,9 @@ void test_windingNumber(ll range) { cerr << "tested windingNumber: " << queries << endl; } -void test_inside(ll range) { +void test_inside(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 30); auto ps = Random::polygon(n, range); ps.push_back(ps[0]); @@ -92,7 +92,7 @@ void test_inside(ll range) { ll count = 0; bool onBorder = false; for (int j = 0; j < n; j++) { - count += details::lineSegmentIntersection(p, p + pt(1, 2'000'000'007), ps[j], ps[j+1]); + count += details::lineSegmentIntersection(p, {real(p)+1, 1'000'000'007}, ps[j], ps[j+1]); onBorder |= pointOnSegment(ps[j], ps[j+1], p); } bool expected = (count % 2) && !onBorder; @@ -105,9 +105,9 @@ void test_inside(ll range) { cerr << "tested inside: " << queries << endl; } -void test_insideConvex(ll range) { +void test_insideConvex(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 30); auto ps = Random::convex(n, range); @@ -145,9 +145,9 @@ bool insideOrOnConvex(pt p, const vector<pt>& hull) { return cross(hull[l], hull[r], p) >= 0; } -void test_minkowski(ll range) { +void test_minkowski(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 30); auto A = Random::convex(n, range); int m = Random::integer(3, 30); @@ -192,10 +192,10 @@ double naive_dist(const vector<pt>& ps, const vector<pt>& qs) { return res; } -void test_dist(ll range) { +void test_dist(ll LIM, ll range) { int queries = 0; int pos = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 10); auto A = Random::convex(n, range / 3); int m = Random::integer(3, 10); @@ -215,9 +215,9 @@ void test_dist(ll range) { cerr << "tested dist: " << queries << " (" << pos << ")" << endl; } -void test_extremal(ll range) { +void test_extremal(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 30); auto ps = Random::convex(n, range); ps.push_back(ps[0]); @@ -238,9 +238,9 @@ void test_extremal(ll range) { cerr << "tested extremal: " << queries << endl; } -void test_intersect(ll range) { +void test_intersect(ll LIM, ll range) { int queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer(3, 10); auto ps = Random::convex(n, range); ps.push_back(ps[0]); @@ -277,20 +277,21 @@ void test_intersect(ll range) { } int main() { - test_area(100); - test_area(1'000'000'000); - test_windingNumber(100); - test_windingNumber(1'000'000'000); - test_inside(100); - test_inside(1'000'000'000); - test_insideConvex(100); - test_insideConvex(1'000'000'000); - test_minkowski(100); - test_minkowski(500'000'000); - test_dist(100); - test_dist(1'000'000'000); - test_extremal(100); - test_extremal(1'000'000'000); - test_intersect(100); - test_intersect(1'000'000'000); + ll LIM = sanitize ? 4'000 : 100'000; + test_area(LIM, 100); + test_area(LIM, 1'000'000'000); + test_windingNumber(LIM, 100); + test_windingNumber(LIM, 1'000'000'000); + test_inside(LIM, 100); + test_inside(LIM, 1'000'000'000); + test_insideConvex(LIM, 100); + test_insideConvex(LIM, 1'000'000'000); + test_minkowski(LIM, 100); + test_minkowski(LIM, 500'000'000); + test_dist(LIM, 100); + test_dist(LIM, 1'000'000'000); + test_extremal(LIM, 100); + test_extremal(LIM, 1'000'000'000); + test_intersect(LIM, 100); + test_intersect(LIM, 1'000'000'000); } diff --git a/test/geometry/segmentIntersection.cpp b/test/geometry/segmentIntersection.cpp index 6d3ddd6..0f67eb2 100644 --- a/test/geometry/segmentIntersection.cpp +++ b/test/geometry/segmentIntersection.cpp @@ -84,5 +84,5 @@ void performance_test() { int main() { stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/geometry/sortAround.cpp b/test/geometry/sortAround.cpp index a27edc8..abd803e 100644 --- a/test/geometry/sortAround.cpp +++ b/test/geometry/sortAround.cpp @@ -79,5 +79,5 @@ int main() { test_tiny(); stress_test(100); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/2sat.cpp b/test/graph/2sat.cpp index cf37131..4635086 100644 --- a/test/graph/2sat.cpp +++ b/test/graph/2sat.cpp @@ -126,5 +126,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/LCA_sparse.cpp b/test/graph/LCA_sparse.cpp index f6eb345..f5b023f 100644 --- a/test/graph/LCA_sparse.cpp +++ b/test/graph/LCA_sparse.cpp @@ -59,5 +59,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/TSP.cpp b/test/graph/TSP.cpp index f9aab2e..930ec88 100644 --- a/test/graph/TSP.cpp +++ b/test/graph/TSP.cpp @@ -57,11 +57,11 @@ void performance_test() { hash_t hash = 0; for (int x : got) hash += x; - if (t.time > 1000) cerr << "too slow: " << t.time << FAIL; + if (t.time > 1500) cerr << "too slow: " << t.time << FAIL; cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; } int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/articulationPoints.bcc.cpp b/test/graph/articulationPoints.bcc.cpp index 15f5cf2..e9fc32f 100644 --- a/test/graph/articulationPoints.bcc.cpp +++ b/test/graph/articulationPoints.bcc.cpp @@ -42,9 +42,9 @@ vector<vector<int>> naiveBCC(int m) { return res; } -void stress_test_bcc() { +void stress_test_bcc(int LIM) { ll queries = 0; - for (int tries = 0; tries < 200'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer<int>(1, 30); int m = Random::integer<int>(0, max<int>(1, min<int>(300, n*(n-1) / 2 + 1))); Graph<NoData, 0, 1> g(n); @@ -74,5 +74,6 @@ void stress_test_bcc() { } int main() { - stress_test_bcc(); + stress_test_bcc(20'000); + if (!sanitize) stress_test_bcc(200'000); } diff --git a/test/graph/articulationPoints.cpp b/test/graph/articulationPoints.cpp index 2567a09..8ee6bc4 100644 --- a/test/graph/articulationPoints.cpp +++ b/test/graph/articulationPoints.cpp @@ -81,5 +81,5 @@ void performance_test() { int main() { stress_test_art(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/bellmannFord.cpp b/test/graph/bellmannFord.cpp index 92f1fef..dd697f7 100644 --- a/test/graph/bellmannFord.cpp +++ b/test/graph/bellmannFord.cpp @@ -9,9 +9,9 @@ namespace floydWarshall { #include <graph/floydWarshall.cpp> } -void stress_test() { +void stress_test(int LIM) { ll queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer<int>(2, 30); int m = Random::integer<int>(n-1, max<int>(n, min<int>(500, n*(n-1) / 2 + 1))); vector<ll> potential = Random::integers<ll>(n, 0, 1'000'000'000'000ll); @@ -65,6 +65,7 @@ void performance_test() { } int main() { - stress_test(); - performance_test(); + stress_test(10'000); + if (!sanitize) stress_test(100'000); + if (!sanitize) performance_test(); } diff --git a/test/graph/bitonicTSP.cpp b/test/graph/bitonicTSP.cpp.todo index 7c448a2..9d6b77d 100644 --- a/test/graph/bitonicTSP.cpp +++ b/test/graph/bitonicTSP.cpp.todo @@ -9,17 +9,25 @@ namespace expected { void stress_test() { ll queries = 0; for (int tries = 0; tries < 200'000; tries++) { - int n = Random::integer<int>(1, 30); + int n = Random::integer<int>(2, 30); vector<vector<double>> dist(n); for (auto& v : dist) v = Random::reals<double>(n, 0, 1e18); + auto eval = [&](const vector<int>& order) { + double res = 0; + for (int i = 0; i < n; i++) res += dist[order[i]][order[i+1]]; + return res; + }; + got::dist = dist; expected::dist = dist; - auto got = got::bitonicTSP(); - auto expected = got::bitonicTSP(); + auto got = eval(got::bitonicTSP()); + auto expected = eval(expected::bitonicTSP()); + std::cout << got << std::endl; + std::cout << expected << std::endl; if (got != expected) cerr << "error" << FAIL; queries += n; } @@ -45,5 +53,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/bitonicTSPsimple.cpp b/test/graph/bitonicTSPsimple.cpp.todo index c79a0ef..7e0a80b 100644 --- a/test/graph/bitonicTSPsimple.cpp +++ b/test/graph/bitonicTSPsimple.cpp.todo @@ -9,7 +9,7 @@ namespace expected { void stress_test() { ll queries = 0; for (int tries = 0; tries < 200'000; tries++) { - int n = Random::integer<int>(1, 30); + int n = Random::integer<int>(2, 30); vector<vector<double>> dist(n); for (auto& v : dist) v = Random::reals<double>(n, 0, 1e18); @@ -18,7 +18,7 @@ void stress_test() { expected::dist = dist; auto got = got::bitonicTSP(); - auto expected = got::bitonicTSP(); + auto expected = expected::bitonicTSP(); if (got != expected) cerr << "error" << FAIL; queries += n; @@ -45,5 +45,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/blossom.cpp b/test/graph/blossom.cpp index 714b029..f44f815 100644 --- a/test/graph/blossom.cpp +++ b/test/graph/blossom.cpp @@ -1,6 +1,6 @@ #include "../util.h" namespace tutte { -void gauss(int n, ll mod); +void gauss(int n, int m); #include <graph/matching.cpp> #include <math/shortModInv.cpp> #include <math/lgsFp.cpp> @@ -72,5 +72,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/bronKerbosch.cpp b/test/graph/bronKerbosch.cpp index 1ccd493..1a90c06 100644 --- a/test/graph/bronKerbosch.cpp +++ b/test/graph/bronKerbosch.cpp @@ -69,5 +69,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/centroid.cpp b/test/graph/centroid.cpp index 41d9d0f..c3f1d3f 100644 --- a/test/graph/centroid.cpp +++ b/test/graph/centroid.cpp @@ -73,5 +73,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/connect.cpp b/test/graph/connect.cpp index bba8104..9580a4b 100644 --- a/test/graph/connect.cpp +++ b/test/graph/connect.cpp @@ -136,5 +136,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/cycleCounting.cpp b/test/graph/cycleCounting.cpp index 8e53aec..6459162 100644 --- a/test/graph/cycleCounting.cpp +++ b/test/graph/cycleCounting.cpp @@ -75,5 +75,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/dijkstra.cpp b/test/graph/dijkstra.cpp index c0cfb7e..dd5b826 100644 --- a/test/graph/dijkstra.cpp +++ b/test/graph/dijkstra.cpp @@ -7,9 +7,9 @@ struct edge { }; #include <graph/bellmannFord.cpp> -void stress_test() { +void stress_test(int LIM) { ll queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer<int>(2, 30); int m = Random::integer<int>(n-1, max<int>(n, min<int>(500, n*(n-1) / 2 + 1))); @@ -59,6 +59,7 @@ void performance_test() { } int main() { - stress_test(); - performance_test(); + stress_test(10'000); + if (!sanitize) stress_test(100'000); + if (!sanitize) performance_test(); } diff --git a/test/graph/dinic.cpp b/test/graph/dinic.cpp index 5af7c6f..bd270be 100644 --- a/test/graph/dinic.cpp +++ b/test/graph/dinic.cpp @@ -58,5 +58,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/dinicScaling.cpp b/test/graph/dinicScaling.cpp index 967d6b1..065dd9e 100644 --- a/test/graph/dinicScaling.cpp +++ b/test/graph/dinicScaling.cpp @@ -57,5 +57,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/euler.cpp b/test/graph/euler.cpp index 457ca99..b26add1 100644 --- a/test/graph/euler.cpp +++ b/test/graph/euler.cpp @@ -83,5 +83,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/floydWarshall.cpp b/test/graph/floydWarshall.cpp index a93a9ea..5926449 100644 --- a/test/graph/floydWarshall.cpp +++ b/test/graph/floydWarshall.cpp @@ -9,9 +9,9 @@ namespace floydWarshall { #include <graph/floydWarshall.cpp> } -void stress_test() { +void stress_test(int LIM) { ll queries = 0; - for (int tries = 0; tries < 100'000; tries++) { + for (int tries = 0; tries < LIM; tries++) { int n = Random::integer<int>(2, 30); int m = Random::integer<int>(n-1, max<int>(n, min<int>(500, n*(n-1) / 2 + 1))); vector<ll> potential = Random::integers<ll>(n, 0, 1'000'000'000'000ll); @@ -85,6 +85,7 @@ void performance_test() { } int main() { - stress_test(); - performance_test(); + stress_test(10'000); + if (!sanitize) stress_test(100'000); + if (!sanitize) performance_test(); } diff --git a/test/graph/havelHakimi.cpp b/test/graph/havelHakimi.cpp index 71476ec..f0b6fd9 100644 --- a/test/graph/havelHakimi.cpp +++ b/test/graph/havelHakimi.cpp @@ -61,5 +61,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/hld.cpp b/test/graph/hld.cpp index bcd9c8c..bf055f7 100644 --- a/test/graph/hld.cpp +++ b/test/graph/hld.cpp @@ -79,5 +79,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/hopcroftKarp.cpp b/test/graph/hopcroftKarp.cpp index 05599dd..a6306b6 100644 --- a/test/graph/hopcroftKarp.cpp +++ b/test/graph/hopcroftKarp.cpp @@ -70,5 +70,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/kruskal.cpp b/test/graph/kruskal.cpp index f6245b9..d80376f 100644 --- a/test/graph/kruskal.cpp +++ b/test/graph/kruskal.cpp @@ -87,5 +87,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/matching.cpp b/test/graph/matching.cpp index b8fbc6c..ccd98e6 100644 --- a/test/graph/matching.cpp +++ b/test/graph/matching.cpp @@ -1,6 +1,6 @@ #include "../util.h" namespace tutte { -void gauss(int n, ll mod); +void gauss(int n, int m); #include <graph/matching.cpp> #include <math/shortModInv.cpp> #include <math/lgsFp.cpp> @@ -58,5 +58,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/maxCarBiMatch.cpp b/test/graph/maxCarBiMatch.cpp index 6d7fad0..6672d30 100644 --- a/test/graph/maxCarBiMatch.cpp +++ b/test/graph/maxCarBiMatch.cpp @@ -70,5 +70,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/maxWeightBipartiteMatching.cpp b/test/graph/maxWeightBipartiteMatching.cpp index d245405..be38d8c 100644 --- a/test/graph/maxWeightBipartiteMatching.cpp +++ b/test/graph/maxWeightBipartiteMatching.cpp @@ -55,5 +55,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/minCostMaxFlow.cpp b/test/graph/minCostMaxFlow.cpp index 8c92aa7..a070f51 100644 --- a/test/graph/minCostMaxFlow.cpp +++ b/test/graph/minCostMaxFlow.cpp @@ -64,5 +64,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/pushRelabel.cpp b/test/graph/pushRelabel.cpp index ac3b079..00a73d1 100644 --- a/test/graph/pushRelabel.cpp +++ b/test/graph/pushRelabel.cpp @@ -57,5 +57,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/reroot.cpp b/test/graph/reroot.cpp index d5043b4..6fc2f4d 100644 --- a/test/graph/reroot.cpp +++ b/test/graph/reroot.cpp @@ -55,5 +55,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/scc.cpp b/test/graph/scc.cpp index cf4efc7..7c1261f 100644 --- a/test/graph/scc.cpp +++ b/test/graph/scc.cpp @@ -65,5 +65,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/stoerWagner.cpp b/test/graph/stoerWagner.cpp index 2003f09..cc01a7d 100644 --- a/test/graph/stoerWagner.cpp +++ b/test/graph/stoerWagner.cpp @@ -77,5 +77,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/treeIsomorphism.cpp b/test/graph/treeIsomorphism.cpp index 97f4df4..e5fd817 100644 --- a/test/graph/treeIsomorphism.cpp +++ b/test/graph/treeIsomorphism.cpp @@ -122,5 +122,5 @@ int main() { stress_test_eq(); test_tiny(); stress_test_neq(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/graph/virtualTree.cpp b/test/graph/virtualTree.cpp index d256760..af57619 100644 --- a/test/graph/virtualTree.cpp +++ b/test/graph/virtualTree.cpp @@ -91,5 +91,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/berlekampMassey.cpp b/test/math/berlekampMassey.cpp index 58fd143..c7e83fc 100644 --- a/test/math/berlekampMassey.cpp +++ b/test/math/berlekampMassey.cpp @@ -63,6 +63,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/bigint.cpp b/test/math/bigint.cpp index 3fc4ac1..53e18dd 100644 --- a/test/math/bigint.cpp +++ b/test/math/bigint.cpp @@ -35,9 +35,9 @@ struct modInt { constexpr ll MOD = 1'394'633'899; constexpr ll POOL = 8; -void stress_test() { +void stress_test(int LIM) { int queries = 0; - for (int tries = 0; tries < 1000; tries++) { + for (int tries = 0; tries < LIM; tries++) { vector<modInt<MOD>> expectedPool(POOL); vector<bigint> gotPool(POOL); for (int i = 0; i < POOL; i++) { @@ -117,6 +117,7 @@ void stress_test() { } int main() { - stress_test(); + stress_test(100); + if (!sanitize) stress_test(1000); } diff --git a/test/math/cycleDetection.cpp b/test/math/cycleDetection.cpp index bf57aed..09480b1 100644 --- a/test/math/cycleDetection.cpp +++ b/test/math/cycleDetection.cpp @@ -42,6 +42,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/discreteLogarithm.cpp b/test/math/discreteLogarithm.cpp index 0f9eecf..6e87e59 100644 --- a/test/math/discreteLogarithm.cpp +++ b/test/math/discreteLogarithm.cpp @@ -59,6 +59,6 @@ int main() { stress_test([](ll p){return sqrtl(p);}); stress_test([](ll p){return min<ll>(10, p - 1);}); stress_test([](ll p){return min<ll>(p - 1, sqrtl(p) + 100);}); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/discreteNthRoot.cpp b/test/math/discreteNthRoot.cpp index d595e6d..e64293c 100644 --- a/test/math/discreteNthRoot.cpp +++ b/test/math/discreteNthRoot.cpp @@ -73,6 +73,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/divSum.cpp b/test/math/divSum.cpp index 1f82387..a366e53 100644 --- a/test/math/divSum.cpp +++ b/test/math/divSum.cpp @@ -43,6 +43,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/divisors.cpp b/test/math/divisors.cpp index 2402d2a..4cc7e70 100644 --- a/test/math/divisors.cpp +++ b/test/math/divisors.cpp @@ -60,6 +60,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/extendedEuclid.cpp b/test/math/extendedEuclid.cpp index 597f722..07e4882 100644 --- a/test/math/extendedEuclid.cpp +++ b/test/math/extendedEuclid.cpp @@ -32,8 +32,10 @@ void stress_test() { queries++; } cerr << "tested random queries: " << queries << endl; - if (t.time > 500) cerr << "too slow: " << t.time << FAIL; - cerr << "tested performance: " << t.time << "ms" << endl; + if (!sanitize) { + if (t.time > 500) cerr << "too slow: " << t.time << FAIL; + cerr << "tested performance: " << t.time << "ms" << endl; + } } int main() { diff --git a/test/math/gauss.cpp b/test/math/gauss.cpp index 6e4759d..167aa62 100644 --- a/test/math/gauss.cpp +++ b/test/math/gauss.cpp @@ -114,5 +114,5 @@ void performance_test() { int main() { test_tiny(); stress_test_inv(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/gcd-lcm.cpp b/test/math/gcd-lcm.cpp deleted file mode 100644 index 294095b..0000000 --- a/test/math/gcd-lcm.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "../util.h" -#include <math/gcd-lcm.cpp> - -void stress_test() { - if (::gcd(0, 0) != 0) cerr << "error: gcd(0, 0)" << FAIL; - if (::lcm(0, 0) != 0) cerr << "error: lcm(0, 0)" << FAIL; - ll queries = 0; - timer t; - for (int i = 0; i < 1'000'000; i++) { - ll a = Random::integer<ll>(0, 1'000'000'000); - ll b = 0; - { - ll got = ::gcd(a, b); - ll expected = std::gcd(a, b); - if (got != expected) cerr << "gcd(" << a << ", " << b << "), got: " << got << ", expected: " << expected << FAIL; - } - { - ll got = ::lcm(a, b); - ll expected = std::lcm(a, b); - if (got != expected) cerr << "lcm(" << a << ", " << b << "), got: " << got << ", expected: " << expected << FAIL; - } - b = Random::integer<ll>(0, 1'000'000'000); - { - t.start(); - ll got = ::gcd(a, b); - t.stop(); - ll expected = std::gcd(a, b); - if (got != expected) cerr << "gcd(" << a << ", " << b << "), got: " << got << ", expected: " << expected << FAIL; - } - { - t.start(); - ll got = ::lcm(a, b); - t.stop(); - ll expected = std::lcm(a, b); - if (got != expected) cerr << "lcm(" << a << ", " << b << "), got: " << got << ", expected: " << expected << FAIL; - } - queries++; - } - cerr << "tested random queries: " << queries << endl; - if (t.time > 750) cerr << "too slow: " << t.time << FAIL; - cerr << "tested performance: " << t.time << "ms" << endl; -} - -int main() { - stress_test(); -} diff --git a/test/math/goldenSectionSearch.cpp b/test/math/goldenSectionSearch.cpp index 565a21c..ff2d067 100644 --- a/test/math/goldenSectionSearch.cpp +++ b/test/math/goldenSectionSearch.cpp @@ -69,6 +69,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/inversions.cpp b/test/math/inversions.cpp index d2a54b7..42ab343 100644 --- a/test/math/inversions.cpp +++ b/test/math/inversions.cpp @@ -38,6 +38,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/inversionsMerge.cpp b/test/math/inversionsMerge.cpp index acdc555..2492af4 100644 --- a/test/math/inversionsMerge.cpp +++ b/test/math/inversionsMerge.cpp @@ -41,6 +41,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/kthperm.cpp b/test/math/kthperm.cpp index 16691b9..1bf8db3 100644 --- a/test/math/kthperm.cpp +++ b/test/math/kthperm.cpp @@ -2,9 +2,9 @@ #include <datastructures/pbds.cpp> #include <math/kthperm.cpp> -void stress_test() { +void stress_test(int LIM) { ll queries = 0; - for (ll i = 0; i < 10'000; i++) { + for (int i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); vector<ll> expected(n); iota(all(expected), 0); @@ -32,7 +32,8 @@ void performance_test() { } int main() { - stress_test(); - performance_test(); + stress_test(1'000); + if (!sanitize) stress_test(10'000); + if (!sanitize) performance_test(); } diff --git a/test/math/legendre.cpp b/test/math/legendre.cpp index f210b57..44f88c1 100644 --- a/test/math/legendre.cpp +++ b/test/math/legendre.cpp @@ -38,6 +38,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/lgsFp.cpp b/test/math/lgsFp.cpp index d7680ea..6db586a 100644 --- a/test/math/lgsFp.cpp +++ b/test/math/lgsFp.cpp @@ -116,5 +116,5 @@ void performance_test() { int main() { test_square(); stress_test_inv(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/linearCongruence.cpp b/test/math/linearCongruence.cpp index ba8eeac..fa01a06 100644 --- a/test/math/linearCongruence.cpp +++ b/test/math/linearCongruence.cpp @@ -48,6 +48,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/linearRecurrence.cpp b/test/math/linearRecurrence.cpp index f0ebe76..977221e 100644 --- a/test/math/linearRecurrence.cpp +++ b/test/math/linearRecurrence.cpp @@ -55,6 +55,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/linearRecurrenceNTT.cpp b/test/math/linearRecurrenceNTT.cpp index e03c27e..ca7e29e 100644 --- a/test/math/linearRecurrenceNTT.cpp +++ b/test/math/linearRecurrenceNTT.cpp @@ -55,6 +55,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/linearRecurrenceOld.cpp b/test/math/linearRecurrenceOld.cpp index dab2256..6435d5a 100644 --- a/test/math/linearRecurrenceOld.cpp +++ b/test/math/linearRecurrenceOld.cpp @@ -49,6 +49,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/linearSieve.cpp b/test/math/linearSieve.cpp index 8ea822b..fbed4b5 100644 --- a/test/math/linearSieve.cpp +++ b/test/math/linearSieve.cpp @@ -59,8 +59,10 @@ void performance_test() { sieve(); hash_t hash = sz(primes); t.stop(); - if (t.time > 500) cerr << "too slow: " << t.time << FAIL; - cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; + if (!sanitize) { + if (t.time > 500) cerr << "too slow: " << t.time << FAIL; + cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; + } } int main() { diff --git a/test/math/longestIncreasingSubsequence.cpp b/test/math/longestIncreasingSubsequence.cpp index 407dafe..0ed0f91 100644 --- a/test/math/longestIncreasingSubsequence.cpp +++ b/test/math/longestIncreasingSubsequence.cpp @@ -72,5 +72,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/matrixPower.cpp b/test/math/matrixPower.cpp index 4dfb0a8..b1d6783 100644 --- a/test/math/matrixPower.cpp +++ b/test/math/matrixPower.cpp @@ -111,6 +111,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/millerRabin.base32.cpp b/test/math/millerRabin.base32.cpp index 742d353..069f125 100644 --- a/test/math/millerRabin.base32.cpp +++ b/test/math/millerRabin.base32.cpp @@ -132,6 +132,6 @@ void performance_test() { int main() { extra_tests(); stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/millerRabin.cpp b/test/math/millerRabin.cpp index fd98586..18fad40 100644 --- a/test/math/millerRabin.cpp +++ b/test/math/millerRabin.cpp @@ -124,6 +124,6 @@ void performance_test() { int main() { extra_tests(); stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/minMod.cpp b/test/math/minMod.cpp index e49da11..39affb4 100644 --- a/test/math/minMod.cpp +++ b/test/math/minMod.cpp @@ -86,7 +86,7 @@ void performance_test_firstVal() { int main() { stress_test_minMod(); stress_test_firstVal(); - performance_test_minMod(); - performance_test_firstVal(); + if (!sanitize) performance_test_minMod(); + if (!sanitize) performance_test_firstVal(); } diff --git a/test/math/modExp.cpp b/test/math/modExp.cpp index ebb38eb..4d2b4b2 100644 --- a/test/math/modExp.cpp +++ b/test/math/modExp.cpp @@ -37,6 +37,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/modMulIterativ.cpp b/test/math/modMulIterativ.cpp index 4f794c5..7783026 100644 --- a/test/math/modMulIterativ.cpp +++ b/test/math/modMulIterativ.cpp @@ -14,7 +14,7 @@ void stress_test() { k++; expected = (expected + a) % n; } while (k < 100); - queries += n; + queries++; } cerr << "tested queries: " << queries << endl; } @@ -28,7 +28,7 @@ void stress_test_large() { ll expected = (lll)a * b % n; auto got = mulMod(a, b, n); if (got != expected) cerr << "got: " << got << ", expected: " << expected << FAIL; - queries += n; + queries++; } cerr << "tested queries: " << queries << endl; } @@ -52,6 +52,6 @@ void performance_test() { int main() { stress_test(); stress_test_large(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/modPowIterativ.cpp b/test/math/modPowIterativ.cpp index 2cf0eb4..29ea4c5 100644 --- a/test/math/modPowIterativ.cpp +++ b/test/math/modPowIterativ.cpp @@ -37,6 +37,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/multInv.cpp b/test/math/multInv.cpp index 93763c5..a6c37a1 100644 --- a/test/math/multInv.cpp +++ b/test/math/multInv.cpp @@ -35,6 +35,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/permIndex.cpp b/test/math/permIndex.cpp index 61d34c8..8dcfd6b 100644 --- a/test/math/permIndex.cpp +++ b/test/math/permIndex.cpp @@ -2,9 +2,9 @@ #include <datastructures/pbds.cpp> #include <math/permIndex.cpp> -void stress_test() { +void stress_test(int LIM) { ll queries = 0; - for (ll i = 0; i < 10'000; i++) { + for (int i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); vector<ll> cur(n); iota(all(cur), 0); @@ -33,7 +33,8 @@ void performance_test() { } int main() { - stress_test(); - performance_test(); + stress_test(1'000); + if (!sanitize) stress_test(10'000); + if (!sanitize) performance_test(); } diff --git a/test/math/piLegendre.cpp b/test/math/piLegendre.cpp index c3513bf..53c459c 100644 --- a/test/math/piLegendre.cpp +++ b/test/math/piLegendre.cpp @@ -34,7 +34,7 @@ void performance_test() { int main() { lehmer::init(); - performance_test(); + if (!sanitize) performance_test(); stress_test(); } diff --git a/test/math/piLehmer.cpp b/test/math/piLehmer.cpp index d84466f..bfc714f 100644 --- a/test/math/piLehmer.cpp +++ b/test/math/piLehmer.cpp @@ -36,7 +36,8 @@ void performance_test() { } int main() { - performance_test(); + if (!sanitize) performance_test(); + if (sanitize) lehmer::init(); stress_test(); } diff --git a/test/math/primeSieve.cpp b/test/math/primeSieve.cpp index 78a50d2..a675f6a 100644 --- a/test/math/primeSieve.cpp +++ b/test/math/primeSieve.cpp @@ -36,8 +36,10 @@ void performance_test() { primeSieve(); hash_t hash = sz(primes); t.stop(); - if (t.time > 500) cerr << "too slow: " << t.time << FAIL; - cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; + if (!sanitize) { + if (t.time > 500) cerr << "too slow: " << t.time << FAIL; + cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; + } } int main() { diff --git a/test/math/recover.cpp b/test/math/recover.cpp index 6f89e5a..9b61653 100644 --- a/test/math/recover.cpp +++ b/test/math/recover.cpp @@ -35,8 +35,10 @@ void stress_test() { } } cerr << "tested random queries: " << queries << endl; - if (t.time > 500) cerr << "too slow: " << t.time << FAIL; - cerr << "tested performance: " << t.time << "ms" << endl; + if (!sanitize) { + if (t.time > 500) cerr << "too slow: " << t.time << FAIL; + cerr << "tested performance: " << t.time << "ms" << endl; + } } int main() { diff --git a/test/math/rho.cpp b/test/math/rho.cpp index 941524b..9943a8c 100644 --- a/test/math/rho.cpp +++ b/test/math/rho.cpp @@ -120,6 +120,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/shortModInv.cpp b/test/math/shortModInv.cpp index 26960bf..0e91900 100644 --- a/test/math/shortModInv.cpp +++ b/test/math/shortModInv.cpp @@ -34,6 +34,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/simpson.cpp b/test/math/simpson.cpp index d7cdba3..019caca 100644 --- a/test/math/simpson.cpp +++ b/test/math/simpson.cpp @@ -53,8 +53,10 @@ void stress_test() { queries++; } } - if (t.time > 5000) cerr << "too slow: " << t.time << FAIL; - cerr << "tested random queries: " << queries << " (" << t.time << "ms)" << endl; + if (!sanitize) { + if (t.time > 5000) cerr << "too slow: " << t.time << FAIL; + cerr << "tested random queries: " << queries << " (" << t.time << "ms)" << endl; + } } int main() { diff --git a/test/math/sqrtModCipolla.cpp b/test/math/sqrtModCipolla.cpp index 26d975b..c7be9a4 100644 --- a/test/math/sqrtModCipolla.cpp +++ b/test/math/sqrtModCipolla.cpp @@ -43,6 +43,6 @@ void performance_test() { int main() { stress_test(1'000); stress_test(1'000'000'000); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/andTransform.cpp b/test/math/transforms/andTransform.cpp index fa029f6..eef57bf 100644 --- a/test/math/transforms/andTransform.cpp +++ b/test/math/transforms/andTransform.cpp @@ -33,6 +33,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/bitwiseTransforms.cpp b/test/math/transforms/bitwiseTransforms.cpp index 132740c..79fe120 100644 --- a/test/math/transforms/bitwiseTransforms.cpp +++ b/test/math/transforms/bitwiseTransforms.cpp @@ -33,6 +33,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/fft.cpp b/test/math/transforms/fft.cpp index 858676b..35f7e15 100644 --- a/test/math/transforms/fft.cpp +++ b/test/math/transforms/fft.cpp @@ -46,6 +46,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/fftMul.cpp b/test/math/transforms/fftMul.cpp index 5933864..72fd4d8 100644 --- a/test/math/transforms/fftMul.cpp +++ b/test/math/transforms/fftMul.cpp @@ -57,6 +57,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/multiplyBitwise.cpp b/test/math/transforms/multiplyBitwise.cpp index bc73290..e89ba4e 100644 --- a/test/math/transforms/multiplyBitwise.cpp +++ b/test/math/transforms/multiplyBitwise.cpp @@ -50,6 +50,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/multiplyFFT.cpp b/test/math/transforms/multiplyFFT.cpp index 782be1b..a54020c 100644 --- a/test/math/transforms/multiplyFFT.cpp +++ b/test/math/transforms/multiplyFFT.cpp @@ -50,6 +50,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/multiplyNTT.cpp b/test/math/transforms/multiplyNTT.cpp index 70fc137..90c606a 100644 --- a/test/math/transforms/multiplyNTT.cpp +++ b/test/math/transforms/multiplyNTT.cpp @@ -51,6 +51,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/ntt.cpp b/test/math/transforms/ntt.cpp index cd32073..533d086 100644 --- a/test/math/transforms/ntt.cpp +++ b/test/math/transforms/ntt.cpp @@ -34,6 +34,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/orTransform.cpp b/test/math/transforms/orTransform.cpp index 0ec9155..b1fdfad 100644 --- a/test/math/transforms/orTransform.cpp +++ b/test/math/transforms/orTransform.cpp @@ -33,6 +33,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/math/transforms/seriesOperations.cpp b/test/math/transforms/seriesOperations.cpp index ee30e00..29c91c7 100644 --- a/test/math/transforms/seriesOperations.cpp +++ b/test/math/transforms/seriesOperations.cpp @@ -63,9 +63,9 @@ namespace reference {//checked against yosupo } } -void test_inv() { +void test_inv(ll LIM) { ll queries = 0; - for (ll i = 0; i < 50'000; i++) { + for (ll i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); int m = Random::integer<int>(1, 100); vector<ll> a = Random::integers<ll>(n, 0, mod); @@ -78,9 +78,9 @@ void test_inv() { cerr << "tested inv: " << queries << endl; } -void test_deriv() { +void test_deriv(ll LIM) { ll queries = 0; - for (ll i = 0; i < 50'000; i++) { + for (ll i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); vector<ll> a = Random::integers<ll>(n, 0, mod); @@ -92,9 +92,9 @@ void test_deriv() { cerr << "tested deriv: " << queries << endl; } -void test_integr() { +void test_integr(ll LIM) { ll queries = 0; - for (ll i = 0; i < 50'000; i++) { + for (ll i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); vector<ll> a = Random::integers<ll>(n, 0, mod); @@ -106,9 +106,9 @@ void test_integr() { cerr << "tested integr: " << queries << endl; } -void test_log() { +void test_log(ll LIM) { ll queries = 0; - for (ll i = 0; i < 50'000; i++) { + for (ll i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); int m = Random::integer<int>(1, 100); vector<ll> a = Random::integers<ll>(n, 0, mod); @@ -121,9 +121,9 @@ void test_log() { cerr << "tested log: " << queries << endl; } -void test_exp() { +void test_exp(ll LIM) { ll queries = 0; - for (ll i = 0; i < 50'000; i++) { + for (ll i = 0; i < LIM; i++) { int n = Random::integer<int>(1, 100); int m = Random::integer<int>(1, 100); vector<ll> a = Random::integers<ll>(n, 0, mod); @@ -137,9 +137,10 @@ void test_exp() { } int main() { - test_inv(); - test_deriv(); - test_integr(); - test_log(); - test_exp(); + ll LIM = sanitize ? 5'000 : 50'000; + test_inv(LIM); + test_deriv(LIM); + test_integr(LIM); + test_log(LIM); + test_exp(LIM); } diff --git a/test/math/transforms/xorTransform.cpp b/test/math/transforms/xorTransform.cpp index 17b0f6f..630331a 100644 --- a/test/math/transforms/xorTransform.cpp +++ b/test/math/transforms/xorTransform.cpp @@ -33,6 +33,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/bitOps.cpp b/test/other/bitOps.cpp index 44f6297..707c3f0 100644 --- a/test/other/bitOps.cpp +++ b/test/other/bitOps.cpp @@ -27,7 +27,7 @@ void test_subsets() { ll naive(ll x) { vector<ll> bits; - for (ll i = 0; i < 64; i++) { + for (ll i = 0; i < 63; i++) { bits.push_back(x & 1); x >>= 1; } @@ -35,7 +35,7 @@ ll naive(ll x) { next_permutation(all(bits)); reverse(all(bits)); x = 0; - for (ll i = 0, j = 1; i < 64; i++, j <<= 1) { + for (ll i = 0, j = 1; i < 63; i++, j <<= 1) { if (bits[i] != 0) x |= j; } return x; diff --git a/test/other/divideAndConquer.cpp b/test/other/divideAndConquer.cpp index 6d1b444..3878758 100644 --- a/test/other/divideAndConquer.cpp +++ b/test/other/divideAndConquer.cpp @@ -98,6 +98,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/fastSubsetSum.cpp b/test/other/fastSubsetSum.cpp index c61b1ea..ea40184 100644 --- a/test/other/fastSubsetSum.cpp +++ b/test/other/fastSubsetSum.cpp @@ -44,6 +44,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/josephus2.cpp b/test/other/josephus2.cpp index 85a9d28..21154a1 100644 --- a/test/other/josephus2.cpp +++ b/test/other/josephus2.cpp @@ -37,6 +37,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/josephusK.cpp b/test/other/josephusK.cpp index e837640..b6680b8 100644 --- a/test/other/josephusK.cpp +++ b/test/other/josephusK.cpp @@ -38,6 +38,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/knuth.cpp b/test/other/knuth.cpp index aaf5059..3d6cb9b 100644 --- a/test/other/knuth.cpp +++ b/test/other/knuth.cpp @@ -98,6 +98,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/pbs.cpp b/test/other/pbs.cpp index ba3b9d0..4fa4470 100644 --- a/test/other/pbs.cpp +++ b/test/other/pbs.cpp @@ -93,11 +93,11 @@ void performance_test() { t.stop(); ll hash = accumulate(all(ans), 0LL); - if (t.time > 700) cerr << "too slow: " << t.time << FAIL; + if (t.time > 900) cerr << "too slow: " << t.time << FAIL; cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl; } int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/other/sos.cpp b/test/other/sos.cpp index f3a6109..52b55ed 100644 --- a/test/other/sos.cpp +++ b/test/other/sos.cpp @@ -45,6 +45,6 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/ahoCorasick.cpp b/test/string/ahoCorasick.cpp index c3361d6..3203855 100644 --- a/test/string/ahoCorasick.cpp +++ b/test/string/ahoCorasick.cpp @@ -72,5 +72,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/deBruijn.cpp b/test/string/deBruijn.cpp index 6b3fea4..09ba611 100644 --- a/test/string/deBruijn.cpp +++ b/test/string/deBruijn.cpp @@ -39,5 +39,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/duval.cpp b/test/string/duval.cpp index 58b4a44..0475386 100644 --- a/test/string/duval.cpp +++ b/test/string/duval.cpp @@ -79,7 +79,7 @@ void performance_test_minrotation() { int main() { stress_test_duval(); - performance_test_duval(); + if (!sanitize) performance_test_duval(); stress_test_minrotation(); - performance_test_minrotation(); + if (!sanitize) performance_test_minrotation(); } diff --git a/test/string/kmp.cpp b/test/string/kmp.cpp index 9c9c924..f70a887 100644 --- a/test/string/kmp.cpp +++ b/test/string/kmp.cpp @@ -78,8 +78,8 @@ void performance_test_kmp() { int main() { cerr << "preprocessing:" << endl; stress_test_preprocessing(); - performance_test_preprocessing(); + if (!sanitize) performance_test_preprocessing(); cerr << "kmp:" << endl; stress_test_kmp(); - performance_test_kmp(); + if (!sanitize) performance_test_kmp(); } diff --git a/test/string/longestCommonSubsequence.cpp b/test/string/longestCommonSubsequence.cpp index 6d7a6c5..68ec71b 100644 --- a/test/string/longestCommonSubsequence.cpp +++ b/test/string/longestCommonSubsequence.cpp @@ -51,5 +51,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/lyndon.cpp b/test/string/lyndon.cpp index ecf2dad..905bf8e 100644 --- a/test/string/lyndon.cpp +++ b/test/string/lyndon.cpp @@ -57,5 +57,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/manacher.cpp b/test/string/manacher.cpp index 503d181..bde1c89 100644 --- a/test/string/manacher.cpp +++ b/test/string/manacher.cpp @@ -45,5 +45,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/rollingHash.cpp b/test/string/rollingHash.cpp index 0491bc0..ba8fc40 100644 --- a/test/string/rollingHash.cpp +++ b/test/string/rollingHash.cpp @@ -37,13 +37,13 @@ void testTiny() { cerr << "tiny: ok" << endl; } -void testSmall() { +void testSmall(int depth) { set<decltype(getHash(""))> got; ll expected = 0; auto dfs = [&](auto&& self, string pref)->void { expected++; got.insert(getHash(pref)); - if(sz(pref) >= 5) return; + if(sz(pref) >= depth) return; for (char c = 'a'; c <= 'z'; c++) { self(self, pref + c); } @@ -86,7 +86,7 @@ void performance_test() { int main() { testThueMorse(); testTiny(); - testSmall(); + testSmall(sanitize ? 4 : 5); stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/rollingHashCf.cpp b/test/string/rollingHashCf.cpp index 79003de..9acce2d 100644 --- a/test/string/rollingHashCf.cpp +++ b/test/string/rollingHashCf.cpp @@ -39,13 +39,13 @@ void testTiny() { cerr << "tiny: ok" << endl; } -void testSmall() { +void testSmall(int depth) { set<decltype(getHash(""))> got; ll expected = 0; auto dfs = [&](auto&& self, string pref)->void { expected++; got.insert(getHash(pref)); - if(sz(pref) >= 5) return; + if(sz(pref) >= depth) return; for (char c = 'a'; c <= 'z'; c++) { self(self, pref + c); } @@ -88,7 +88,7 @@ void performance_test() { int main() { testThueMorse(); testTiny(); - testSmall(); + testSmall(sanitize ? 4 : 5); stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/suffixArray.cpp b/test/string/suffixArray.cpp index 4945d8e..1314155 100644 --- a/test/string/suffixArray.cpp +++ b/test/string/suffixArray.cpp @@ -57,5 +57,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/suffixAutomaton.cpp b/test/string/suffixAutomaton.cpp index c2ff511..146ae11 100644 --- a/test/string/suffixAutomaton.cpp +++ b/test/string/suffixAutomaton.cpp @@ -58,5 +58,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/suffixTree.cpp b/test/string/suffixTree.cpp index c0d79e4..9181c2e 100644 --- a/test/string/suffixTree.cpp +++ b/test/string/suffixTree.cpp @@ -46,5 +46,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/trie.cpp b/test/string/trie.cpp index 45d89cf..1ea5b1a 100644 --- a/test/string/trie.cpp +++ b/test/string/trie.cpp @@ -54,5 +54,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/string/z.cpp b/test/string/z.cpp index f890a3e..f190482 100644 --- a/test/string/z.cpp +++ b/test/string/z.cpp @@ -37,5 +37,5 @@ void performance_test() { int main() { stress_test(); - performance_test(); + if (!sanitize) performance_test(); } diff --git a/test/test.sh b/test/test.sh index 6609f1a..a3e6ea9 100755 --- a/test/test.sh +++ b/test/test.sh @@ -4,11 +4,14 @@ cd "$(dirname "$0")" ulimit -s 4000000 export MALLOC_PERTURB_="$((2#01011001))" shopt -s lastpipe +export UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 declare -A cppstandard cppstandard["string/suffixArray.cpp"]="gnu++20" cppstandard["other/pbs.cpp"]="gnu++20" seedmacro="" +compilerflags="-O2" +debugflags="-O2 -fsanitize=address,undefined" process_awk() { awk_file=$(realpath --relative-to="${PWD}" "${1}") @@ -22,13 +25,24 @@ process_awk() { test_file() { file=$(realpath --relative-to="${PWD}" "${1}") echo "$file:" - echo "compiling..." + + echo "compiling with sanitizer..." + std="gnu++17" + if [[ -v cppstandard[$file] ]]; then + std=${cppstandard[$file]} + fi + g++ -std=$std "$file" -I ./awk/ -I ../content/ $debugflags -Wall -Wextra -Wshadow -Werror -DSANITIZE $seedmacro + echo "running with sanitizer..." + timeout --foreground 90s ./a.out + rm ./a.out + + echo "compiling -O2..." std="gnu++17" if [[ -v cppstandard[$file] ]]; then std=${cppstandard[$file]} fi - g++ -std=$std "$file" -I ./awk/ -I ../content/ -O2 -Wall -Wextra -Wshadow -Werror $seedmacro - echo "running..." + g++ -std=$std "$file" -I ./awk/ -I ../content/ $compilerflags -Wall -Wextra -Wshadow -Werror $seedmacro + echo "running -O2..." timeout --foreground 60s ./a.out echo "" rm ./a.out @@ -92,6 +106,8 @@ if [ "$#" -ne 0 ]; then coverage elif [[ $arg == --seed=* ]]; then seedmacro="-DSEED=${arg:7}ll" + elif [[ $arg == "--debug" ]]; then + debugflags="-g -fsanitize=address,undefined" elif [ -d "$arg" ]; then dir=$(realpath --relative-to="${PWD}" "$arg") find . -type f -path "./${dir}/*.cpp" -not -path './awk/*' -print0 | sort -z | while read -d $'\0' file @@ -102,6 +118,7 @@ if [ "$#" -ne 0 ]; then test_file "$arg" else echo "did not recognize: $arg" + exit 1 fi done else diff --git a/test/util.h b/test/util.h index 6f23b82..8de393d 100644 --- a/test/util.h +++ b/test/util.h @@ -4,6 +4,13 @@ using namespace std; #define all(x) std::begin(x), std::end(x) #define sz(x) (ll)std::size(x) +#ifdef SANITIZE + constexpr bool sanitize = true; +#else + constexpr bool sanitize = false; +#endif + + using ll = long long; using lll = __int128; using ld = long double; |
