Skip to content

Commit f4019a4

Browse files
committed
Improve test coverage.
1 parent 2609d70 commit f4019a4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Manopt.jl

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ export StopAfter,
440440
StopWhenChangeLess,
441441
StopWhenCostLess,
442442
StopWhenCurvatureIsNegative,
443+
StopWhenEntryChangeLess,
443444
StopWhenGradientChangeLess,
444445
StopWhenGradientNormLess,
445446
StopWhenFirstOrderProgress,

src/plans/stopping_criterion.jl

+3
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ function update_stopping_criterion!(c::StopWhenEntryChangeLess, ::Val{:Threshold
397397
c.threshold = v
398398
return c
399399
end
400+
function show(io::IO, c::StopWhenEntryChangeLess)
401+
return print(io, "StopWhenEntryChangeLess\n $(status_summary(c))")
402+
end
400403

401404
@doc raw"""
402405
StopWhenGradientChangeLess <: StoppingCriterion

test/plans/test_stopping_criteria.jl

+10-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ end
5050
@testset "Test StopAfter" begin
5151
p = TestStopProblem()
5252
o = TestStopState()
53-
s = StopAfter(Second(1))
53+
s = StopAfter(Millisecond(30))
5454
@test !Manopt.indicates_convergence(s)
5555
@test Manopt.status_summary(s) == "stopped after $(s.threshold):\tnot reached"
56-
@test repr(s) == "StopAfter(Second(1))\n $(Manopt.status_summary(s))"
56+
@test repr(s) == "StopAfter(Millisecond(30))\n $(Manopt.status_summary(s))"
5757
s(p, o, 0) # Start
5858
@test s(p, o, 1) == false
59-
sleep(1.02)
59+
sleep(0.05)
6060
@test s(p, o, 2) == true
6161
@test_throws ErrorException StopAfter(Second(-1))
6262
@test_throws ErrorException update_stopping_criterion!(s, :MaxTime, Second(-1))
@@ -170,3 +170,10 @@ end
170170
update_stopping_criterion!(s1, :MinStepsize, 1e-1)
171171
@test s1.threshold == 1e-1
172172
end
173+
174+
@testset "Test further setters" begin
175+
swecl = StopWhenEntryChangeLess(:dummy, (p, s, v, w) -> norm(w - v), 1e-5)
176+
@test startswith(repr(swecl), "StopWhenEntryChangeLess\n")
177+
update_stopping_criterion!(swecl, :Threshold, 1e-1)
178+
@test swecl.threshold == 1e-1
179+
end

0 commit comments

Comments
 (0)