Skip to content

Commit e456f0d

Browse files
committed
codecov++
1 parent c518f1b commit e456f0d

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

test/stopping_criterion.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ problem = AIT.DummyProblem()
2424
end
2525

2626
@testset "StopAfter" begin
27-
s1 = StopAfter(Second(1))
27+
s1 = StopAfter(Nanosecond(7))
2828
@test s1 isa StoppingCriterion
29-
@test string(s1) == "StopAfter(Second(1))"
29+
@test string(s1) == "StopAfter(Nanosecond(7))"
3030
@test_throws ArgumentError StopAfter(Second(-1))
3131

3232
algorithm = AIT.DummyAlgorithm(s1)
3333
s1_state = initialize_state(problem, algorithm, s1)
34-
alg_state = AIT.DummyState(s1_state, 1)
34+
alg_state = AIT.DummyState(s1_state, 0)
35+
# Iteration 0: Start timer
36+
@test !is_finished!(problem, algorithm, alg_state)
3537
@test !is_finished(problem, algorithm, alg_state)
36-
s1_state.time = Second(2)
38+
@test isnothing(get_reason(s1, s1_state))
39+
# Fake stop
40+
s1_state.time = Nanosecond(9)
41+
alg_state.iteration = 2
42+
@test is_finished!(problem, algorithm, alg_state)
3743
@test is_finished(problem, algorithm, alg_state)
38-
s1_state.at_iteration = 2
3944
@test startswith(get_reason(s1, s1_state), "After iteration 2")
4045
@test endswith(summary(s1, s1_state), " reached")
4146
end
@@ -64,13 +69,16 @@ end
6469
s1_state.criteria_states[2].start = Nanosecond(time_ns())
6570
s1_state.criteria_states[2].time = Nanosecond(7)
6671
# just time is not enough
72+
@test !is_finished!(problem, algorithm, alg_state)
6773
@test !is_finished(problem, algorithm, alg_state)
6874
alg_state.iteration = 2
6975
# but now both are
7076
@test is_finished!(problem, algorithm, alg_state)
7177
@test !indicates_convergence(s1)
7278
# check that reset works (a) check with modification
7379
@test is_finished!(problem, algorithm, alg_state)
80+
@test is_finished(problem, algorithm, alg_state)
81+
@test startswith(get_reason(s1, s1_state), "At iteration 2")
7482
@test alg_state.stopping_criterion_state.at_iteration > 0
7583
AlgorithmsInterface.initialize_state!(problem, algorithm, s1, s1_state)
7684
@test s1_state.criteria_states[1].at_iteration == -1
@@ -102,6 +110,7 @@ end
102110

103111
@test isnothing(AlgorithmsInterface.get_reason(s1, s1_state))
104112
alg_state = AIT.DummyState(s1_state, 1)
113+
@test !is_finished!(problem, algorithm, alg_state)
105114
@test !is_finished(problem, algorithm, alg_state)
106115
s1_state.criteria_states[2].time = Second(2)
107116
@test is_finished(problem, algorithm, alg_state)

0 commit comments

Comments
 (0)