代码如下:
using GraphPlot
using LightGraphs
using Colors
using Compose
using Base.Test
using VisualRegressionTests
# global variables
istravis = "TRAVIS" ∈ keys(ENV)
datadir = joinpath(@__DIR__, "data")
# graphs to test
g = graphfamous("karate")
h = LightGraphs.WheelGraph(10)
# plot and save function for visual regression tests
function plot_and_save(fname, g; gplot_kwargs...)
srand(2017)
draw(PNG(fname, 8inch, 8inch), gplot(g; gplot_kwargs...))
end
@testset "Karate Net" begin
# auxiliary variables
nodelabel = collect(1:nv(g))
nodesize = outdegree(g) .* 1.0
# test nodesize
plot_and_save1(fname) = plot_and_save(fname, g, nodesize=nodesize.^0.3, nodelabel=nodelabel, nodelabelsize=nodesize.^0.3)
refimg1 = joinpath(datadir, "karate_different_nodesize.png")
@test test_images(VisualTest(plot_and_save1, refimg1), popup=!istravis) |> success
# test directed graph
plot_and_save2(fname) = plot_and_save(fname, g, arrowlengthfrac=0.02, nodelabel=nodelabel)
refimg2 = joinpath(datadir, "karate_straight_directed.png")
@test test_images(VisualTest(plot_and_save2, refimg2), popup=!istravis) |> success
# test node membership
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]
nodecolor = [colorant"lightseagreen", colorant"orange"]
nodefillc = nodecolor[membership]
plot_and_save3(fname) = plot_and_save(fname, g, nodelabel=nodelabel, nodefillc=nodefillc)
refimg3 = joinpath(datadir, "karate_groups.png")
@test test_images(VisualTest(plot_and_save3, refimg3), popup=!istravis) |> success
end
@testset "WheelGraph" begin
# default options
plot_and_save1(fname) = plot_and_save(fname, h)
refimg1 = joinpath(datadir, "wheel10.png")
@test test_images(VisualTest(plot_and_save1, refimg1), popup=!istravis) |> success
end
源码地址:https://github.com/JuliaGraph...
第一次看到这样的代码,小白瑟瑟发抖,请教各位前辈jl代码怎么运行?还是借助python解释器?
小弟也看的瑟瑟发抖,但人家名字都表明是 julia 语言的代码,跟 python 没啥关系,用 julia 的运行环境去跑就是了。https://julialang.org/downloads/