Skip to content

Adds tests for Type Stability of FD functions. #48

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Feb 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,36 @@ epsi(::Type{T}) where T = eps(T)
end
end

@testset "type stability" begin
# Test that basic operations are type stable for all the basic integer types.
fs = [0, 1, 2, 7, 16, 38] # To save time, don't test all possible combinations.
@testset for T in (CONTAINER_TYPES..., BigInt,)
maxF = FixedPointDecimals.max_exp10(T)
frange = filter(f->f<=maxF, fs)
# Unary operations
@testset for f in frange
@test @inferred(zero(FD{T,f}(1))) === FD{T,f}(0)
@test @inferred(one(FD{T,f}(1))) === FD{T,f}(1)
@test @inferred(ceil(FD{T,f}(1))) === FD{T,f}(1)
@test @inferred(round(FD{T,f}(1))) === FD{T,f}(1)
@test @inferred(abs(FD{T,f}(1))) === FD{T,f}(1)
@test @inferred(FD{T,f}(1)^2) === FD{T,f}(1)
@test @inferred(typemax(FD{T,f})) isa FD{T,f}
end
# Binary operations
@testset for (f1,f2) in Iterators.product(frange, frange)
fmax = max(f1,f2)
@test @inferred(FD{T,f1}(1) + FD{T,f2}(0)) === FD{T,fmax}(1)
@test @inferred(FD{T,f1}(1) - FD{T,f2}(0)) === FD{T,fmax}(1)
@test @inferred(FD{T,f1}(1) * FD{T,f2}(1)) === FD{T,fmax}(1)
@test @inferred(FD{T,f1}(1) / FD{T,f2}(1)) === FD{T,fmax}(1)
@test @inferred(FD{T,f1}(1) ÷ FD{T,f2}(1)) === FD{T,fmax}(1)
@test @inferred(max(FD{T,f1}(1), FD{T,f2}(0))) === FD{T,fmax}(1)
@test @inferred(min(FD{T,f1}(1), FD{T,f2}(0))) === FD{T,fmax}(0)
end
end
end

@testset "print" begin
@test string(FD2(1.00)) == "1.00"
@test string(FD2(1.23)) == "1.23"
Expand Down