Commit baf47ff8 authored by taylorfausak's avatar taylorfausak Committed by Marge Bot

Add tests for rounding ratios

parent 3932fb97
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)
......@@ -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, [])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment