diff --git a/Tests/NumLib/TestFixedTimeStepping.cpp b/Tests/NumLib/TestFixedTimeStepping.cpp index 503777e8a16c1f0ecd0956b153ca3b22d6bb19cc..08813926e3a97f8d3c9469bde64146cb25059906 100644 --- a/Tests/NumLib/TestFixedTimeStepping.cpp +++ b/Tests/NumLib/TestFixedTimeStepping.cpp @@ -142,3 +142,56 @@ TEST_F(NumLibFixedTimeStepping, next) ac::check<std::vector<double>>( test, 1000, time_points, gtest_reporter, double_classifier); } + +TEST_F(NumLibFixedTimeStepping, next_StaticTest) +{ + std::vector<double> expected_time_points{}; + for (int i = 0; i < 101; ++i) + { + expected_time_points.push_back(i * 1e-2); + } + + std::vector<double> fixed_output_times{}; + for (int i = 0; i < 10; ++i) + { + fixed_output_times.push_back(i * 1e-1); + } + + double const t_initial = expected_time_points.front(); + + expected_time_points.erase(expected_time_points.begin()); + + double const t_end = expected_time_points.back(); + auto dts = transformTimesToDts(expected_time_points); + dts.front() -= t_initial; + auto const repeat_dt_pair = transformToRepeatDtPair(dts); + NumLib::FixedTimeStepping fixed_time_stepping{ + t_initial, t_end, repeat_dt_pair, fixed_output_times}; + + NumLib::TimeStep ts_dummy(0, 0, 0); + NumLib::TimeStep ts_current(0, t_initial, 0); + for (auto const& expected_time_point : expected_time_points) + { + auto [is_next, step_size] = + fixed_time_stepping.next(0.0 /* solution_error */, + 0 /* number_of_iterations */, + ts_dummy, + ts_current); + // this only happens if the last time step was processed or the + // current time is already at the end time up to machine precision + ASSERT_FALSE(!is_next && step_size != 0.0); + + // if the current time plus the computed step size minus the + // expected time is larger than the minimal time step size then the + // step size should be larger + // if next is true then the step + ASSERT_FALSE(is_next && std::abs((ts_current.current() + step_size) - + expected_time_point) > + NumLib::TimeStep::minimalTimeStepSize); + + // if next is true then the step size should be larger than zero + ASSERT_FALSE(is_next && step_size == 0.0); + ts_current += step_size; + } + ASSERT_EQ(ts_current.timeStepNumber(), dts.size()); +}