diff options
author | taylorfausak <taylor@fausak.me> | 2019-10-04 08:26:41 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-11-01 04:54:47 -0400 |
commit | baf47ff84f5fce832f7173febcac6d9b6b32631a (patch) | |
tree | 626f6120d129990999fba35b49da348da0d53f65 | |
parent | 3932fb97f59d78a91aaf99e7ea3ae04e6a5a10ea (diff) | |
download | haskell-baf47ff84f5fce832f7173febcac6d9b6b32631a.tar.gz |
Add tests for rounding ratios
-rw-r--r-- | testsuite/tests/numeric/should_run/T17303.hs | 41 | ||||
-rw-r--r-- | testsuite/tests/numeric/should_run/all.T | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/numeric/should_run/T17303.hs b/testsuite/tests/numeric/should_run/T17303.hs new file mode 100644 index 0000000000..5bb8e96a41 --- /dev/null +++ b/testsuite/tests/numeric/should_run/T17303.hs @@ -0,0 +1,41 @@ +import Control.Monad (when) +import Data.Ratio (Ratio, (%)) +import Numeric.Natural (Natural) + +infix 4 ~= +(~=) :: (Integral a, Show a) => Ratio a -> a -> IO () +ratio ~= expected = do + let actual = round ratio + when (actual /= expected) (fail (unwords + ["round", show ratio, "expected", show expected, "but got", show actual])) + +main :: IO () +main = do + + -12 % 6 ~= (-2 :: Integer) + -10 % 6 ~= (-2 :: Integer) + -9 % 6 ~= (-2 :: Integer) + -8 % 6 ~= (-1 :: Integer) + -6 % 6 ~= (-1 :: Integer) + -4 % 6 ~= (-1 :: Integer) + -3 % 6 ~= (0 :: Integer) + -2 % 6 ~= (0 :: Integer) + 0 % 6 ~= (0 :: Integer) + 2 % 6 ~= (0 :: Integer) + 3 % 6 ~= (0 :: Integer) + 4 % 6 ~= (1 :: Integer) + 6 % 6 ~= (1 :: Integer) + 8 % 6 ~= (1 :: Integer) + 9 % 6 ~= (2 :: Integer) + 10 % 6 ~= (2 :: Integer) + 12 % 6 ~= (2 :: Integer) + + 0 % 6 ~= (0 :: Natural) + 2 % 6 ~= (0 :: Natural) + 3 % 6 ~= (0 :: Natural) + 4 % 6 ~= (1 :: Natural) + 6 % 6 ~= (1 :: Natural) + 8 % 6 ~= (1 :: Natural) + 9 % 6 ~= (2 :: Natural) + 10 % 6 ~= (2 :: Natural) + 12 % 6 ~= (2 :: Natural) diff --git a/testsuite/tests/numeric/should_run/all.T b/testsuite/tests/numeric/should_run/all.T index de1f5bef14..f633c2e884 100644 --- a/testsuite/tests/numeric/should_run/all.T +++ b/testsuite/tests/numeric/should_run/all.T @@ -68,3 +68,4 @@ test('T11702', extra_ways(['optasm']), compile_and_run, ['']) test('T12136', normal, compile_and_run, ['']) test('T15301', normal, compile_and_run, ['-O2']) test('T497', normal, compile_and_run, ['-O']) +test('T17303', normal, compile_and_run, []) |