{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Test.QuickCheck.Instances.Scientific () where
import Prelude ()
import Test.QuickCheck.Instances.CustomPrelude
import Test.QuickCheck
import qualified Data.Scientific as Scientific
instance Arbitrary Scientific.Scientific where
arbitrary :: Gen Scientific
arbitrary = do
Integer
c <- Gen Integer
forall a. Arbitrary a => Gen a
arbitrary
Int
e <- Gen Int
forall a. Arbitrary a => Gen a
arbitrary
Scientific -> Gen Scientific
forall a. a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return (Scientific -> Gen Scientific) -> Scientific -> Gen Scientific
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Scientific
Scientific.scientific Integer
c Int
e
shrink :: Scientific -> [Scientific]
shrink Scientific
s = ((Integer, Int) -> Scientific) -> [(Integer, Int)] -> [Scientific]
forall a b. (a -> b) -> [a] -> [b]
map ((Integer -> Int -> Scientific) -> (Integer, Int) -> Scientific
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> Scientific
Scientific.scientific) ([(Integer, Int)] -> [Scientific])
-> [(Integer, Int)] -> [Scientific]
forall a b. (a -> b) -> a -> b
$
(Integer, Int) -> [(Integer, Int)]
forall a. Arbitrary a => a -> [a]
shrink (Scientific -> Integer
Scientific.coefficient Scientific
s, Scientific -> Int
Scientific.base10Exponent Scientific
s)
instance CoArbitrary Scientific.Scientific where
coarbitrary :: forall b. Scientific -> Gen b -> Gen b
coarbitrary Scientific
s = (Integer, Int) -> Gen b -> Gen b
forall b. (Integer, Int) -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (Scientific -> Integer
Scientific.coefficient Scientific
s, Scientific -> Int
Scientific.base10Exponent Scientific
s)
instance Function Scientific.Scientific where
function :: forall b. (Scientific -> b) -> Scientific :-> b
function = (Scientific -> (Integer, Int))
-> ((Integer, Int) -> Scientific)
-> (Scientific -> b)
-> Scientific :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap
(\Scientific
s -> (Scientific -> Integer
Scientific.coefficient Scientific
s, Scientific -> Int
Scientific.base10Exponent Scientific
s))
((Integer -> Int -> Scientific) -> (Integer, Int) -> Scientific
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> Scientific
Scientific.scientific)