Skip to content

Commit 250c089

Browse files
committed
Add RoundingMode tests
1 parent cbafd58 commit 250c089

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/runtests.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,54 @@ end
605605
@test round(Int, FD2(1.50)) === 2
606606
end
607607

608+
# Is alias for `ceil`.
609+
@testset "up" begin
610+
@test round(Int, FD2(-0.51), RoundUp) === 0
611+
@test round(Int, FD2(-0.50), RoundUp) === 0
612+
@test round(Int, FD2(-0.49), RoundUp) === 0
613+
@test round(Int, FD2(0.50), RoundUp) === 1
614+
@test round(Int, FD2(0.51), RoundUp) === 1
615+
@test round(Int, FD2(1.50), RoundUp) === 2
616+
end
617+
618+
# Is alias for `floor`.
619+
@testset "down" begin
620+
@test round(Int, FD2(-0.51), RoundDown) === -1
621+
@test round(Int, FD2(-0.50), RoundDown) === -1
622+
@test round(Int, FD2(-0.49), RoundDown) === -1
623+
@test round(Int, FD2(0.50), RoundDown) === 0
624+
@test round(Int, FD2(0.51), RoundDown) === 0
625+
@test round(Int, FD2(1.50), RoundDown) === 1
626+
end
627+
628+
# Is alias for `trunc`.
629+
@testset "to zero" begin
630+
@test round(Int, FD2(-0.51), RoundToZero) === 0
631+
@test round(Int, FD2(-0.50), RoundToZero) === 0
632+
@test round(Int, FD2(-0.49), RoundToZero) === 0
633+
@test round(Int, FD2(0.50), RoundToZero) === 0
634+
@test round(Int, FD2(0.51), RoundToZero) === 0
635+
@test round(Int, FD2(1.50), RoundToZero) === 1
636+
end
637+
638+
@testset "tie away" begin
639+
@test round(Int, FD2(-0.51), RoundNearestTiesAway) === -1
640+
@test round(Int, FD2(-0.50), RoundNearestTiesAway) === -1
641+
@test round(Int, FD2(-0.49), RoundNearestTiesAway) === 0
642+
@test round(Int, FD2(0.50), RoundNearestTiesAway) === 1
643+
@test round(Int, FD2(0.51), RoundNearestTiesAway) === 1
644+
@test round(Int, FD2(1.50), RoundNearestTiesAway) === 2
645+
end
646+
647+
@testset "tie up" begin
648+
@test round(Int, FD2(-0.51), RoundNearestTiesUp) === -1
649+
@test round(Int, FD2(-0.50), RoundNearestTiesUp) === 0
650+
@test round(Int, FD2(-0.49), RoundNearestTiesUp) === 0
651+
@test round(Int, FD2(0.50), RoundNearestTiesUp) === 1
652+
@test round(Int, FD2(0.51), RoundNearestTiesUp) === 1
653+
@test round(Int, FD2(1.50), RoundNearestTiesUp) === 2
654+
end
655+
608656
@testset "rounding invariant $x" for x in filter(!islarge, keyvalues[FD2])
609657
@test isinteger(round(x))
610658
@test x - FD2(1//2) round(x) x + FD2(1//2)

0 commit comments

Comments
 (0)