|
1 | 1 | using Test |
2 | 2 | using AlgorithmsInterface |
| 3 | +using AlgorithmsInterface: Test as AIT |
3 | 4 | using Dates |
4 | 5 |
|
5 | | -struct DummyAlgorithm <: Algorithm |
6 | | - stopping_criterion::StoppingCriterion |
7 | | -end |
8 | | -struct DummyProblem <: Problem end |
9 | | -mutable struct DummyState{S <: StoppingCriterionState} <: State |
10 | | - stopping_criterion_state::S |
11 | | - iteration::Int |
12 | | -end |
13 | | - |
14 | | -problem = DummyProblem() |
| 6 | +problem = AIT.DummyProblem() |
15 | 7 |
|
16 | 8 | @testset "StopAfterIteration" begin |
17 | 9 | s1 = StopAfterIteration(2) |
18 | 10 | @test s1 isa StoppingCriterion |
19 | | - @test string(s1) == "StopAfterIteration(2)" |
20 | | - |
21 | | - algorithm = DummyAlgorithm(s1) |
| 11 | + @test repr(s1) == "StopAfterIteration(2)" |
| 12 | + @test !indicates_convergence(s1) |
| 13 | + algorithm = AIT.DummyAlgorithm(s1) |
22 | 14 | s1_state = initialize_state(problem, algorithm, s1) |
23 | | - state_finished = DummyState(s1_state, 2) |
24 | | - state_not_finished = DummyState(s1_state, 1) |
| 15 | + @test !indicates_convergence(s1, s1_state) |
| 16 | + state_finished = AIT.DummyState(s1_state, 2) |
| 17 | + state_not_finished = AIT.DummyState(s1_state, 1) |
25 | 18 | @test is_finished(problem, algorithm, state_finished) |
26 | 19 | @test !is_finished(problem, algorithm, state_not_finished) |
27 | 20 | end |
|
31 | 24 | @test s1 isa StoppingCriterion |
32 | 25 | @test string(s1) == "StopAfter(Second(1))" |
33 | 26 |
|
34 | | - algorithm = DummyAlgorithm(s1) |
| 27 | + algorithm = AIT.DummyAlgorithm(s1) |
35 | 28 | s1_state = initialize_state(problem, algorithm, s1) |
36 | | - state_not_finished = DummyState(s1_state, 1) |
| 29 | + state_not_finished = AIT.DummyState(s1_state, 1) |
37 | 30 | @test !is_finished(problem, algorithm, state_not_finished) |
38 | 31 | s1_state.time = Second(2) |
39 | 32 | @test is_finished(problem, algorithm, state_not_finished) |
40 | 33 | end |
41 | 34 |
|
42 | 35 | @testset "StopWhenAll" begin |
43 | 36 | s1 = StopAfterIteration(2) & StopAfter(Second(1)) |
| 37 | + s1b = StopWhenAll([StopAfterIteration(2), StopAfter(Second(1))]) |
| 38 | + @test s1 == s1b |
44 | 39 | @test s1 isa StoppingCriterion |
45 | 40 | @test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1) == |
46 | 41 | "StopWhenAll with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Second(1))" |
47 | 42 |
|
48 | | - algorithm = DummyAlgorithm(s1) |
| 43 | + algorithm = AIT.DummyAlgorithm(s1) |
49 | 44 | s1_state = initialize_state(problem, algorithm, s1) |
50 | | - state_not_finished = DummyState(s1_state, 1) |
| 45 | + state_not_finished = AIT.DummyState(s1_state, 1) |
51 | 46 | @test !is_finished(problem, algorithm, state_not_finished) |
52 | 47 | s1_state.criteria_states[2].time = Second(2) |
53 | 48 | @test !is_finished(problem, algorithm, state_not_finished) |
54 | 49 | state_not_finished.iteration = 2 |
55 | 50 | @test is_finished(problem, algorithm, state_not_finished) |
| 51 | + @test !indicates_convergence(s1) |
56 | 52 | end |
57 | 53 |
|
58 | 54 | @testset "StopWhenAny" begin |
|
61 | 57 | @test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1) == |
62 | 58 | "StopWhenAny with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Second(1))" |
63 | 59 |
|
64 | | - algorithm = DummyAlgorithm(s1) |
| 60 | + algorithm = AIT.DummyAlgorithm(s1) |
65 | 61 | s1_state = initialize_state(problem, algorithm, s1) |
66 | | - state_not_finished = DummyState(s1_state, 1) |
| 62 | + state_not_finished = AIT.DummyState(s1_state, 1) |
67 | 63 | @test !is_finished(problem, algorithm, state_not_finished) |
68 | 64 | s1_state.criteria_states[2].time = Second(2) |
69 | 65 | @test is_finished(problem, algorithm, state_not_finished) |
|
0 commit comments