Reputation: 185
I am working on a set of functions in Julia and I have to develop a set of covering tests. I have one function that returns 3 values in a tuple.
How can I make a test such as:
@test_approx_eq_eps()
that will work on all three output values, all of which are floats?
Upvotes: 1
Views: 205
Reputation: 7893
Just use a loop in any of it's flavors:
julia> using Base.Test: @test_approx_eq_eps
julia> ns = tuple(ones(3)...)
(1.0, 1.0, 1.0)
julia> x = 1.0
1.0
julia> epsilon = 0.0
0.0
julia> for n in ns # simple loop
@test_approx_eq_eps n x epsilon
end
julia> [@test_approx_eq_eps(n, x, epsilon) for n in ns] # comprehension
3-element Array{Void,1}:
nothing
nothing
nothing
julia> foreach(ns) do n # foreach (doesn't return anything)
@test_approx_eq_eps n x epsilon
end
julia> test_aprox_eq_eps(n, x, epsilon) = @test_approx_eq_eps(n, x, epsilon)
test_aprox_eq_eps (generic function with 1 method)
julia> test_aprox_eq_eps.(ns, x, epsilon) # broadcasting
(nothing, nothing, nothing)
Upvotes: 2