Skip to content

Commit 8ed1347

Browse files
committed
Add tests for convergence history plot recipes
1 parent 4be8cc7 commit 8ed1347

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/history.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
11
using IterativeSolvers
2+
using RecipesBase
3+
using Base.Test
24

35
@testset "ConvergenceHistory" begin
46

7+
const KW = Dict{Symbol, Any}
8+
9+
RecipesBase.is_key_supported(k::Symbol) = k == :sep ? false : true
10+
11+
# No plottables
12+
begin
13+
history = ConvergenceHistory(partial = false)
14+
@test_throws ErrorException RecipesBase.apply_recipe(KW(), history)
15+
end
16+
17+
# Without restart markers
18+
begin
19+
history = ConvergenceHistory(partial = false)
20+
history.iters = 3
21+
history.data[:resnorm] = [10.0, 3.0, 0.1]
22+
23+
plots = (
24+
RecipesBase.apply_recipe(KW(), history),
25+
RecipesBase.apply_recipe(KW(), history, :resnorm)
26+
)
27+
28+
for data in plots
29+
@test length(data) == 1
30+
@test data[1].d[:label] == "resnorm"
31+
@test data[1].d[:seriestype] == :line
32+
end
33+
end
34+
35+
# With restart markers
36+
begin
37+
history = ConvergenceHistory(partial = false, restart = 2)
38+
history.iters = 3
39+
history.data[:resnorm] = [10.0, 3.0, 0.1]
40+
41+
plots = (
42+
RecipesBase.apply_recipe(KW(), history),
43+
RecipesBase.apply_recipe(KW(), history, :resnorm)
44+
)
45+
46+
for data in plots
47+
@test length(data) == 2
48+
@test data[2].d[:linecolor] == :white
49+
end
50+
end
51+
52+
# Custom color
53+
begin
54+
history = ConvergenceHistory(partial = false, restart = 2)
55+
history.iters = 3
56+
history.data[:resnorm] = [10.0, 3.0, 0.1]
57+
58+
plots = (
59+
RecipesBase.apply_recipe(KW(:sep => :red), history),
60+
RecipesBase.apply_recipe(KW(:sep => :red), history, :resnorm)
61+
)
62+
63+
for data in plots
64+
@test length(data) == 2
65+
@test data[2].d[:linecolor] == :red
66+
end
67+
end
568
end

0 commit comments

Comments
 (0)