Skip to content

Commit 6af1829

Browse files
committed
F64D in conversion tests
1 parent 0bfde60 commit 6af1829

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

test/FixedDecimal.jl

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,22 @@ end
255255

256256
@testset "128-bit conversion correctness" begin
257257
# Force the bits for these tests
258-
FD2 = FixedDecimal{Int64, 2}
259-
UFD2 = FixedDecimal{UInt64, 2}
258+
F64D2 = FixedDecimal{Int64, 2}
259+
UF64D2 = FixedDecimal{UInt64, 2}
260260

261261
@testset "Convert from 64-bit to 128-bit" begin
262262
@test convert(WFD2, 1).i === Int128(100)
263263
@test convert(UWFD2, 1).i === UInt128(100)
264264
@test convert(WFD2, -1).i === Int128(-100)
265265
@test_throws InexactError(:convert, UWFD2, -1) convert(UWFD2, -1)
266-
@test convert(WFD2, UInt(1)).i === Int128(100)
267-
@test convert(UWFD2, UInt(1)).i === UInt128(100)
268-
@test convert(WFD2, typemax(Int)).i === Int128(922337203685477580700)
269-
@test convert(UWFD2, typemax(Int)).i === UInt128(922337203685477580700)
270-
@test convert(WFD2, typemin(Int)).i === Int128(-922337203685477580800)
271-
@test_throws InexactError(:convert, UWFD2, typemin(Int)) convert(UWFD2, typemin(Int))
272-
@test convert(WFD2, typemax(UInt)).i === Int128(1844674407370955161500)
273-
@test convert(UWFD2, typemax(UInt)).i === UInt128(1844674407370955161500)
266+
@test convert(WFD2, UInt64(1)).i === Int128(100)
267+
@test convert(UWFD2, UInt64(1)).i === UInt128(100)
268+
@test convert(WFD2, typemax(Int64)).i === Int128(922337203685477580700)
269+
@test convert(UWFD2, typemax(Int64)).i === UInt128(922337203685477580700)
270+
@test convert(WFD2, typemin(Int64)).i === Int128(-922337203685477580800)
271+
@test_throws InexactError(:convert, UWFD2, typemin(Int64)) convert(UWFD2, typemin(Int64))
272+
@test convert(WFD2, typemax(UInt64)).i === Int128(1844674407370955161500)
273+
@test convert(UWFD2, typemax(UInt64)).i === UInt128(1844674407370955161500)
274274
end
275275

276276
@testset "Convert from 128-bit to 128-bit" begin
@@ -289,18 +289,18 @@ end
289289
end
290290

291291
@testset "Convert from 128-bit to 64-bit" begin
292-
@test convert(FD2, Int128(1)).i === Int(100)
293-
@test convert(UFD2, Int128(1)).i === UInt(100)
294-
@test convert(FD2, UInt128(1)).i === Int(100)
295-
@test convert(UFD2, UInt128(1)).i === UInt(100)
296-
@test convert(FD2, Int128(-1)).i === Int(-100)
297-
@test_throws InexactError(:convert, UFD2, Int128(-1)) convert(UFD2, Int128(-1))
298-
@test_throws InexactError(:convert, FD2, typemax(Int128)) convert(FD2, typemax(Int128))
299-
@test_throws InexactError(:convert, UFD2, typemax(Int128)) convert(UFD2, typemax(Int128))
300-
@test_throws InexactError(:convert, FD2, typemin(Int128)) convert(FD2, typemin(Int128))
301-
@test_throws InexactError(:convert, UFD2, typemin(Int128)) convert(UFD2, typemin(Int128))
302-
@test_throws InexactError(:convert, FD2, typemax(UInt128)) convert(FD2, typemax(UInt128))
303-
@test_throws InexactError(:convert, UFD2, typemax(UInt128)) convert(UFD2, typemax(UInt128))
292+
@test convert(F64D2, Int128(1)).i === Int64(100)
293+
@test convert(UF64D2, Int128(1)).i === UInt64(100)
294+
@test convert(F64D2, UInt128(1)).i === Int64(100)
295+
@test convert(UF64D2, UInt128(1)).i === UInt64(100)
296+
@test convert(F64D2, Int128(-1)).i === Int64(-100)
297+
@test_throws InexactError(:convert, UF64D2, Int128(-1)) convert(UFD2, Int128(-1))
298+
@test_throws InexactError(:convert, F64D2, typemax(Int128)) convert(F64D2, typemax(Int128))
299+
@test_throws InexactError(:convert, UF64D2, typemax(Int128)) convert(UF64D2, typemax(Int128))
300+
@test_throws InexactError(:convert, F64D2, typemin(Int128)) convert(F64D2, typemin(Int128))
301+
@test_throws InexactError(:convert, UF64D2, typemin(Int128)) convert(UF64D2, typemin(Int128))
302+
@test_throws InexactError(:convert, F64D2, typemax(UInt128)) convert(F64D2, typemax(UInt128))
303+
@test_throws InexactError(:convert, UF64D2, typemax(UInt128)) convert(UF64D2, typemax(UInt128))
304304
end
305305

306306
@testset "Convert from BigInt to 128-bit" begin
@@ -333,19 +333,16 @@ using FixedPointDecimals
333333

334334
const SFD2 = FixedDecimal{Int16, 2}
335335
const SFD4 = FixedDecimal{Int16, 4}
336-
const FD1 = FixedDecimal{Int, 1}
337-
const FD2 = FixedDecimal{Int, 2}
338-
const FD3 = FixedDecimal{Int, 3}
339-
const FD4 = FixedDecimal{Int, 4}
336+
const F64D2 = FixedDecimal{Int64, 2}
337+
const UF64D2 = FixedDecimal{UInt64, 2}
340338
const WFD2 = FixedDecimal{Int128, 2}
341-
const WFD4 = FixedDecimal{Int128, 4}
342339
const UFD2 = FixedDecimal{UInt, 2}
343340
const UWFD2 = FixedDecimal{UInt128, 2}
344341

345342
@testset "128-bit conversion performance" begin
346343
# Baseline cases
347-
@test @allocated(convert(FD2, Int8(-1))) == 0
348-
@test @allocated(convert(FD2, UInt8(1))) == 0
344+
@test @allocated(convert(F64D2, Int8(-1))) == 0
345+
@test @allocated(convert(F64D2, UInt8(1))) == 0
349346
@test @allocated(convert(SFD2, Int8(-1))) == 0
350347

351348
# Int 128 cases
@@ -363,11 +360,11 @@ const UWFD2 = FixedDecimal{UInt128, 2}
363360
@test @allocated(convert(UWFD2, UInt128(1))) == 0
364361
@test @allocated(convert(WFD2, Int128(-1))) == 0
365362

366-
@test @allocated(convert(FD2, Int128(1))) == 0
367-
@test @allocated(convert(UFD2, Int128(1))) == 0
368-
@test @allocated(convert(FD2, UInt128(1))) == 0
369-
@test @allocated(convert(UFD2, UInt128(1))) == 0
370-
@test @allocated(convert(FD2, Int128(-1))) == 0
363+
@test @allocated(convert(F64D2, Int128(1))) == 0
364+
@test @allocated(convert(UF64D2, Int128(1))) == 0
365+
@test @allocated(convert(F64D2, UInt128(1))) == 0
366+
@test @allocated(convert(UF64D2, UInt128(1))) == 0
367+
@test @allocated(convert(F64D2, Int128(-1))) == 0
371368
end
372369

373370
@testset "BigInt conversion performance" begin

0 commit comments

Comments
 (0)