Skip to content

Commit

Permalink
Improve test coverage (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
waldyrious authored Jan 9, 2017
1 parent 87b98e9 commit a18437b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
using Tau
using Base.Test

# Basic tests
@test_broken tau == 2*pi
@test Float32(tau) == 2*Float32(pi)
@test Float64(Float32(tau)) == Float64(2*Float32(pi))
@test big(tau) == 2(big(pi))
@test isa(tau, Irrational)

# degree-based trig functions
# Test approximate results of degree-based trig functions
for T = (Float32,Float64)
for x = -2:0.1:2
@test_approx_eq_eps sintau(convert(T,x))::T convert(T,sin(tau*x)) eps(tau*convert(T,x))
@test_approx_eq_eps costau(convert(T,x))::T convert(T,cos(tau*x)) eps(tau*convert(T,x))
end
for x = 0.0:1.0:4.0
@test sintau(convert(T,x)) === zero(T)
@test sintau(-convert(T,x)) === -zero(T)
end

# Test exact results of passing integer values to sintau/costau
for T = (Int, Complex)
for x = -3:3
@test sintau(convert(T,x)) == zero(T)
@test costau(convert(T,x)) == one(T)
end
end

# Adapted from julia/test/math.jl
# Test exact results of passing integer values to sintau/costau as float types
for T = (Float32, Float64, BigFloat, Complex)
for x = -3.0:3.0
@test sintau(convert(T,x)) == sign(x)*zero(T)
@test costau(convert(T,x)) == one(T)
end
end

# check type stability
for T = (Float32,Float64,BigFloat)
# Check type stability of sintau/costau (adapted from julia/test/math.jl)
for T = (Int,Float32,Float64,BigFloat)
for f = (sintau,costau)
@test Base.return_types(f,Tuple{T}) == [T]
end
end

# Adapted from julia/test/mod2pi.jl
# Test passing Inf to sintau / costau
@test_throws DomainError sintau(Inf)
@test_throws DomainError costau(Inf)

# Test modtau (adapted from julia/test/mod2pi.jl)
@test_throws ArgumentError modtau(Int64(2)^60-1)

@test modtau(10) mod(10, tau)
@test modtau(-10) mod(-10, tau)
@test modtau(355) 3.1416227979431572

0 comments on commit a18437b

Please sign in to comment.