1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
{-# OPTIONS_GHC -dsuppress-all #-}
{-# LANGUAGE
DeriveGeneric,
TemplateHaskell
#-}
import GHC.Generics (Generic)
import Test.QuickCheck (Arbitrary(arbitrary), Gen, choose)
import Test.Inspection (inspect, (===))
import Generic.Random
arbMaybe :: Arbitrary a => Gen (Maybe a)
arbMaybe = genericArbitraryU
arbMaybe' :: Arbitrary a => Gen (Maybe a)
arbMaybe' = do
i <- choose (0, 1 :: Int)
if i < 1 then
pure Nothing
else
Just <$> arbitrary
data T = A | B | C Int [Bool]
deriving Generic
arbT :: Gen T
arbT = genericArbitrary (1 % 2 % 3 % ())
arbT' :: Gen T
arbT' = do
i <- choose (0, 5 :: Int)
if i < 1 then
pure A
else
if i - 1 < 2 then
pure B
else
C <$> arbitrary <*> arbitrary
main :: IO ()
main = pure ()
inspect $ 'arbMaybe === 'arbMaybe'
inspect $ 'arbT === 'arbT'
|