Skip to content

Commit 804710b

Browse files
committed
Add promotions tests
1 parent 07bf40f commit 804710b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

test/FixedDecimal.jl

+17-2
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ end
624624
@test FD{Int8,1}(2) / Int8(20) == FD{Int8,1}(0.1)
625625
end
626626

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

668-
@testset "Overflow corner cases" begin
668+
@testset "checked math corner cases" begin
669669
@testset for I in (Int128, UInt128, Int8, UInt8), f in (0,2)
670670
T = FD{I, f}
671671
issigned(I) = signed(I) === I
@@ -715,6 +715,21 @@ end
715715
issigned(I) && @test_throws OverflowError Base.checked_neg(typemin(T))
716716
end
717717
end
718+
719+
@testset "checked math promotions" begin
720+
x = FD{Int8,1}(1)
721+
y = FD{Int64,1}(2)
722+
@testset for op in (
723+
Base.checked_add, Base.checked_sub, Base.checked_mul, Base.checked_div,
724+
Base.checked_cld, Base.checked_fld, Base.checked_rem, Base.checked_mod,
725+
FixedPointDecimals.checked_decimal_division,
726+
)
727+
@test op(x, y) isa FD{Int64,1}
728+
@test op(x, y) == op(FD{Int64,1}(1), y)
729+
@test op(y, x) isa FD{Int64,1}
730+
@test op(y, x) == op(y, FD{Int64,1}(1))
731+
end
732+
end
718733
end
719734

720735
@testset "limits of $T" for T in CONTAINER_TYPES

0 commit comments

Comments
 (0)