File: Inspect.hs

package info (click to toggle)
haskell-generic-random 1.5.0.1-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: haskell: 1,066; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
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'