|
100 | 100 | end
|
101 | 101 | end
|
102 | 102 |
|
| 103 | + @testset "invalid" begin |
| 104 | + @test_throws InexactError convert(FD2, FD4(0.0001)) |
| 105 | + @test_throws InexactError convert(FD4, typemax(FD2)) |
| 106 | + @test_throws InexactError convert(SFD2, typemax(FD2)) |
| 107 | + @test_throws InexactError convert(FD2, 1//3) |
| 108 | + @test_throws InexactError convert(FD{Int8,1}, 1//4) |
| 109 | + end |
| 110 | + |
103 | 111 | @testset "limits of $T" for T in CONTAINER_TYPES
|
104 | 112 | f = FixedPointDecimals.max_exp10(T) + 1
|
105 | 113 | powt = FixedPointDecimals.coefficient(FD{T,f})
|
@@ -136,11 +144,24 @@ end
|
136 | 144 | @test_throws InexactError convert(FD{T,f}, min_int ÷ powt - T(1)) # Overflows with Unsigned
|
137 | 145 | end
|
138 | 146 |
|
139 |
| - @test_throws InexactError convert(FD2, FD4(0.0001)) |
140 |
| - @test_throws InexactError convert(FD4, typemax(FD2)) |
141 |
| - @test_throws InexactError convert(SFD2, typemax(FD2)) |
142 |
| - @test_throws InexactError convert(FD2, 1//3) |
143 |
| - @test_throws InexactError convert(FD{Int8,1}, 1//4) |
| 147 | + @testset "limits from $U to $T" for T in CONTAINER_TYPES, U in CONTAINER_TYPES |
| 148 | + f = FixedPointDecimals.max_exp10(T) + 1 |
| 149 | + g = FixedPointDecimals.max_exp10(U) + 1 |
| 150 | + powt = div( |
| 151 | + FixedPointDecimals.coefficient(FD{T, f}), |
| 152 | + FixedPointDecimals.coefficient(FD{U, g}), |
| 153 | + ) |
| 154 | + |
| 155 | + val = typemax(U) |
| 156 | + expected = widemul(typemax(U), powt) |
| 157 | + |
| 158 | + # Mixed usage of signed and unsigned types makes testing with typemin hard. |
| 159 | + if f >= g && expected <= typemax(T) |
| 160 | + @test convert(FD{T,f}, reinterpret(FD{U,g}, val)) == reinterpret(FD{T,f}, expected) |
| 161 | + else |
| 162 | + @test_throws InexactError convert(FD{T,f}, reinterpret(FD{U,g}, val)) |
| 163 | + end |
| 164 | + end |
144 | 165 | end
|
145 | 166 |
|
146 | 167 | @testset "promotion" begin
|
|
0 commit comments