|
605 | 605 | @test round(Int, FD2(1.50)) === 2
|
606 | 606 | end
|
607 | 607 |
|
| 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 | + |
608 | 656 | @testset "rounding invariant $x" for x in filter(!islarge, keyvalues[FD2])
|
609 | 657 | @test isinteger(round(x))
|
610 | 658 | @test x - FD2(1//2) ≤ round(x) ≤ x + FD2(1//2)
|
|
0 commit comments