From f2d9926e6689972abc33e190f8fe9e58f6b0ac98 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 15 Nov 2026 18:57:08 +0100 Subject: [PATCH] test(track): count the steps along a buckle in integers SonarCloud S2193: no float loop counters. --- tests/unit/test_track_buckle.cpp | 7 ++++--- tests/unit/test_track_buckle_derailment.cpp | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_track_buckle.cpp b/tests/unit/test_track_buckle.cpp index df26c74ab..589ed125d 100644 --- a/tests/unit/test_track_buckle.cpp +++ b/tests/unit/test_track_buckle.cpp @@ -180,8 +180,9 @@ TEST_CASE("the buckle has its amplitude in the middle, side lobes the other way CHECK(track_buckle::bend(shape, 60.0) == doctest::Approx(-peak)); // none larger anywhere, and the curvature with no jumps auto previous{track_buckle::bend(shape, 35.0)}; - for (auto at = 35.0; at <= 85.0; at += 0.01) + for (auto step = 0; step <= 5000; ++step) { + auto const at{35.0 + 0.01 * step}; auto const bend{track_buckle::bend(shape, at)}; CHECK(std::abs(bend) <= peak * 1.0001); CHECK(std::abs(bend - previous) < 0.01 * peak); @@ -230,8 +231,8 @@ TEST_CASE("a bogie feels the curvature of the buckle averaged over its wheelbase CHECK(std::abs(across) < 0.5 * peak); // the most the body feels, at any place, is less than a bogie does auto most{0.0}; - for (auto at = 20.0; at <= 80.0; at += 0.05) - most = std::max(most, std::abs(track_buckle::body_bend(shape, at, 17.0, 2.5))); + for (auto step = 0; step <= 1200; ++step) + most = std::max(most, std::abs(track_buckle::body_bend(shape, 20.0 + 0.05 * step, 17.0, 2.5))); CHECK(most < 0.95 * peak); CHECK(most > 0.3 * peak); } diff --git a/tests/unit/test_track_buckle_derailment.cpp b/tests/unit/test_track_buckle_derailment.cpp index 1b72db4cc..2f5d99592 100644 --- a/tests/unit/test_track_buckle_derailment.cpp +++ b/tests/unit/test_track_buckle_derailment.cpp @@ -51,8 +51,12 @@ derailment::outcome ride(track_buckle::shape const &Shape, double const Radius, derailment::monitor monitor; auto const velocity{Speed / 3.6}; auto const reach{track_buckle::reach(Shape) + Stock.pivots}; - for (auto at = Shape.centre - reach - 5.0; at <= Shape.centre + reach + 5.0; at += velocity * Step) + auto const start{Shape.centre - reach - 5.0}; + auto const advance{velocity * Step}; + auto const steps{static_cast(std::floor((2.0 * (reach + 5.0)) / advance))}; + for (auto step = 0; step <= steps; ++step) { + auto const at{start + step * advance}; derailment::track_state track; track.radius = Radius; auto const bend{track_buckle::body_bend(Shape, at, Stock.pivots, Stock.base)};