From 4dc17d2f14d9ff0e373a69b57e6dbbc42f15ef53 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Fri, 2 Dec 2016 17:37:01 -0500 Subject: [PATCH] Add missing test files Also fix a few deprecations identified by the tests --- src/VML.jl | 2 +- test/common.jl | 8 ++++---- test/complex.jl | 16 ++++++++++++++++ test/real.jl | 25 +++++++++++++++++++++++++ test/runtests.jl | 4 +++- 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 test/complex.jl create mode 100644 test/real.jl diff --git a/src/VML.jl b/src/VML.jl index b710531..9a854d0 100644 --- a/src/VML.jl +++ b/src/VML.jl @@ -25,7 +25,7 @@ function vml_check_error() vml_error = ccall((:_vmlClearErrStatus, lib), Cint, ()) if vml_error != 0 if vml_error == 1 - error(DomainError()) + throw(DomainError()) elseif vml_error == 2 || vml_error == 3 || vml_error == 4 # Singularity, overflow, or underflow # I don't think Base throws on these diff --git a/test/common.jl b/test/common.jl index d737da5..c437e43 100644 --- a/test/common.jl +++ b/test/common.jl @@ -67,8 +67,8 @@ const base_binary_complex = ( ) function randindomain{T<:Real}(t::Type{T}, n, domain) - d1 = oftype(t, domain[1]) - d2 = oftype(t, domain[2]) + d1 = convert(t, domain[1]) + d2 = convert(t, domain[2]) ddiff = d2 - d1 @assert isfinite(ddiff) v = rand(t, n) @@ -79,8 +79,8 @@ function randindomain{T<:Real}(t::Type{T}, n, domain) end function randindomain{T<:Complex}(t::Type{T}, n, domain) - d1 = oftype(t, domain[1]) - d2 = oftype(t, domain[2]) + d1 = convert(t, domain[1]) + d2 = convert(t, domain[2]) ddiff = d2 - d1 @assert isfinite(ddiff) v = rand(t, 2*n) diff --git a/test/complex.jl b/test/complex.jl new file mode 100644 index 0000000..b7560b8 --- /dev/null +++ b/test/complex.jl @@ -0,0 +1,16 @@ +# First generate some random data and test functions in Base on it +const NVALS = 1000 +input = Dict(t=>[[(randindomain(t, NVALS, domain),) for (fn, domain) in base_unary_complex]; + [(randindomain(t, NVALS, domain1), randindomain(t, NVALS, domain2)) + for (fn, domain1, domain2) in base_binary_complex]; + (randindomain(t, NVALS, (0, 100)), randindomain(t, 1, (-2, 10))[1])] + for t in (Complex64, Complex128)) +fns = [[x[1] for x in base_unary_complex]; [x[1] for x in base_binary_complex]; .^] +output = Dict(t=>[fns[i](input[t][i]...) for i = 1:length(fns)] for t in (Complex64, Complex128)) + +# Now test the same data with VML +using VML +for t in (Complex64, Complex128), i = 1:length(fns) + fn = fns[i] + Base.Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "VML $t $fn") +end diff --git a/test/real.jl b/test/real.jl new file mode 100644 index 0000000..d17bbc3 --- /dev/null +++ b/test/real.jl @@ -0,0 +1,25 @@ +# First generate some random data and test functions in Base on it +const NVALS = 1000 +input = Dict(t=>[[(randindomain(t, NVALS, domain),) for (fn, domain) in base_unary_real]; + [(randindomain(t, NVALS, domain1), randindomain(t, NVALS, domain2)) + for (fn, domain1, domain2) in base_binary_real]; + (randindomain(t, NVALS, (0, 100)), randindomain(t, 1, (-5, 20))[1])] + for t in (Float32, Float64)) +fns = [[x[1] for x in base_unary_real]; [x[1] for x in base_binary_real]; .^] +output = Dict(t=>[fns[i](input[t][i]...) for i = 1:length(fns)] for t in (Float32, Float64)) + +# Now test the same data with VML +using VML +for t in (Float32, Float64), i = 1:length(fns) + fn = fns[i] + Base.Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "VML $t $fn") +end + +# Verify that we still throw DomainErrors +Base.Test.@test_throws DomainError sqrt([-1.0]) + +# Setting accuracy +vml_set_accuracy(VML_LA) +@assert vml_get_accuracy() == VML_LA +vml_set_accuracy(VML_EP) +@assert vml_get_accuracy() == VML_EP diff --git a/test/runtests.jl b/test/runtests.jl index 688b71a..41cde16 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1 +1,3 @@ -include("common.jl") \ No newline at end of file +include("common.jl") +include("real.jl") +include("complex.jl")