-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compare Arrays of Numbers, e.g. Floats #97
Comments
I guess another way would be to store the reference array in a, say, JLD or BSON file. Which is what is done already with pictures. I'd be happy to make a PR if this deemed a useful add-on. |
I haven't tried it but my guess is that JLD/BSON should just work. If it isn't then we might need to add some adaptors to https://github.com/JuliaTesting/ReferenceTests.jl/blob/master/src/fileio.jl |
Cool. So how do I use those files? Just by specifying the file extension? |
Yes, ReferenceTest delegates almost all the IO work to FileIO so as long as the format is registered in FileIO, it should be recognizable. |
Cool, this works:
So, I guess it's a documentation issue? I can add an example for this and maybe other backends. |
That would be great! (and if possible also a piece of test) We definitely need some rewrite of the docs using Documenter, which is currently an empty project. |
Do you know how to deal with JLD? This, and permutations, does not work:
the command for jld is
i.e. it needs both a name and a value. |
It seems that save("x.jld", Dict("x"=>[1, 2]))
@test_reference "x.jld" Dict("x"=>[1,2]) |
JLD2 worked out of the box for me: julia> A = rand(20);
julia> @test_reference "myref.jld2" Dict("A" => A) by=(r,a)->isapprox(r["A"], a["A"], rtol=0.1)
┌ Info: Reference file for "myref.jld2" did not exist. It has been created
└ new_reference = "/Users/funks/myref.jld2"
- NEW CONTENT -----------------
Dict{String, Vector{Float64}} with 1 entry:
"A" => [0.968553, 0.439909, 0.555604, 0.151386, 0.687479, 0.14697, 0.408348, …
-------------------------------
[ Info: Please run the tests again for any changes to take effect julia> @test_reference "myref.jld2" Dict("A" => 0.95 * A) by=(r,a)->isapprox(r["A"], a["A"], rtol=0.1)
Test Passed
Expression: true julia> @test_reference "myref.jld2" Dict("A" => 0.8 * A) by=(r,a)->isapprox(r["A"], a["A"], rtol=0.1)
┌ Info: Reference Test for "myref.jld2" failed.
│ reference = "/Users/funks/myref.jld2"
└ actual = "/var/folders/74/wcz8c9qs5dzc8wgkk7839k5c0000gn/T/jl_aRRSda/myref.jld2"
- REFERENCE -------------------
Dict{String, Vector{Float64}} with 1 entry:
"A" => [0.968553, 0.439909, 0.555604, 0.151386, 0.687479, 0.14697, 0.408348, …
-------------------------------
- ACTUAL ----------------------
Dict{String, Vector{Float64}} with 1 entry:
"A" => [0.774842, 0.351927, 0.444483, 0.121109, 0.549983, 0.117576, 0.326679,…
-------------------------------
Replace reference with actual result? [y/n]
n
Test Failed at /Users/funks/.julia/packages/ReferenceTests/ehVLM/src/test_reference.jl:158
Expression: false
ERROR: There was an error during testing However the error message could be improved, as it gets cut off after a couple of dictionary entries, making debugging harder. julia> A[end] = 42;
julia> @test_reference "myref.jld2" Dict("A" => A) by=(r,a)->isapprox(r["A"], a["A"], rtol=0.1)
┌ Info: Reference Test for "myref.jld2" failed.
│ reference = "/Users/funks/myref.jld2"
└ actual = "/var/folders/74/wcz8c9qs5dzc8wgkk7839k5c0000gn/T/jl_H4C9fc/myref.jld2"
- REFERENCE -------------------
Dict{String, Vector{Float64}} with 1 entry:
"A" => [0.968553, 0.439909, 0.555604, 0.151386, 0.687479, 0.14697, 0.408348, …
-------------------------------
- ACTUAL ----------------------
Dict{String, Vector{Float64}} with 1 entry:
"A" => [0.968553, 0.439909, 0.555604, 0.151386, 0.687479, 0.14697, 0.408348, …
-------------------------------
Replace reference with actual result? [y/n] |
Is there (or should there be) a way to compare arrays of floats? This would entail first parsing the string into floats to then compare the floats approximately. A hack looks like:
The text was updated successfully, but these errors were encountered: