@@ -45,77 +45,87 @@ h = Graphs.wheel_graph(10)
4545test_layout (g:: AbstractGraph ; kws... ) = spring_layout (g, 2017 , kws... )
4646
4747# plot and save function for visual regression tests
48- function plot_and_save (fname, g; gplot_kwargs... )
49- draw (PNG (fname, 8 inch, 8 inch), gplot (g; layout= test_layout, gplot_kwargs... ))
48+ # TODO visual regression tests are currently broken for higher Julia versions
49+ @static if VERSION < v " 1.7"
50+ function plot_and_save (fname, g; gplot_kwargs... )
51+ draw (PNG (fname, 8 inch, 8 inch), gplot (g; layout= test_layout, gplot_kwargs... ))
52+ end
53+
54+ function save_comparison (result:: VisualTestResult )
55+ grid = hcat (result. refImage, result. testImage)
56+ path = joinpath (datadir, string (basename (result. refFilename)[1 : end - length (" .png" )], " -comparison.png" ))
57+ ImageMagick. save (path, grid)
58+ return result
59+ end
5060end
5161
52- function save_comparison (result:: VisualTestResult )
53- grid = hcat (result. refImage, result. testImage)
54- path = joinpath (datadir, string (basename (result. refFilename)[1 : end - length (" .png" )], " -comparison.png" ))
55- ImageMagick. save (path, grid)
56- return result
57- end
58-
59- @testset " Karate Net" begin
60- # auxiliary variables
61- nodelabel = collect (1 : nv (g))
62- nodesize = outdegree (g) .* 1.0
62+ @static if VERSION < v " 1.7"
63+ @testset " Karate Net" begin
64+ # auxiliary variables
65+ nodelabel = collect (1 : nv (g))
66+ nodesize = outdegree (g) .* 1.0
6367
6468 # test nodesize
65- plot_and_save1 (fname) = plot_and_save (fname, g, nodesize= nodesize.^ 0.3 , nodelabel= nodelabel, nodelabelsize= nodesize.^ 0.3 )
66- refimg1 = joinpath (datadir, " karate_different_nodesize.png" )
67- @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
68-
69- # test directed graph
70- plot_and_save2 (fname) = plot_and_save (fname, g, arrowlengthfrac= 0.05 , nodelabel= nodelabel, font_family= " Sans" )
71- refimg2 = joinpath (datadir, " karate_straight_directed.png" )
72- @test test_images (VisualTest (plot_and_save2, refimg2), popup= ! istravis) |> save_comparison |> success
73-
74- # test node membership
75- membership = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,1 ,1 ,2 ,1 ,2 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ]
76- nodecolor = [colorant " lightseagreen" , colorant " orange" ]
77- nodefillc = nodecolor[membership]
78- plot_and_save3 (fname) = plot_and_save (fname, g, nodelabel= nodelabel, nodefillc= nodefillc)
79- refimg3 = joinpath (datadir, " karate_groups.png" )
80- @test test_images (VisualTest (plot_and_save3, refimg3), popup= ! istravis) |> save_comparison |> success
69+ plot_and_save1 (fname) = plot_and_save (fname, g, nodesize= nodesize.^ 0.3 , nodelabel= nodelabel, nodelabelsize= nodesize.^ 0.3 )
70+ refimg1 = joinpath (datadir, " karate_different_nodesize.png" )
71+ @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
72+
73+
74+ # test directed graph
75+ plot_and_save2 (fname) = plot_and_save (fname, g, arrowlengthfrac= 0.05 , nodelabel= nodelabel, font_family= " Sans" )
76+ refimg2 = joinpath (datadir, " karate_straight_directed.png" )
77+ @test test_images (VisualTest (plot_and_save2, refimg2), popup= ! istravis) |> save_comparison |> success
78+
79+ # test node membership
80+ membership = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,1 ,1 ,2 ,1 ,2 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ]
81+ nodecolor = [colorant " lightseagreen" , colorant " orange" ]
82+ nodefillc = nodecolor[membership]
83+
84+ plot_and_save3 (fname) = plot_and_save (fname, g, nodelabel= nodelabel, nodefillc= nodefillc)
85+ refimg3 = joinpath (datadir, " karate_groups.png" )
86+ @test test_images (VisualTest (plot_and_save3, refimg3), popup= ! istravis) |> save_comparison |> success
8187
8288 # test background color
83- plot_and_save4 (fname) = plot_and_save (fname, g, background_color= colorant " lightyellow" )
84- refimg4 = joinpath (datadir, " karate_background_color.png" )
85- @test test_images (VisualTest (plot_and_save4, refimg4), popup= ! istravis) |> save_comparison |> success
89+ plot_and_save4 (fname) = plot_and_save (fname, g, background_color= colorant " lightyellow" )
90+ refimg4 = joinpath (datadir, " karate_background_color.png" )
91+ @test test_images (VisualTest (plot_and_save4, refimg4), popup= ! istravis) |> save_comparison |> success
92+ end
8693end
8794
88- @testset " WheelGraph" begin
89- # default options
90- plot_and_save1 (fname) = plot_and_save (fname, h)
91- refimg1 = joinpath (datadir, " wheel10.png" )
92- @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
95+ @static if VERSION < v " 1.7"
96+ @testset " WheelGraph" begin
97+ # default options
98+ plot_and_save1 (fname) = plot_and_save (fname, h)
99+ refimg1 = joinpath (datadir, " wheel10.png" )
100+ @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
101+ end
93102end
94103
95- @testset " Curves" begin
104+ @static if VERSION < v " 1.7"
105+ @testset " Curves" begin
96106
97- g2 = DiGraph (2 )
98- add_edge! (g2, 1 ,2 )
99- add_edge! (g2, 2 ,1 )
107+ g2 = DiGraph (2 )
108+ add_edge! (g2, 1 ,2 )
109+ add_edge! (g2, 2 ,1 )
100110
101- plot_and_save1 (fname) = plot_and_save (fname, g2, linetype= " curve" , arrowlengthfrac= 0.2 , pad= 5 mm)
102- refimg1 = joinpath (datadir, " curve.png" )
103- @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
111+ plot_and_save1 (fname) = plot_and_save (fname, g2, linetype= " curve" , arrowlengthfrac= 0.2 , pad= 5 mm)
112+ refimg1 = joinpath (datadir, " curve.png" )
113+ @test test_images (VisualTest (plot_and_save1, refimg1), popup= ! istravis) |> save_comparison |> success
104114
105- g3 = DiGraph (2 )
106- add_edge! (g3, 1 ,1 )
107- add_edge! (g3, 1 ,2 )
108- add_edge! (g3, 2 ,1 )
109-
110- plot_and_save2 (fname) = plot_and_save (fname, g3, linetype= " curve" , arrowlengthfrac= 0.2 , leftpad= 20 mm, toppad= 3 mm, bottompad= 3 mm)
111- refimg2 = joinpath (datadir, " self_directed.png" )
112- @test test_images (VisualTest (plot_and_save2, refimg2), popup= ! istravis) |> save_comparison |> success
115+ g3 = DiGraph (2 )
116+ add_edge! (g3, 1 ,1 )
117+ add_edge! (g3, 1 ,2 )
118+ add_edge! (g3, 2 ,1 )
113119
120+ plot_and_save2 (fname) = plot_and_save (fname, g3, linetype= " curve" , arrowlengthfrac= 0.2 , leftpad= 20 mm, toppad= 3 mm, bottompad= 3 mm)
121+ refimg2 = joinpath (datadir, " self_directed.png" )
122+ @test test_images (VisualTest (plot_and_save2, refimg2), popup= ! istravis) |> save_comparison |> success
123+ end
114124end
115125
116126@testset " Spring Layout" begin
117127 g1 = path_digraph (3 )
118- x1, y1 = spring_layout (g1, 0 ; C = 1 )
128+ x1, y1 = spring_layout (g1, 0 ; C = 1 )
119129 @test all (isapprox .(x1, [1.0 , - 0.014799825222963192 , - 1.0 ]))
120130 @test all (isapprox .(y1, [- 1.0 , 0.014799825222963303 , 1.0 ]))
121131end
143153 x2,y2 = shell_layout (g,[[1 ,3 ,5 ],[2 ,4 ,6 ]])
144154 @test all (isapprox .(x2, [1.0 , 2.0 , - 0.4999999999999998 , - 0.9999999999999996 , - 0.5000000000000004 , - 1.0000000000000009 ]))
145155 @test all (isapprox .(y2, [0.0 , 0.0 , 0.8660254037844387 , 1.7320508075688774 , - 0.8660254037844385 , - 1.732050807568877 ]))
146- end
156+ end
0 commit comments