Skip to content

Commit bd97c48

Browse files
authored
Merge pull request #11 from JuliaMath/sjk/fix-tests
Add missing test files
2 parents 9cbd53c + 4dc17d2 commit bd97c48

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

src/VML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function vml_check_error()
2525
vml_error = ccall((:_vmlClearErrStatus, lib), Cint, ())
2626
if vml_error != 0
2727
if vml_error == 1
28-
error(DomainError())
28+
throw(DomainError())
2929
elseif vml_error == 2 || vml_error == 3 || vml_error == 4
3030
# Singularity, overflow, or underflow
3131
# I don't think Base throws on these

test/common.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const base_binary_complex = (
6767
)
6868

6969
function randindomain{T<:Real}(t::Type{T}, n, domain)
70-
d1 = oftype(t, domain[1])
71-
d2 = oftype(t, domain[2])
70+
d1 = convert(t, domain[1])
71+
d2 = convert(t, domain[2])
7272
ddiff = d2 - d1
7373
@assert isfinite(ddiff)
7474
v = rand(t, n)
@@ -79,8 +79,8 @@ function randindomain{T<:Real}(t::Type{T}, n, domain)
7979
end
8080

8181
function randindomain{T<:Complex}(t::Type{T}, n, domain)
82-
d1 = oftype(t, domain[1])
83-
d2 = oftype(t, domain[2])
82+
d1 = convert(t, domain[1])
83+
d2 = convert(t, domain[2])
8484
ddiff = d2 - d1
8585
@assert isfinite(ddiff)
8686
v = rand(t, 2*n)

test/complex.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# First generate some random data and test functions in Base on it
2+
const NVALS = 1000
3+
input = Dict(t=>[[(randindomain(t, NVALS, domain),) for (fn, domain) in base_unary_complex];
4+
[(randindomain(t, NVALS, domain1), randindomain(t, NVALS, domain2))
5+
for (fn, domain1, domain2) in base_binary_complex];
6+
(randindomain(t, NVALS, (0, 100)), randindomain(t, 1, (-2, 10))[1])]
7+
for t in (Complex64, Complex128))
8+
fns = [[x[1] for x in base_unary_complex]; [x[1] for x in base_binary_complex]; .^]
9+
output = Dict(t=>[fns[i](input[t][i]...) for i = 1:length(fns)] for t in (Complex64, Complex128))
10+
11+
# Now test the same data with VML
12+
using VML
13+
for t in (Complex64, Complex128), i = 1:length(fns)
14+
fn = fns[i]
15+
Base.Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "VML $t $fn")
16+
end

test/real.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# First generate some random data and test functions in Base on it
2+
const NVALS = 1000
3+
input = Dict(t=>[[(randindomain(t, NVALS, domain),) for (fn, domain) in base_unary_real];
4+
[(randindomain(t, NVALS, domain1), randindomain(t, NVALS, domain2))
5+
for (fn, domain1, domain2) in base_binary_real];
6+
(randindomain(t, NVALS, (0, 100)), randindomain(t, 1, (-5, 20))[1])]
7+
for t in (Float32, Float64))
8+
fns = [[x[1] for x in base_unary_real]; [x[1] for x in base_binary_real]; .^]
9+
output = Dict(t=>[fns[i](input[t][i]...) for i = 1:length(fns)] for t in (Float32, Float64))
10+
11+
# Now test the same data with VML
12+
using VML
13+
for t in (Float32, Float64), i = 1:length(fns)
14+
fn = fns[i]
15+
Base.Test.test_approx_eq(output[t][i], fn(input[t][i]...), "Base $t $fn", "VML $t $fn")
16+
end
17+
18+
# Verify that we still throw DomainErrors
19+
Base.Test.@test_throws DomainError sqrt([-1.0])
20+
21+
# Setting accuracy
22+
vml_set_accuracy(VML_LA)
23+
@assert vml_get_accuracy() == VML_LA
24+
vml_set_accuracy(VML_EP)
25+
@assert vml_get_accuracy() == VML_EP

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
include("common.jl")
1+
include("common.jl")
2+
include("real.jl")
3+
include("complex.jl")

0 commit comments

Comments
 (0)