Skip to content

Commit 11ee5e1

Browse files
committed
Add @inferred tests for type stability of *.
Adds @inferred tests of several possible built-in FD representations that multiplication (even w/ two different types) is type stable. Before the last commit, this PR caused these tests to fail. For example: ``` (f1, f2) = (2, 4): Error During Test at /Users/nathan.daly/.julia/dev/FixedPointDecimals/test/runtests.jl:402 Test threw exception Expression: #= /Users/nathan.daly/.julia/dev/FixedPointDecimals/test/runtests.jl:402 =# @inferred(FD{T, f1}(1.1) * FD{T, f2}(1)) == FD{T, fmax}(1.1) return type FixedDecimal{UInt64,4} does not match inferred return type Any ``` After the last commit, these tests all pass.
1 parent 189ec07 commit 11ee5e1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ end
390390
@test reinterpret(FD{T,f}, min_int) * scalar ==
391391
reinterpret(FD{T,f}, div(min_int, 10))
392392
end
393+
394+
# Test that multiplication is type stable for all the basic integer types.
395+
@testset "type stable" begin
396+
fs = [0, 1, 2, 4, 8, 16, 38] # To save time, don't test all possible combinations.
397+
@testset for T in CONTAINER_TYPES
398+
maxF = FixedPointDecimals.max_exp10(T)
399+
frange = filter(f->f<=maxF, fs)
400+
@testset for (f1,f2) in Iterators.product(frange, frange)
401+
fmax = max(f1,f2)
402+
@test @inferred(FD{T,f1}(1) * FD{T,f2}(1)) == FD{T,fmax}(1)
403+
end
404+
end
405+
end
393406
end
394407

395408
@testset "division" begin

0 commit comments

Comments
 (0)