@@ -6,6 +6,7 @@ module Main(main) where
66import qualified Codec.CBOR.FlatTerm as FlatTerm
77import Codec.Serialise (deserialiseOrFail , serialise )
88import qualified Codec.Serialise as Serialise
9+ import Control.Exception (ErrorCall , catch )
910import qualified Data.ByteString as BS
1011import Data.Either (isLeft )
1112import Hedgehog (MonadGen , Property , PropertyT , annotateShow , assert , forAll , property , tripping )
@@ -19,7 +20,7 @@ import PlutusTx.Ratio (Rational, denominator, numerator, recip, (
1920import PlutusTx.Sqrt (Sqrt (.. ), isqrt , rsqrt )
2021import Prelude hiding (Rational , negate , recip )
2122import Test.Tasty
22- import Test.Tasty.HUnit (testCase , (@?=) )
23+ import Test.Tasty.HUnit (Assertion , testCase , (@?=) )
2324import Test.Tasty.Hedgehog (testProperty )
2425
2526main :: IO ()
@@ -167,8 +168,16 @@ ratioTests = testGroup "Ratio"
167168 [ testProperty " reciprocal ordering 1" reciprocalOrdering1
168169 , testProperty " reciprocal ordering 2" reciprocalOrdering2
169170 , testProperty " reciprocal ordering 3" reciprocalOrdering3
171+ , testCase " recip 0 % 2 fails" reciprocalFailsZeroNumerator
170172 ]
171173
174+ -- We check that 'recip' throws an exception if the numerator is zero
175+ reciprocalFailsZeroNumerator :: Assertion
176+ reciprocalFailsZeroNumerator = do
177+ res <- catch (pure $! recip $ 0 % 2 ) $ \ (_ :: ErrorCall ) -> pure $ 1 % 1
178+ -- the result should be 1 % 1 if there was an exception
179+ res @?= (1 % 1 )
180+
172181genPositiveRational :: Monad m => PropertyT m Rational
173182genPositiveRational = do
174183 a <- forAll . Gen. integral $ Range. linear 1 100000
0 commit comments