use StableRNGs for testing
This commit is contained in:
parent
96ec035811
commit
0b31e26007
@ -49,6 +49,7 @@ RecipesPipeline = "0.1.7"
|
|||||||
Reexport = "0.2"
|
Reexport = "0.2"
|
||||||
Requires = "1"
|
Requires = "1"
|
||||||
Showoff = "0.3.1"
|
Showoff = "0.3.1"
|
||||||
|
StableRNGs = "0.1.1"
|
||||||
StatsBase = "0.32, 0.33"
|
StatsBase = "0.32, 0.33"
|
||||||
julia = "1"
|
julia = "1"
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
|||||||
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
|
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
|
||||||
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
|
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
|
||||||
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
|
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
|
||||||
|
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
|
||||||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||||
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
|
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
|
||||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
@ -70,4 +72,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
|
|||||||
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
|
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
|
||||||
|
|
||||||
[targets]
|
[targets]
|
||||||
test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"]
|
test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"]
|
||||||
|
|||||||
@ -1,5 +1,21 @@
|
|||||||
import Plots._current_plots_version
|
import Plots._current_plots_version
|
||||||
|
|
||||||
|
# replace `f(args...)` with `f(rng, args...)` for `f ∈ (rand, randn)`
|
||||||
|
function replace_rand!(ex) end
|
||||||
|
function replace_rand!(ex::Expr)
|
||||||
|
for arg in ex.args
|
||||||
|
replace_rand!(arg)
|
||||||
|
end
|
||||||
|
if ex.head === :call && ex.args[1] ∈ (:rand, :randn)
|
||||||
|
pushfirst!(ex.args, ex.args[1])
|
||||||
|
ex.args[2] = :rng
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function fix_rand!(ex)
|
||||||
|
replace_rand!(ex)
|
||||||
|
pushfirst!(ex.args[1].args, :(rng = StableRNG(1234)))
|
||||||
|
end
|
||||||
|
|
||||||
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !is_ci(), sigma = [1,1], tol = 1e-2)
|
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !is_ci(), sigma = [1,1], tol = 1e-2)
|
||||||
Plots._debugMode.on = debug
|
Plots._debugMode.on = debug
|
||||||
example = Plots._examples[idx]
|
example = Plots._examples[idx]
|
||||||
@ -8,8 +24,6 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !i
|
|||||||
backend(pkg)
|
backend(pkg)
|
||||||
backend()
|
backend()
|
||||||
default(size=(500,300))
|
default(size=(500,300))
|
||||||
# ensure consistent results
|
|
||||||
Random.seed!(1234)
|
|
||||||
|
|
||||||
fn = "ref$idx.png"
|
fn = "ref$idx.png"
|
||||||
reffn = reference_file(pkg, idx, _current_plots_version)
|
reffn = reference_file(pkg, idx, _current_plots_version)
|
||||||
@ -19,6 +33,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !i
|
|||||||
func = (fn, idx) -> begin
|
func = (fn, idx) -> begin
|
||||||
expr = Expr(:block)
|
expr = Expr(:block)
|
||||||
append!(expr.args, example.exprs)
|
append!(expr.args, example.exprs)
|
||||||
|
fix_rand!(expr)
|
||||||
eval(expr)
|
eval(expr)
|
||||||
png(fn)
|
png(fn)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import ImageMagick
|
|||||||
using VisualRegressionTests
|
using VisualRegressionTests
|
||||||
using Plots
|
using Plots
|
||||||
using Random
|
using Random
|
||||||
|
using StableRNGs
|
||||||
using Test
|
using Test
|
||||||
using FileIO
|
using FileIO
|
||||||
using Gtk
|
using Gtk
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user