Skip to content

Commit

Permalink
Add promotions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Dec 9, 2023
1 parent 07bf40f commit 804710b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/FixedDecimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ end
@test FD{Int8,1}(2) / Int8(20) == FD{Int8,1}(0.1)
end

@testset "limits: overflow" begin
@testset "limits: overflow checked math" begin
# Easy to reason about cases of overflow:
@test_throws OverflowError Base.checked_add(FD{Int8,2}(1), FD{Int8,2}(1))
@test_throws OverflowError Base.checked_add(FD{Int8,2}(1), 1)
Expand Down Expand Up @@ -665,7 +665,7 @@ end
@test Base.checked_abs(typemax(FD{Int8,2})) == FD{Int8,2}(1.27)
@test Base.checked_neg(typemax(FD{Int8,2})) == FD{Int8,2}(-1.27)

@testset "Overflow corner cases" begin
@testset "checked math corner cases" begin
@testset for I in (Int128, UInt128, Int8, UInt8), f in (0,2)
T = FD{I, f}
issigned(I) = signed(I) === I
Expand Down Expand Up @@ -715,6 +715,21 @@ end
issigned(I) && @test_throws OverflowError Base.checked_neg(typemin(T))
end
end

@testset "checked math promotions" begin
x = FD{Int8,1}(1)
y = FD{Int64,1}(2)
@testset for op in (
Base.checked_add, Base.checked_sub, Base.checked_mul, Base.checked_div,
Base.checked_cld, Base.checked_fld, Base.checked_rem, Base.checked_mod,
FixedPointDecimals.checked_decimal_division,
)
@test op(x, y) isa FD{Int64,1}
@test op(x, y) == op(FD{Int64,1}(1), y)
@test op(y, x) isa FD{Int64,1}
@test op(y, x) == op(y, FD{Int64,1}(1))
end
end
end

@testset "limits of $T" for T in CONTAINER_TYPES
Expand Down

0 comments on commit 804710b

Please sign in to comment.