@@ -5,12 +5,21 @@ using Dates
55struct DummyAlgorithm <: Algorithm
66 stopping_criterion:: StoppingCriterion
77end
8+
89struct DummyProblem <: Problem end
10+
911mutable struct DummyState{S <: StoppingCriterionState } <: State
1012 stopping_criterion_state:: S
1113 iteration:: Int
1214end
1315
16+ function AlgorithmsInterface. initialize_state (
17+ problem:: DummyProblem , algorithm:: DummyAlgorithm , stopping_criterion_state:: StoppingCriterionState ;
18+ kwargs...
19+ )
20+ return DummyState (stopping_criterion_state, 1 )
21+ end
22+
1423problem = DummyProblem ()
1524
1625@testset " StopAfterIteration" begin
@@ -19,11 +28,10 @@ problem = DummyProblem()
1928 @test string (s1) == " StopAfterIteration(2)"
2029
2130 algorithm = DummyAlgorithm (s1)
22- s1_state = initialize_state (problem, algorithm, s1)
23- state_finished = DummyState (s1_state, 2 )
24- state_not_finished = DummyState (s1_state, 1 )
25- @test is_finished (problem, algorithm, state_finished)
26- @test ! is_finished (problem, algorithm, state_not_finished)
31+ state = initialize_state (problem, algorithm)
32+ @test ! is_finished (problem, algorithm, state)
33+ AlgorithmsInterface. increment! (state)
34+ @test is_finished (problem, algorithm, state)
2735end
2836
2937@testset " StopAfter" begin
3240 @test string (s1) == " StopAfter(Second(1))"
3341
3442 algorithm = DummyAlgorithm (s1)
35- s1_state = initialize_state (problem, algorithm, s1)
36- state_not_finished = DummyState (s1_state, 1 )
37- @test ! is_finished (problem, algorithm, state_not_finished)
38- s1_state. time = Second (2 )
39- @test is_finished (problem, algorithm, state_not_finished)
43+ state = initialize_state (problem, algorithm)
44+ @test ! is_finished (problem, algorithm, state)
45+ state. stopping_criterion_state. time = Second (2 )
46+ @test is_finished (problem, algorithm, state)
4047end
4148
4249@testset " StopWhenAll" begin
4653 " StopWhenAll with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Second(1))"
4754
4855 algorithm = DummyAlgorithm (s1)
49- s1_state = initialize_state (problem, algorithm, s1)
50- state_not_finished = DummyState (s1_state, 1 )
51- @test ! is_finished (problem, algorithm, state_not_finished)
52- s1_state. criteria_states[2 ]. time = Second (2 )
53- @test ! is_finished (problem, algorithm, state_not_finished)
54- state_not_finished. iteration = 2
55- @test is_finished (problem, algorithm, state_not_finished)
56+ state = initialize_state (problem, algorithm)
57+ @test ! is_finished (problem, algorithm, state)
58+ state. stopping_criterion_state. criteria_states[2 ]. time = Second (2 )
59+ @test ! is_finished (problem, algorithm, state)
60+ AlgorithmsInterface. increment! (state)
61+ @test is_finished (problem, algorithm, state)
5662end
5763
5864@testset " StopWhenAny" begin
6268 " StopWhenAny with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Second(1))"
6369
6470 algorithm = DummyAlgorithm (s1)
65- s1_state = initialize_state (problem, algorithm, s1)
66- state_not_finished = DummyState (s1_state, 1 )
67- @test ! is_finished (problem, algorithm, state_not_finished)
68- s1_state. criteria_states[2 ]. time = Second (2 )
69- @test is_finished (problem, algorithm, state_not_finished)
70- state_not_finished. iteration = 2
71- @test is_finished (problem, algorithm, state_not_finished)
71+ state = initialize_state (problem, algorithm)
72+ @test ! is_finished (problem, algorithm, state)
73+ state. stopping_criterion_state. criteria_states[2 ]. time = Second (2 )
74+ @test is_finished (problem, algorithm, state)
75+ AlgorithmsInterface. increment! (state)
76+ @test is_finished (problem, algorithm, state)
7277end
0 commit comments