{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
#ifndef NO_GENERICS
{-# LANGUAGE DefaultSignatures, FlexibleContexts, TypeOperators #-}
{-# LANGUAGE FlexibleInstances, KindSignatures, ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
#if __GLASGOW_HASKELL__ >= 710
#define OVERLAPPING_ {-# OVERLAPPING #-}
#else
{-# LANGUAGE OverlappingInstances #-}
#define OVERLAPPING_
#endif
#endif
#ifndef NO_POLYKINDS
{-# LANGUAGE PolyKinds #-}
#endif
#ifndef NO_SAFE_HASKELL
{-# LANGUAGE Trustworthy #-}
#endif
#ifndef NO_NEWTYPE_DERIVING
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
#endif
module Test.QuickCheck.Arbitrary
(
Arbitrary(..)
, CoArbitrary(..)
, Arbitrary1(..)
, arbitrary1
, shrink1
, Arbitrary2(..)
, arbitrary2
, shrink2
, applyArbitrary2
, applyArbitrary3
, applyArbitrary4
, arbitrarySizedIntegral
, arbitrarySizedNatural
, arbitraryBoundedIntegral
, arbitrarySizedBoundedIntegral
, arbitrarySizedFractional
, arbitraryBoundedRandom
, arbitraryBoundedEnum
, arbitraryUnicodeChar
, arbitraryASCIIChar
, arbitraryPrintableChar
#ifndef NO_GENERICS
, RecursivelyShrink
, GSubterms
, genericShrink
, subterms
, recursivelyShrink
, genericCoarbitrary
#endif
, shrinkNothing
, shrinkList
, shrinkMap
, shrinkMapBy
, shrinkIntegral
, shrinkRealFrac
, shrinkBoundedEnum
, shrinkDecimal
, coarbitraryIntegral
, coarbitraryReal
, coarbitraryShow
, coarbitraryEnum
, (><)
, vector
, orderedList
, infiniteList
)
where
import Control.Applicative
import Data.Foldable(toList)
import System.Random(Random)
import Test.QuickCheck.Gen
import Test.QuickCheck.Random
import Test.QuickCheck.Gen.Unsafe
import Data.Char
( ord
, isLower
, isUpper
, toLower
, isDigit
, isSpace
, isPrint
, generalCategory
, GeneralCategory(..)
)
#ifndef NO_FIXED
import Data.Fixed
( Fixed
, HasResolution
)
#endif
import Data.Ratio
( Ratio
, (%)
, numerator
, denominator
)
import Data.Complex
( Complex((:+)) )
import Data.List
( sort
, nub
)
import Data.Version (Version (..))
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,2,0)
import System.IO
( Newline(..)
, NewlineMode(..)
)
#endif
#endif
import Control.Monad
( liftM
, liftM2
, liftM3
, liftM4
, liftM5
)
import Data.Int(Int8, Int16, Int32, Int64)
import Data.Word(Word, Word8, Word16, Word32, Word64)
import System.Exit (ExitCode(..))
import Foreign.C.Types
#ifndef NO_GENERICS
import GHC.Generics
#endif
import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Data.IntSet as IntSet
import qualified Data.IntMap as IntMap
import qualified Data.Sequence as Sequence
import qualified Data.Tree as Tree
import Data.Bits
import qualified Data.Monoid as Monoid
#ifndef NO_TRANSFORMERS
import Data.Functor.Identity
import Data.Functor.Constant
import Data.Functor.Compose
import Data.Functor.Product
#endif
class Arbitrary a where
arbitrary :: Gen a
shrink :: a -> [a]
shrink a
_ = []
class Arbitrary1 f where
liftArbitrary :: Gen a -> Gen (f a)
liftShrink :: (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
_ f a
_ = []
arbitrary1 :: (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1 :: forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1 = forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink1 :: (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1 :: forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1 = forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink forall a. Arbitrary a => a -> [a]
shrink
class Arbitrary2 f where
liftArbitrary2 :: Gen a -> Gen b -> Gen (f a b)
liftShrink2 :: (a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
_ b -> [b]
_ f a b
_ = []
arbitrary2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => Gen (f a b)
arbitrary2 :: forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
Gen (f a b)
arbitrary2 = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => f a b -> [f a b]
shrink2 :: forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
f a b -> [f a b]
shrink2 = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 forall a. Arbitrary a => a -> [a]
shrink forall a. Arbitrary a => a -> [a]
shrink
#ifndef NO_GENERICS
genericShrink :: (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a]
genericShrink :: forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink a
x = forall a. (Generic a, GSubterms (Rep a) a) => a -> [a]
subterms a
x forall a. [a] -> [a] -> [a]
++ forall a. (Generic a, RecursivelyShrink (Rep a)) => a -> [a]
recursivelyShrink a
x
recursivelyShrink :: (Generic a, RecursivelyShrink (Rep a)) => a -> [a]
recursivelyShrink :: forall a. (Generic a, RecursivelyShrink (Rep a)) => a -> [a]
recursivelyShrink = forall a b. (a -> b) -> [a] -> [b]
map forall a x. Generic a => Rep a x -> a
to forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
class RecursivelyShrink f where
grecursivelyShrink :: f a -> [f a]
instance (RecursivelyShrink f, RecursivelyShrink g) => RecursivelyShrink (f :*: g) where
grecursivelyShrink :: forall (a :: k). (:*:) f g a -> [(:*:) f g a]
grecursivelyShrink (f a
x :*: g a
y) =
[f a
x' forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g a
y | f a
x' <- forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink f a
x] forall a. [a] -> [a] -> [a]
++
[f a
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g a
y' | g a
y' <- forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink g a
y]
instance (RecursivelyShrink f, RecursivelyShrink g) => RecursivelyShrink (f :+: g) where
grecursivelyShrink :: forall (a :: k). (:+:) f g a -> [(:+:) f g a]
grecursivelyShrink (L1 f a
x) = forall a b. (a -> b) -> [a] -> [b]
map forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink f a
x)
grecursivelyShrink (R1 g a
x) = forall a b. (a -> b) -> [a] -> [b]
map forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink g a
x)
instance RecursivelyShrink f => RecursivelyShrink (M1 i c f) where
grecursivelyShrink :: forall (a :: k). M1 i c f a -> [M1 i c f a]
grecursivelyShrink (M1 f a
x) = forall a b. (a -> b) -> [a] -> [b]
map forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (forall {k} (f :: k -> *) (a :: k).
RecursivelyShrink f =>
f a -> [f a]
grecursivelyShrink f a
x)
instance Arbitrary a => RecursivelyShrink (K1 i a) where
grecursivelyShrink :: forall (a :: k). K1 i a a -> [K1 i a a]
grecursivelyShrink (K1 a
x) = forall a b. (a -> b) -> [a] -> [b]
map forall k i c (p :: k). c -> K1 i c p
K1 (forall a. Arbitrary a => a -> [a]
shrink a
x)
instance RecursivelyShrink U1 where
grecursivelyShrink :: forall (a :: k). U1 a -> [U1 a]
grecursivelyShrink U1 a
U1 = []
instance RecursivelyShrink V1 where
grecursivelyShrink :: forall (a :: k). V1 a -> [V1 a]
grecursivelyShrink V1 a
_ = []
subterms :: (Generic a, GSubterms (Rep a) a) => a -> [a]
subterms :: forall a. (Generic a, GSubterms (Rep a) a) => a -> [a]
subterms = forall (f :: * -> *) a. GSubterms f a => f a -> [a]
gSubterms forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
class GSubterms f a where
gSubterms :: f a -> [a]
instance GSubterms V1 a where
gSubterms :: V1 a -> [a]
gSubterms V1 a
_ = []
instance GSubterms U1 a where
gSubterms :: U1 a -> [a]
gSubterms U1 a
U1 = []
instance (GSubtermsIncl f a, GSubtermsIncl g a) => GSubterms (f :*: g) a where
gSubterms :: (:*:) f g a -> [a]
gSubterms (f a
l :*: g a
r) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl f a
l forall a. [a] -> [a] -> [a]
++ forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl g a
r
instance (GSubtermsIncl f a, GSubtermsIncl g a) => GSubterms (f :+: g) a where
gSubterms :: (:+:) f g a -> [a]
gSubterms (L1 f a
x) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl f a
x
gSubterms (R1 g a
x) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl g a
x
instance GSubterms f a => GSubterms (M1 i c f) a where
gSubterms :: M1 i c f a -> [a]
gSubterms (M1 f a
x) = forall (f :: * -> *) a. GSubterms f a => f a -> [a]
gSubterms f a
x
instance GSubterms (K1 i a) b where
gSubterms :: K1 i a b -> [b]
gSubterms (K1 a
_) = []
class GSubtermsIncl f a where
gSubtermsIncl :: f a -> [a]
instance GSubtermsIncl V1 a where
gSubtermsIncl :: V1 a -> [a]
gSubtermsIncl V1 a
_ = []
instance GSubtermsIncl U1 a where
gSubtermsIncl :: U1 a -> [a]
gSubtermsIncl U1 a
U1 = []
instance (GSubtermsIncl f a, GSubtermsIncl g a) => GSubtermsIncl (f :*: g) a where
gSubtermsIncl :: (:*:) f g a -> [a]
gSubtermsIncl (f a
l :*: g a
r) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl f a
l forall a. [a] -> [a] -> [a]
++ forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl g a
r
instance (GSubtermsIncl f a, GSubtermsIncl g a) => GSubtermsIncl (f :+: g) a where
gSubtermsIncl :: (:+:) f g a -> [a]
gSubtermsIncl (L1 f a
x) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl f a
x
gSubtermsIncl (R1 g a
x) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl g a
x
instance GSubtermsIncl f a => GSubtermsIncl (M1 i c f) a where
gSubtermsIncl :: M1 i c f a -> [a]
gSubtermsIncl (M1 f a
x) = forall (f :: * -> *) a. GSubtermsIncl f a => f a -> [a]
gSubtermsIncl f a
x
instance OVERLAPPING_ GSubtermsIncl (K1 i a) a where
gSubtermsIncl :: K1 i a a -> [a]
gSubtermsIncl (K1 a
x) = [a
x]
instance OVERLAPPING_ GSubtermsIncl (K1 i a) b where
gSubtermsIncl :: K1 i a b -> [b]
gSubtermsIncl (K1 a
_) = []
#endif
instance (CoArbitrary a) => Arbitrary1 ((->) a) where
liftArbitrary :: forall a. Gen a -> Gen (a -> a)
liftArbitrary Gen a
arbB = forall (m :: * -> *) a. Monad m => m (Gen a) -> Gen (m a)
promote (forall a b. CoArbitrary a => a -> Gen b -> Gen b
`coarbitrary` Gen a
arbB)
instance (CoArbitrary a, Arbitrary b) => Arbitrary (a -> b) where
arbitrary :: Gen (a -> b)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
instance Arbitrary () where
arbitrary :: Gen ()
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance Arbitrary Bool where
arbitrary :: Gen Bool
arbitrary = forall a. Enum a => (a, a) -> Gen a
chooseEnum (Bool
False,Bool
True)
shrink :: Bool -> [Bool]
shrink Bool
True = [Bool
False]
shrink Bool
False = []
instance Arbitrary Ordering where
arbitrary :: Gen Ordering
arbitrary = forall a. [a] -> Gen a
elements [Ordering
LT, Ordering
EQ, Ordering
GT]
shrink :: Ordering -> [Ordering]
shrink Ordering
GT = [Ordering
EQ, Ordering
LT]
shrink Ordering
LT = [Ordering
EQ]
shrink Ordering
EQ = []
instance Arbitrary1 Maybe where
liftArbitrary :: forall a. Gen a -> Gen (Maybe a)
liftArbitrary Gen a
arb = forall a. [(Int, Gen a)] -> Gen a
frequency [(Int
1, forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing), (Int
3, forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a. a -> Maybe a
Just Gen a
arb)]
liftShrink :: forall a. (a -> [a]) -> Maybe a -> [Maybe a]
liftShrink a -> [a]
shr (Just a
x) = forall a. Maybe a
Nothing forall a. a -> [a] -> [a]
: [ forall a. a -> Maybe a
Just a
x' | a
x' <- a -> [a]
shr a
x ]
liftShrink a -> [a]
_ Maybe a
Nothing = []
instance Arbitrary a => Arbitrary (Maybe a) where
arbitrary :: Gen (Maybe a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Maybe a -> [Maybe a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary2 Either where
liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (Either a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = forall a. [Gen a] -> Gen a
oneof [forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a b. a -> Either a b
Left Gen a
arbA, forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a b. b -> Either a b
Right Gen b
arbB]
liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> Either a b -> [Either a b]
liftShrink2 a -> [a]
shrA b -> [b]
_ (Left a
x) = [ forall a b. a -> Either a b
Left a
x' | a
x' <- a -> [a]
shrA a
x ]
liftShrink2 a -> [a]
_ b -> [b]
shrB (Right b
y) = [ forall a b. b -> Either a b
Right b
y' | b
y' <- b -> [b]
shrB b
y ]
instance Arbitrary a => Arbitrary1 (Either a) where
liftArbitrary :: forall a. Gen a -> Gen (Either a a)
liftArbitrary = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 forall a. Arbitrary a => Gen a
arbitrary
liftShrink :: forall a. (a -> [a]) -> Either a a -> [Either a a]
liftShrink = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 forall a. Arbitrary a => a -> [a]
shrink
instance (Arbitrary a, Arbitrary b) => Arbitrary (Either a b) where
arbitrary :: Gen (Either a b)
arbitrary = forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
Gen (f a b)
arbitrary2
shrink :: Either a b -> [Either a b]
shrink = forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
f a b -> [f a b]
shrink2
instance Arbitrary1 [] where
liftArbitrary :: forall a. Gen a -> Gen [a]
liftArbitrary = forall a. Gen a -> Gen [a]
listOf
liftShrink :: forall a. (a -> [a]) -> [a] -> [[a]]
liftShrink = forall a. (a -> [a]) -> [a] -> [[a]]
shrinkList
instance Arbitrary a => Arbitrary [a] where
arbitrary :: Gen [a]
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: [a] -> [[a]]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
shrinkList :: (a -> [a]) -> [a] -> [[a]]
shrinkList :: forall a. (a -> [a]) -> [a] -> [[a]]
shrinkList a -> [a]
shr [a]
xs = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ forall {a}. Int -> Int -> [a] -> [[a]]
removes Int
k Int
n [a]
xs | Int
k <- forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
>Int
0) (forall a. (a -> a) -> a -> [a]
iterate (forall a. Integral a => a -> a -> a
`div`Int
2) Int
n) ]
forall a. [a] -> [a] -> [a]
++ [a] -> [[a]]
shrinkOne [a]
xs
where
n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs
shrinkOne :: [a] -> [[a]]
shrinkOne [] = []
shrinkOne (a
x:[a]
xs) = [ a
x'forall a. a -> [a] -> [a]
:[a]
xs | a
x' <- a -> [a]
shr a
x ]
forall a. [a] -> [a] -> [a]
++ [ a
xforall a. a -> [a] -> [a]
:[a]
xs' | [a]
xs' <- [a] -> [[a]]
shrinkOne [a]
xs ]
removes :: Int -> Int -> [a] -> [[a]]
removes Int
k Int
n [a]
xs
| Int
k forall a. Ord a => a -> a -> Bool
> Int
n = []
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
xs2 = [[]]
| Bool
otherwise = [a]
xs2 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map ([a]
xs1 forall a. [a] -> [a] -> [a]
++) (Int -> Int -> [a] -> [[a]]
removes Int
k (Int
nforall a. Num a => a -> a -> a
-Int
k) [a]
xs2)
where
xs1 :: [a]
xs1 = forall a. Int -> [a] -> [a]
take Int
k [a]
xs
xs2 :: [a]
xs2 = forall a. Int -> [a] -> [a]
drop Int
k [a]
xs
instance Integral a => Arbitrary (Ratio a) where
arbitrary :: Gen (Ratio a)
arbitrary = forall a. Fractional a => Gen a
arbitrarySizedFractional
shrink :: Ratio a -> [Ratio a]
shrink = forall a. RealFrac a => a -> [a]
shrinkRealFrac
#if defined(MIN_VERSION_base) && MIN_VERSION_base(4,4,0)
instance Arbitrary a => Arbitrary (Complex a) where
#else
instance (RealFloat a, Arbitrary a) => Arbitrary (Complex a) where
#endif
arbitrary :: Gen (Complex a)
arbitrary = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. a -> a -> Complex a
(:+) forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink :: Complex a -> [Complex a]
shrink (a
x :+ a
y) = [ a
x' forall a. a -> a -> Complex a
:+ a
y | a
x' <- forall a. Arbitrary a => a -> [a]
shrink a
x ] forall a. [a] -> [a] -> [a]
++
[ a
x forall a. a -> a -> Complex a
:+ a
y' | a
y' <- forall a. Arbitrary a => a -> [a]
shrink a
y ]
#ifndef NO_FIXED
instance HasResolution a => Arbitrary (Fixed a) where
arbitrary :: Gen (Fixed a)
arbitrary = forall a. Fractional a => Gen a
arbitrarySizedFractional
shrink :: Fixed a -> [Fixed a]
shrink = forall a. RealFrac a => a -> [a]
shrinkDecimal
#endif
instance Arbitrary2 (,) where
liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (a, b)
liftArbitrary2 = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,)
liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)]
liftShrink2 a -> [a]
shrA b -> [b]
shrB (a
x, b
y) =
[ (a
x', b
y) | a
x' <- a -> [a]
shrA a
x ]
forall a. [a] -> [a] -> [a]
++ [ (a
x, b
y') | b
y' <- b -> [b]
shrB b
y ]
instance (Arbitrary a) => Arbitrary1 ((,) a) where
liftArbitrary :: forall a. Gen a -> Gen (a, a)
liftArbitrary = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 forall a. Arbitrary a => Gen a
arbitrary
liftShrink :: forall a. (a -> [a]) -> (a, a) -> [(a, a)]
liftShrink = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 forall a. Arbitrary a => a -> [a]
shrink
instance (Arbitrary a, Arbitrary b) => Arbitrary (a,b) where
arbitrary :: Gen (a, b)
arbitrary = forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
Gen (f a b)
arbitrary2
shrink :: (a, b) -> [(a, b)]
shrink = forall (f :: * -> * -> *) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
f a b -> [f a b]
shrink2
instance (Arbitrary a, Arbitrary b, Arbitrary c)
=> Arbitrary (a,b,c)
where
arbitrary :: Gen (a, b, c)
arbitrary = forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 (,,) forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c) -> [(a, b, c)]
shrink (a
x, b
y, c
z) =
[ (a
x', b
y', c
z')
| (a
x', (b
y', c
z')) <- forall a. Arbitrary a => a -> [a]
shrink (a
x, (b
y, c
z)) ]
instance (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d)
=> Arbitrary (a,b,c,d)
where
arbitrary :: Gen (a, b, c, d)
arbitrary = forall (m :: * -> *) a1 a2 a3 a4 r.
Monad m =>
(a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
liftM4 (,,,) forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d) -> [(a, b, c, d)]
shrink (a
w, b
x, c
y, d
z) =
[ (a
w', b
x', c
y', d
z')
| (a
w', (b
x', (c
y', d
z'))) <- forall a. Arbitrary a => a -> [a]
shrink (a
w, (b
x, (c
y, d
z))) ]
instance (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e)
=> Arbitrary (a,b,c,d,e)
where
arbitrary :: Gen (a, b, c, d, e)
arbitrary = forall (m :: * -> *) a1 a2 a3 a4 a5 r.
Monad m =>
(a1 -> a2 -> a3 -> a4 -> a5 -> r)
-> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
liftM5 (,,,,) forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e) -> [(a, b, c, d, e)]
shrink (a
v, b
w, c
x, d
y, e
z) =
[ (a
v', b
w', c
x', d
y', e
z')
| (a
v', (b
w', (c
x', (d
y', e
z')))) <- forall a. Arbitrary a => a -> [a]
shrink (a
v, (b
w, (c
x, (d
y, e
z)))) ]
instance ( Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e
, Arbitrary f
)
=> Arbitrary (a,b,c,d,e,f)
where
arbitrary :: Gen (a, b, c, d, e, f)
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e, f) -> [(a, b, c, d, e, f)]
shrink (a
u, b
v, c
w, d
x, e
y, f
z) =
[ (a
u', b
v', c
w', d
x', e
y', f
z')
| (a
u', (b
v', (c
w', (d
x', (e
y', f
z'))))) <- forall a. Arbitrary a => a -> [a]
shrink (a
u, (b
v, (c
w, (d
x, (e
y, f
z))))) ]
instance ( Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e
, Arbitrary f, Arbitrary g
)
=> Arbitrary (a,b,c,d,e,f,g)
where
arbitrary :: Gen (a, b, c, d, e, f, g)
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,,)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e, f, g) -> [(a, b, c, d, e, f, g)]
shrink (a
t, b
u, c
v, d
w, e
x, f
y, g
z) =
[ (a
t', b
u', c
v', d
w', e
x', f
y', g
z')
| (a
t', (b
u', (c
v', (d
w', (e
x', (f
y', g
z')))))) <- forall a. Arbitrary a => a -> [a]
shrink (a
t, (b
u, (c
v, (d
w, (e
x, (f
y, g
z)))))) ]
instance ( Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e
, Arbitrary f, Arbitrary g, Arbitrary h
)
=> Arbitrary (a,b,c,d,e,f,g,h)
where
arbitrary :: Gen (a, b, c, d, e, f, g, h)
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,,,)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e, f, g, h) -> [(a, b, c, d, e, f, g, h)]
shrink (a
s, b
t, c
u, d
v, e
w, f
x, g
y, h
z) =
[ (a
s', b
t', c
u', d
v', e
w', f
x', g
y', h
z')
| (a
s', (b
t', (c
u', (d
v', (e
w', (f
x', (g
y', h
z')))))))
<- forall a. Arbitrary a => a -> [a]
shrink (a
s, (b
t, (c
u, (d
v, (e
w, (f
x, (g
y, h
z))))))) ]
instance ( Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e
, Arbitrary f, Arbitrary g, Arbitrary h, Arbitrary i
)
=> Arbitrary (a,b,c,d,e,f,g,h,i)
where
arbitrary :: Gen (a, b, c, d, e, f, g, h, i)
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,,,,)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e, f, g, h, i) -> [(a, b, c, d, e, f, g, h, i)]
shrink (a
r, b
s, c
t, d
u, e
v, f
w, g
x, h
y, i
z) =
[ (a
r', b
s', c
t', d
u', e
v', f
w', g
x', h
y', i
z')
| (a
r', (b
s', (c
t', (d
u', (e
v', (f
w', (g
x', (h
y', i
z'))))))))
<- forall a. Arbitrary a => a -> [a]
shrink (a
r, (b
s, (c
t, (d
u, (e
v, (f
w, (g
x, (h
y, i
z)))))))) ]
instance ( Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e
, Arbitrary f, Arbitrary g, Arbitrary h, Arbitrary i, Arbitrary j
)
=> Arbitrary (a,b,c,d,e,f,g,h,i,j)
where
arbitrary :: Gen (a, b, c, d, e, f, g, h, i, j)
arbitrary = forall (m :: * -> *) a. Monad m => a -> m a
return (,,,,,,,,,)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: (a, b, c, d, e, f, g, h, i, j) -> [(a, b, c, d, e, f, g, h, i, j)]
shrink (a
q, b
r, c
s, d
t, e
u, f
v, g
w, h
x, i
y, j
z) =
[ (a
q', b
r', c
s', d
t', e
u', f
v', g
w', h
x', i
y', j
z')
| (a
q', (b
r', (c
s', (d
t', (e
u', (f
v', (g
w', (h
x', (i
y', j
z')))))))))
<- forall a. Arbitrary a => a -> [a]
shrink (a
q, (b
r, (c
s, (d
t, (e
u, (f
v, (g
w, (h
x, (i
y, j
z))))))))) ]
instance Arbitrary Integer where
arbitrary :: Gen Integer
arbitrary = forall a. Integral a => Gen a
arbitrarySizedIntegral
shrink :: Integer -> [Integer]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Int where
arbitrary :: Gen Int
arbitrary = forall a. Integral a => Gen a
arbitrarySizedIntegral
shrink :: Int -> [Int]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Int8 where
arbitrary :: Gen Int8
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Int8 -> [Int8]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Int16 where
arbitrary :: Gen Int16
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Int16 -> [Int16]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Int32 where
arbitrary :: Gen Int32
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Int32 -> [Int32]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Int64 where
arbitrary :: Gen Int64
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Int64 -> [Int64]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Word where
arbitrary :: Gen Word
arbitrary = forall a. Integral a => Gen a
arbitrarySizedNatural
shrink :: Word -> [Word]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Word8 where
arbitrary :: Gen Word8
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Word8 -> [Word8]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Word16 where
arbitrary :: Gen Word16
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Word16 -> [Word16]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Word32 where
arbitrary :: Gen Word32
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Word32 -> [Word32]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Word64 where
arbitrary :: Gen Word64
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: Word64 -> [Word64]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary Char where
arbitrary :: Gen Char
arbitrary =
forall a. [(Int, Gen a)] -> Gen a
frequency
[(Int
3, Gen Char
arbitraryASCIIChar),
(Int
1, Gen Char
arbitraryUnicodeChar)]
shrink :: Char -> [Char]
shrink Char
c = forall a. (a -> Bool) -> [a] -> [a]
filter (Char -> Char -> Bool
<. Char
c) forall a b. (a -> b) -> a -> b
$ forall a. Eq a => [a] -> [a]
nub
forall a b. (a -> b) -> a -> b
$ [Char
'a',Char
'b',Char
'c']
forall a. [a] -> [a] -> [a]
++ [ Char -> Char
toLower Char
c | Char -> Bool
isUpper Char
c ]
forall a. [a] -> [a] -> [a]
++ [Char
'A',Char
'B',Char
'C']
forall a. [a] -> [a] -> [a]
++ [Char
'1',Char
'2',Char
'3']
forall a. [a] -> [a] -> [a]
++ [Char
' ',Char
'\n']
where
Char
a <. :: Char -> Char -> Bool
<. Char
b = Char -> ((Bool, Bool, Bool), (Bool, Bool, Char))
stamp Char
a forall a. Ord a => a -> a -> Bool
< Char -> ((Bool, Bool, Bool), (Bool, Bool, Char))
stamp Char
b
stamp :: Char -> ((Bool, Bool, Bool), (Bool, Bool, Char))
stamp Char
a = ( (Bool -> Bool
not (Char -> Bool
isLower Char
a)
, Bool -> Bool
not (Char -> Bool
isUpper Char
a)
, Bool -> Bool
not (Char -> Bool
isDigit Char
a))
, (Bool -> Bool
not (Char
aforall a. Eq a => a -> a -> Bool
==Char
' ')
, Bool -> Bool
not (Char -> Bool
isSpace Char
a)
, Char
a)
)
instance Arbitrary Float where
arbitrary :: Gen Float
arbitrary = forall a. [Gen a] -> Gen a
oneof
[ Gen Float
genFloat
, forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Arbitrary a => Gen a
arbitrary :: Gen Int)
, Gen Float
smallDenominators
, Gen Float
uniform
, forall a. Fractional a => Gen a
arbitrarySizedFractional
]
where
smallDenominators :: Gen Float
smallDenominators = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
Int
i <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Fractional a => Rational -> a
fromRational (forall a. Int -> Stream a -> a
streamNth Int
i Stream Rational
rationalUniverse))
uniform :: Gen Float
uniform = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
let n' :: Integer
n' = forall a. Integral a => a -> Integer
toInteger Int
n
Integer
b <- (Integer, Integer) -> Gen Integer
chooseInteger (Integer
1, forall a. Ord a => a -> a -> a
max Integer
1 Integer
n')
Integer
a <- (Integer, Integer) -> Gen Integer
chooseInteger ((-Integer
n') forall a. Num a => a -> a -> a
* Integer
b, Integer
n' forall a. Num a => a -> a -> a
* Integer
b)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Fractional a => Rational -> a
fromRational (Integer
a forall a. Integral a => a -> a -> Ratio a
% Integer
b))
shrink :: Float -> [Float]
shrink = forall a. RealFrac a => a -> [a]
shrinkDecimal
instance Arbitrary Double where
arbitrary :: Gen Double
arbitrary = forall a. [Gen a] -> Gen a
oneof
[ Gen Double
genDouble
, forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Arbitrary a => Gen a
arbitrary :: Gen Int)
, Gen Double
smallDenominators
, Gen Double
uniform
, forall a. Fractional a => Gen a
arbitrarySizedFractional
]
where
smallDenominators :: Gen Double
smallDenominators = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
Int
i <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Fractional a => Rational -> a
fromRational (forall a. Int -> Stream a -> a
streamNth Int
i Stream Rational
rationalUniverse))
uniform :: Gen Double
uniform = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
let n' :: Integer
n' = forall a. Integral a => a -> Integer
toInteger Int
n
Integer
b <- (Integer, Integer) -> Gen Integer
chooseInteger (Integer
1, forall a. Ord a => a -> a -> a
max Integer
1 Integer
n')
Integer
a <- (Integer, Integer) -> Gen Integer
chooseInteger ((-Integer
n') forall a. Num a => a -> a -> a
* Integer
b, Integer
n' forall a. Num a => a -> a -> a
* Integer
b)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Fractional a => Rational -> a
fromRational (Integer
a forall a. Integral a => a -> a -> Ratio a
% Integer
b))
shrink :: Double -> [Double]
shrink = forall a. RealFrac a => a -> [a]
shrinkDecimal
instance Arbitrary CChar where
arbitrary :: Gen CChar
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CChar -> [CChar]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CSChar where
arbitrary :: Gen CSChar
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CSChar -> [CSChar]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CUChar where
arbitrary :: Gen CUChar
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CUChar -> [CUChar]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CShort where
arbitrary :: Gen CShort
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CShort -> [CShort]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CUShort where
arbitrary :: Gen CUShort
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CUShort -> [CUShort]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CInt where
arbitrary :: Gen CInt
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CInt -> [CInt]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CUInt where
arbitrary :: Gen CUInt
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CUInt -> [CUInt]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CLong where
arbitrary :: Gen CLong
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CLong -> [CLong]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CULong where
arbitrary :: Gen CULong
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CULong -> [CULong]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CPtrdiff where
arbitrary :: Gen CPtrdiff
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CPtrdiff -> [CPtrdiff]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CSize where
arbitrary :: Gen CSize
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CSize -> [CSize]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CWchar where
arbitrary :: Gen CWchar
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CWchar -> [CWchar]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CSigAtomic where
arbitrary :: Gen CSigAtomic
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CSigAtomic -> [CSigAtomic]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CLLong where
arbitrary :: Gen CLLong
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CLLong -> [CLLong]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CULLong where
arbitrary :: Gen CULLong
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CULLong -> [CULLong]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CIntPtr where
arbitrary :: Gen CIntPtr
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CIntPtr -> [CIntPtr]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CUIntPtr where
arbitrary :: Gen CUIntPtr
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CUIntPtr -> [CUIntPtr]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CIntMax where
arbitrary :: Gen CIntMax
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CIntMax -> [CIntMax]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
instance Arbitrary CUIntMax where
arbitrary :: Gen CUIntMax
arbitrary = forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral
shrink :: CUIntMax -> [CUIntMax]
shrink = forall a. Integral a => a -> [a]
shrinkIntegral
#ifndef NO_CTYPES_CONSTRUCTORS
instance Arbitrary CClock where
arbitrary :: Gen CClock
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int64 -> CClock
CClock forall a. Arbitrary a => Gen a
arbitrary
shrink :: CClock -> [CClock]
shrink (CClock Int64
x) = forall a b. (a -> b) -> [a] -> [b]
map Int64 -> CClock
CClock (forall a. Arbitrary a => a -> [a]
shrink Int64
x)
instance Arbitrary CTime where
arbitrary :: Gen CTime
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int64 -> CTime
CTime forall a. Arbitrary a => Gen a
arbitrary
shrink :: CTime -> [CTime]
shrink (CTime Int64
x) = forall a b. (a -> b) -> [a] -> [b]
map Int64 -> CTime
CTime (forall a. Arbitrary a => a -> [a]
shrink Int64
x)
#ifndef NO_FOREIGN_C_USECONDS
instance Arbitrary CUSeconds where
arbitrary :: Gen CUSeconds
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> CUSeconds
CUSeconds forall a. Arbitrary a => Gen a
arbitrary
shrink :: CUSeconds -> [CUSeconds]
shrink (CUSeconds Word32
x) = forall a b. (a -> b) -> [a] -> [b]
map Word32 -> CUSeconds
CUSeconds (forall a. Arbitrary a => a -> [a]
shrink Word32
x)
instance Arbitrary CSUSeconds where
arbitrary :: Gen CSUSeconds
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int64 -> CSUSeconds
CSUSeconds forall a. Arbitrary a => Gen a
arbitrary
shrink :: CSUSeconds -> [CSUSeconds]
shrink (CSUSeconds Int64
x) = forall a b. (a -> b) -> [a] -> [b]
map Int64 -> CSUSeconds
CSUSeconds (forall a. Arbitrary a => a -> [a]
shrink Int64
x)
#endif
#endif
instance Arbitrary CFloat where
arbitrary :: Gen CFloat
arbitrary = forall a. Fractional a => Gen a
arbitrarySizedFractional
shrink :: CFloat -> [CFloat]
shrink = forall a. RealFrac a => a -> [a]
shrinkDecimal
instance Arbitrary CDouble where
arbitrary :: Gen CDouble
arbitrary = forall a. Fractional a => Gen a
arbitrarySizedFractional
shrink :: CDouble -> [CDouble]
shrink = forall a. RealFrac a => a -> [a]
shrinkDecimal
instance (Ord a, Arbitrary a) => Arbitrary (Set.Set a) where
arbitrary :: Gen (Set a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Ord a => [a] -> Set a
Set.fromList forall a. Arbitrary a => Gen a
arbitrary
shrink :: Set a -> [Set a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. Ord a => [a] -> Set a
Set.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toList
instance (Ord k, Arbitrary k) => Arbitrary1 (Map.Map k) where
liftArbitrary :: forall a. Gen a -> Gen (Map k a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
liftShrink :: forall a. (a -> [a]) -> Map k a -> [Map k a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink (forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList
instance (Ord k, Arbitrary k, Arbitrary v) => Arbitrary (Map.Map k v) where
arbitrary :: Gen (Map k v)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Map k v -> [Map k v]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary IntSet.IntSet where
arbitrary :: Gen IntSet
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Int] -> IntSet
IntSet.fromList forall a. Arbitrary a => Gen a
arbitrary
shrink :: IntSet -> [IntSet]
shrink = forall a b. (a -> b) -> [a] -> [b]
map [Int] -> IntSet
IntSet.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IntSet.toList
instance Arbitrary1 IntMap.IntMap where
liftArbitrary :: forall a. Gen a -> Gen (IntMap a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [(Int, a)] -> IntMap a
IntMap.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
liftShrink :: forall a. (a -> [a]) -> IntMap a -> [IntMap a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall a. [(Int, a)] -> IntMap a
IntMap.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink (forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IntMap a -> [(Int, a)]
IntMap.toList
instance Arbitrary a => Arbitrary (IntMap.IntMap a) where
arbitrary :: Gen (IntMap a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: IntMap a -> [IntMap a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary1 Sequence.Seq where
liftArbitrary :: forall a. Gen a -> Gen (Seq a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [a] -> Seq a
Sequence.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
liftShrink :: forall a. (a -> [a]) -> Seq a -> [Seq a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall a. [a] -> Seq a
Sequence.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
instance Arbitrary a => Arbitrary (Sequence.Seq a) where
arbitrary :: Gen (Seq a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Seq a -> [Seq a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary1 Tree.Tree where
liftArbitrary :: forall a. Gen a -> Gen (Tree a)
liftArbitrary Gen a
arb = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
Int
k <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int
n)
Int -> Gen (Tree a)
go Int
k
where
go :: Int -> Gen (Tree a)
go Int
n = do
a
value <- Gen a
arb
[Int]
pars <- Int -> Gen [Int]
arbPartition (Int
n forall a. Num a => a -> a -> a
- Int
1)
[Tree a]
forest <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Int -> Gen (Tree a)
go [Int]
pars
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> [Tree a] -> Tree a
Tree.Node a
value [Tree a]
forest
arbPartition :: Int -> Gen [Int]
arbPartition :: Int -> Gen [Int]
arbPartition Int
k = case forall a. Ord a => a -> a -> Ordering
compare Int
k Int
1 of
Ordering
LT -> forall (f :: * -> *) a. Applicative f => a -> f a
pure []
Ordering
EQ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure [Int
1]
Ordering
GT -> do
Int
first <- (Int, Int) -> Gen Int
chooseInt (Int
1, Int
k)
[Int]
rest <- Int -> Gen [Int]
arbPartition forall a b. (a -> b) -> a -> b
$ Int
k forall a. Num a => a -> a -> a
- Int
first
forall a. [a] -> Gen [a]
shuffle (Int
first forall a. a -> [a] -> [a]
: [Int]
rest)
liftShrink :: forall a. (a -> [a]) -> Tree a -> [Tree a]
liftShrink a -> [a]
shr = Tree a -> [Tree a]
go
where
go :: Tree a -> [Tree a]
go (Tree.Node a
val [Tree a]
forest) = [Tree a]
forest forall a. [a] -> [a] -> [a]
++
[ forall a. a -> [Tree a] -> Tree a
Tree.Node a
e [Tree a]
fs
| (a
e, [Tree a]
fs) <- forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
shr (forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink Tree a -> [Tree a]
go) (a
val, [Tree a]
forest)
]
instance Arbitrary a => Arbitrary (Tree.Tree a) where
arbitrary :: Gen (Tree a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Tree a -> [Tree a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary1 ZipList where
liftArbitrary :: forall a. Gen a -> Gen (ZipList a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [a] -> ZipList a
ZipList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
liftShrink :: forall a. (a -> [a]) -> ZipList a -> [ZipList a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall a. [a] -> ZipList a
ZipList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ZipList a -> [a]
getZipList
instance Arbitrary a => Arbitrary (ZipList a) where
arbitrary :: Gen (ZipList a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: ZipList a -> [ZipList a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
#ifndef NO_TRANSFORMERS
instance Arbitrary1 Identity where
liftArbitrary :: forall a. Gen a -> Gen (Identity a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Identity a
Identity
liftShrink :: forall a. (a -> [a]) -> Identity a -> [Identity a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
shr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity
instance Arbitrary a => Arbitrary (Identity a) where
arbitrary :: Gen (Identity a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Identity a -> [Identity a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance Arbitrary2 Constant where
liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (Constant a b)
liftArbitrary2 Gen a
arbA Gen b
_ = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Constant a b
Constant Gen a
arbA
liftShrink2 :: forall a b.
(a -> [a]) -> (b -> [b]) -> Constant a b -> [Constant a b]
liftShrink2 a -> [a]
shrA b -> [b]
_ = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
shrA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Constant a b -> a
getConstant
instance Arbitrary a => Arbitrary1 (Constant a) where
liftArbitrary :: forall a. Gen a -> Gen (Constant a a)
liftArbitrary = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 forall a. Arbitrary a => Gen a
arbitrary
liftShrink :: forall a. (a -> [a]) -> Constant a a -> [Constant a a]
liftShrink = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 forall a. Arbitrary a => a -> [a]
shrink
instance Arbitrary a => Arbitrary (Constant a b) where
arbitrary :: Gen (Constant a b)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Constant a b
Constant forall a. Arbitrary a => Gen a
arbitrary
shrink :: Constant a b -> [Constant a b]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Constant a b -> a
getConstant
instance (Arbitrary1 f, Arbitrary1 g) => Arbitrary1 (Product f g) where
liftArbitrary :: forall a. Gen a -> Gen (Product f g a)
liftArbitrary Gen a
arb = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen a
arb) (forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen a
arb)
liftShrink :: forall a. (a -> [a]) -> Product f g a -> [Product f g a]
liftShrink a -> [a]
shr (Pair f a
f g a
g) =
[ forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
f' g a
g | f a
f' <- forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr f a
f ] forall a. [a] -> [a] -> [a]
++
[ forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
f g a
g' | g a
g' <- forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr g a
g ]
instance (Arbitrary1 f, Arbitrary1 g, Arbitrary a) => Arbitrary (Product f g a) where
arbitrary :: Gen (Product f g a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Product f g a -> [Product f g a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
instance (Arbitrary1 f, Arbitrary1 g) => Arbitrary1 (Compose f g) where
liftArbitrary :: forall a. Gen a -> Gen (Compose f g a)
liftArbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
liftShrink :: forall a. (a -> [a]) -> Compose f g a -> [Compose f g a]
liftShrink a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink (forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
instance (Arbitrary1 f, Arbitrary1 g, Arbitrary a) => Arbitrary (Compose f g a) where
arbitrary :: Gen (Compose f g a)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
shrink :: Compose f g a -> [Compose f g a]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1
#endif
instance Arbitrary2 Const where
liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (Const a b)
liftArbitrary2 Gen a
arbA Gen b
_ = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Const a b
Const Gen a
arbA
liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> Const a b -> [Const a b]
liftShrink2 a -> [a]
shrA b -> [b]
_ = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Const a b
Const forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
shrA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Const a b -> a
getConst
instance Arbitrary a => Arbitrary1 (Const a) where
liftArbitrary :: forall a. Gen a -> Gen (Const a a)
liftArbitrary = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 forall a. Arbitrary a => Gen a
arbitrary
liftShrink :: forall a. (a -> [a]) -> Const a a -> [Const a a]
liftShrink = forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 forall a. Arbitrary a => a -> [a]
shrink
instance Arbitrary a => Arbitrary (Const a b) where
arbitrary :: Gen (Const a b)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} a (b :: k). a -> Const a b
Const forall a. Arbitrary a => Gen a
arbitrary
shrink :: Const a b -> [Const a b]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall {k} a (b :: k). a -> Const a b
Const forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Const a b -> a
getConst
instance Arbitrary (m a) => Arbitrary (WrappedMonad m a) where
arbitrary :: Gen (WrappedMonad m a)
arbitrary = forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
shrink :: WrappedMonad m a -> [WrappedMonad m a]
shrink (WrapMonad m a
a) = forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad (forall a. Arbitrary a => a -> [a]
shrink m a
a)
instance Arbitrary (a b c) => Arbitrary (WrappedArrow a b c) where
arbitrary :: Gen (WrappedArrow a b c)
arbitrary = forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
WrapArrow forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
shrink :: WrappedArrow a b c -> [WrappedArrow a b c]
shrink (WrapArrow a b c
a) = forall a b. (a -> b) -> [a] -> [b]
map forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
WrapArrow (forall a. Arbitrary a => a -> [a]
shrink a b c
a)
instance Arbitrary a => Arbitrary (Monoid.Dual a) where
arbitrary :: Gen (Dual a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Dual a
Monoid.Dual forall a. Arbitrary a => Gen a
arbitrary
shrink :: Dual a -> [Dual a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Dual a
Monoid.Dual forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Dual a -> a
Monoid.getDual
instance (Arbitrary a, CoArbitrary a) => Arbitrary (Monoid.Endo a) where
arbitrary :: Gen (Endo a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. (a -> a) -> Endo a
Monoid.Endo forall a. Arbitrary a => Gen a
arbitrary
shrink :: Endo a -> [Endo a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. (a -> a) -> Endo a
Monoid.Endo forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Endo a -> a -> a
Monoid.appEndo
instance Arbitrary Monoid.All where
arbitrary :: Gen All
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> All
Monoid.All forall a. Arbitrary a => Gen a
arbitrary
shrink :: All -> [All]
shrink = forall a b. (a -> b) -> [a] -> [b]
map Bool -> All
Monoid.All forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. All -> Bool
Monoid.getAll
instance Arbitrary Monoid.Any where
arbitrary :: Gen Any
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Any
Monoid.Any forall a. Arbitrary a => Gen a
arbitrary
shrink :: Any -> [Any]
shrink = forall a b. (a -> b) -> [a] -> [b]
map Bool -> Any
Monoid.Any forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. Any -> Bool
Monoid.getAny
instance Arbitrary a => Arbitrary (Monoid.Sum a) where
arbitrary :: Gen (Sum a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Sum a
Monoid.Sum forall a. Arbitrary a => Gen a
arbitrary
shrink :: Sum a -> [Sum a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Sum a
Monoid.Sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Sum a -> a
Monoid.getSum
instance Arbitrary a => Arbitrary (Monoid.Product a) where
arbitrary :: Gen (Product a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Product a
Monoid.Product forall a. Arbitrary a => Gen a
arbitrary
shrink :: Product a -> [Product a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Product a
Monoid.Product forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Product a -> a
Monoid.getProduct
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(3,0,0)
instance Arbitrary a => Arbitrary (Monoid.First a) where
arbitrary :: Gen (First a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Maybe a -> First a
Monoid.First forall a. Arbitrary a => Gen a
arbitrary
shrink :: First a -> [First a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. Maybe a -> First a
Monoid.First forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. First a -> Maybe a
Monoid.getFirst
instance Arbitrary a => Arbitrary (Monoid.Last a) where
arbitrary :: Gen (Last a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Maybe a -> Last a
Monoid.Last forall a. Arbitrary a => Gen a
arbitrary
shrink :: Last a -> [Last a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall a. Maybe a -> Last a
Monoid.Last forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Last a -> Maybe a
Monoid.getLast
#endif
#if MIN_VERSION_base(4,8,0)
instance Arbitrary (f a) => Arbitrary (Monoid.Alt f a) where
arbitrary :: Gen (Alt f a)
arbitrary = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (f :: k -> *) (a :: k). f a -> Alt f a
Monoid.Alt forall a. Arbitrary a => Gen a
arbitrary
shrink :: Alt f a -> [Alt f a]
shrink = forall a b. (a -> b) -> [a] -> [b]
map forall {k} (f :: k -> *) (a :: k). f a -> Alt f a
Monoid.Alt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Arbitrary a => a -> [a]
shrink forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Alt f a -> f a
Monoid.getAlt
#endif
#endif
instance Arbitrary Version where
arbitrary :: Gen Version
arbitrary = forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n ->
do Int
k <- (Int, Int) -> Gen Int
chooseInt (Int
0, Int -> Int
log2 Int
n)
[Int]
xs <- forall a. Int -> Gen a -> Gen [a]
vectorOf (Int
kforall a. Num a => a -> a -> a
+Int
1) forall a. Integral a => Gen a
arbitrarySizedNatural
forall (m :: * -> *) a. Monad m => a -> m a
return ([Int] -> [[Char]] -> Version
Version [Int]
xs [])
where
log2 :: Int -> Int
log2 :: Int -> Int
log2 Int
n | Int
n forall a. Ord a => a -> a -> Bool
<= Int
1 = Int
0
| Bool
otherwise = Int
1 forall a. Num a => a -> a -> a
+ Int -> Int
log2 (Int
n forall a. Integral a => a -> a -> a
`div` Int
2)
shrink :: Version -> [Version]
shrink (Version [Int]
xs [[Char]]
_) =
[ [Int] -> [[Char]] -> Version
Version [Int]
xs' []
| [Int]
xs' <- forall a. Arbitrary a => a -> [a]
shrink [Int]
xs
, forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
xs' forall a. Ord a => a -> a -> Bool
> Int
0
, forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
>=Int
0) [Int]
xs'
]
instance Arbitrary QCGen where
arbitrary :: Gen QCGen
arbitrary = forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\QCGen
g Int
_ -> QCGen
g)
instance Arbitrary ExitCode where
arbitrary :: Gen ExitCode
arbitrary = forall a. [(Int, Gen a)] -> Gen a
frequency [(Int
1, forall (m :: * -> *) a. Monad m => a -> m a
return ExitCode
ExitSuccess), (Int
3, forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Int -> ExitCode
ExitFailure forall a. Arbitrary a => Gen a
arbitrary)]
shrink :: ExitCode -> [ExitCode]
shrink (ExitFailure Int
x) = ExitCode
ExitSuccess forall a. a -> [a] -> [a]
: [ Int -> ExitCode
ExitFailure Int
x' | Int
x' <- forall a. Arbitrary a => a -> [a]
shrink Int
x ]
shrink ExitCode
_ = []
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,2,0)
instance Arbitrary Newline where
arbitrary :: Gen Newline
arbitrary = forall a. [a] -> Gen a
elements [Newline
LF, Newline
CRLF]
shrink :: Newline -> [Newline]
shrink Newline
LF = []
shrink Newline
CRLF = [Newline
LF]
instance Arbitrary NewlineMode where
arbitrary :: Gen NewlineMode
arbitrary = Newline -> Newline -> NewlineMode
NewlineMode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
shrink :: NewlineMode -> [NewlineMode]
shrink (NewlineMode Newline
inNL Newline
outNL) = [Newline -> Newline -> NewlineMode
NewlineMode Newline
inNL' Newline
outNL' | (Newline
inNL', Newline
outNL') <- forall a. Arbitrary a => a -> [a]
shrink (Newline
inNL, Newline
outNL)]
#endif
#endif
applyArbitrary2 :: (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r
applyArbitrary2 :: forall a b r. (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r
applyArbitrary2 a -> b -> r
f = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> r
f forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
applyArbitrary3
:: (Arbitrary a, Arbitrary b, Arbitrary c)
=> (a -> b -> c -> r) -> Gen r
applyArbitrary3 :: forall a b c r.
(Arbitrary a, Arbitrary b, Arbitrary c) =>
(a -> b -> c -> r) -> Gen r
applyArbitrary3 a -> b -> c -> r
f = forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 a -> b -> c -> r
f forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary forall a. Arbitrary a => Gen a
arbitrary
applyArbitrary4
:: (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d)
=> (a -> b -> c -> d -> r) -> Gen r
applyArbitrary4 :: forall a b c d r.
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) =>
(a -> b -> c -> d -> r) -> Gen r
applyArbitrary4 a -> b -> c -> d -> r
f = forall a b c r.
(Arbitrary a, Arbitrary b, Arbitrary c) =>
(a -> b -> c -> r) -> Gen r
applyArbitrary3 (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> c -> d -> r
f)
arbitrarySizedIntegral :: Integral a => Gen a
arbitrarySizedIntegral :: forall a. Integral a => Gen a
arbitrarySizedIntegral =
forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n ->
forall a. Integral a => (Int -> a) -> Gen Int -> Gen a
inBounds forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int, Int) -> Gen Int
chooseInt (-Int
n, Int
n))
arbitrarySizedNatural :: Integral a => Gen a
arbitrarySizedNatural :: forall a. Integral a => Gen a
arbitrarySizedNatural =
forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n ->
forall a. Integral a => (Int -> a) -> Gen Int -> Gen a
inBounds forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int, Int) -> Gen Int
chooseInt (Int
0, Int
n))
inBounds :: Integral a => (Int -> a) -> Gen Int -> Gen a
inBounds :: forall a. Integral a => (Int -> a) -> Gen Int -> Gen a
inBounds Int -> a
fi Gen Int
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> a
fi (Gen Int
g forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` (\Int
x -> forall a. Integral a => a -> Integer
toInteger Int
x forall a. Eq a => a -> a -> Bool
== forall a. Integral a => a -> Integer
toInteger (Int -> a
fi Int
x)))
arbitrarySizedFractional :: Fractional a => Gen a
arbitrarySizedFractional :: forall a. Fractional a => Gen a
arbitrarySizedFractional =
forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
n -> do
Int
denom <- (Int, Int) -> Gen Int
chooseInt (Int
1, forall a. Ord a => a -> a -> a
max Int
1 Int
n)
Int
numer <- (Int, Int) -> Gen Int
chooseInt (-Int
nforall a. Num a => a -> a -> a
*Int
denom, Int
nforall a. Num a => a -> a -> a
*Int
denom)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
numer forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
denom
{-# INLINE withBounds #-}
withBounds :: Bounded a => (a -> a -> Gen a) -> Gen a
withBounds :: forall a. Bounded a => (a -> a -> Gen a) -> Gen a
withBounds a -> a -> Gen a
k = a -> a -> Gen a
k forall a. Bounded a => a
minBound forall a. Bounded a => a
maxBound
arbitraryBoundedIntegral :: (Bounded a, Integral a) => Gen a
arbitraryBoundedIntegral :: forall a. (Bounded a, Integral a) => Gen a
arbitraryBoundedIntegral = forall a. (Bounded a, Integral a) => (a, a) -> Gen a
chooseBoundedIntegral (forall a. Bounded a => a
minBound, forall a. Bounded a => a
maxBound)
arbitraryBoundedRandom :: (Bounded a, Random a) => Gen a
arbitraryBoundedRandom :: forall a. (Bounded a, Random a) => Gen a
arbitraryBoundedRandom = forall a. Random a => (a, a) -> Gen a
choose (forall a. Bounded a => a
minBound,forall a. Bounded a => a
maxBound)
arbitraryBoundedEnum :: (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum :: forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum = forall a. Enum a => (a, a) -> Gen a
chooseEnum (forall a. Bounded a => a
minBound, forall a. Bounded a => a
maxBound)
arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a
{-# INLINEABLE arbitrarySizedBoundedIntegral #-}
arbitrarySizedBoundedIntegral :: forall a. (Bounded a, Integral a) => Gen a
arbitrarySizedBoundedIntegral =
forall a. Bounded a => (a -> a -> Gen a) -> Gen a
withBounds forall a b. (a -> b) -> a -> b
$ \a
mn a
mx ->
let ilog2 :: t -> a
ilog2 t
1 = a
0
ilog2 t
n | t
n forall a. Ord a => a -> a -> Bool
> t
0 = a
1 forall a. Num a => a -> a -> a
+ t -> a
ilog2 (t
n forall a. Integral a => a -> a -> a
`div` t
2)
bits :: Int
bits = forall {t} {a}. (Num a, Integral t) => t -> a
ilog2 (forall a. Integral a => a -> Integer
toInteger a
mx forall a. Num a => a -> a -> a
- forall a. Integral a => a -> Integer
toInteger a
mn forall a. Num a => a -> a -> a
+ Integer
1) in
forall a. (Int -> Gen a) -> Gen a
sized forall a b. (a -> b) -> a -> b
$ \Int
k ->
let
power :: Int
power = ((Int
bits forall a. Ord a => a -> a -> a
`max` Int
40) forall a. Num a => a -> a -> a
* Int
k) forall a. Integral a => a -> a -> a
`div` Int
80
lo :: Integer
lo = forall a. Integral a => a -> Integer
toInteger a
mn forall a. Ord a => a -> a -> a
`max` (-Integer
1 forall a. Bits a => a -> Int -> a
`shiftL` (Int
power forall a. Ord a => a -> a -> a
`min` Int
bits))
hi :: Integer
hi = forall a. Integral a => a -> Integer
toInteger a
mx forall a. Ord a => a -> a -> a
`min` (Integer
1 forall a. Bits a => a -> Int -> a
`shiftL` (Int
power forall a. Ord a => a -> a -> a
`min` Int
bits)) in
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => Integer -> a
fromInteger ((Integer, Integer) -> Gen Integer
chooseInteger (Integer
lo, Integer
hi))
arbitraryUnicodeChar :: Gen Char
arbitraryUnicodeChar :: Gen Char
arbitraryUnicodeChar =
forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` Char -> Bool
isValidUnicode
where
isValidUnicode :: Char -> Bool
isValidUnicode Char
c = case Char -> GeneralCategory
generalCategory Char
c of
GeneralCategory
Surrogate -> Bool
False
GeneralCategory
NotAssigned -> Bool
False
GeneralCategory
_ -> Bool
True
arbitraryASCIIChar :: Gen Char
arbitraryASCIIChar :: Gen Char
arbitraryASCIIChar = forall a. Enum a => (a, a) -> Gen a
chooseEnum (Char
'\0', Char
'\127')
arbitraryPrintableChar :: Gen Char
arbitraryPrintableChar :: Gen Char
arbitraryPrintableChar = forall a. Arbitrary a => Gen a
arbitrary forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` Char -> Bool
isPrint
shrinkNothing :: a -> [a]
shrinkNothing :: forall a. a -> [a]
shrinkNothing a
_ = []
shrinkMap :: Arbitrary a => (a -> b) -> (b -> a) -> b -> [b]
shrinkMap :: forall a b. Arbitrary a => (a -> b) -> (b -> a) -> b -> [b]
shrinkMap a -> b
f b -> a
g = forall a b. (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b]
shrinkMapBy a -> b
f b -> a
g forall a. Arbitrary a => a -> [a]
shrink
shrinkMapBy :: (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b]
shrinkMapBy :: forall a b. (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b]
shrinkMapBy a -> b
f b -> a
g a -> [a]
shr = forall a b. (a -> b) -> [a] -> [b]
map a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
shr forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
g
shrinkIntegral :: Integral a => a -> [a]
shrinkIntegral :: forall a. Integral a => a -> [a]
shrinkIntegral a
x =
forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$
[ -a
x
| a
x forall a. Ord a => a -> a -> Bool
< a
0, -a
x forall a. Ord a => a -> a -> Bool
> a
x
] forall a. [a] -> [a] -> [a]
++
[ a
x'
| a
x' <- forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall {a}. (Ord a, Num a) => a -> a -> Bool
<< a
x) (a
0forall a. a -> [a] -> [a]
:[ a
x forall a. Num a => a -> a -> a
- a
i | a
i <- forall a. [a] -> [a]
tail (forall a. (a -> a) -> a -> [a]
iterate (forall a. Integral a => a -> a -> a
`quot` a
2) a
x) ])
]
where
a
a << :: a -> a -> Bool
<< a
b = case (a
a forall a. Ord a => a -> a -> Bool
>= a
0, a
b forall a. Ord a => a -> a -> Bool
>= a
0) of
(Bool
True, Bool
True) -> a
a forall a. Ord a => a -> a -> Bool
< a
b
(Bool
False, Bool
False) -> a
a forall a. Ord a => a -> a -> Bool
> a
b
(Bool
True, Bool
False) -> a
a forall a. Num a => a -> a -> a
+ a
b forall a. Ord a => a -> a -> Bool
< a
0
(Bool
False, Bool
True) -> a
a forall a. Num a => a -> a -> a
+ a
b forall a. Ord a => a -> a -> Bool
> a
0
shrinkBoundedEnum :: (Bounded a, Enum a, Eq a) => a -> [a]
shrinkBoundedEnum :: forall a. (Bounded a, Enum a, Eq a) => a -> [a]
shrinkBoundedEnum a
a
| a
a forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound =
[]
| Bool
otherwise =
forall a. Enum a => Int -> a
toEnum forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Ord a => a -> a -> Bool
>= Int
minBoundInt) (forall a. Integral a => a -> [a]
shrinkIntegral forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum a
a)
where
minBoundInt :: Int
minBoundInt :: Int
minBoundInt = forall a. Enum a => a -> Int
fromEnum (forall a. Bounded a => a
minBound forall a. a -> a -> a
`asTypeOf` a
a)
shrinkRealFrac :: RealFrac a => a -> [a]
shrinkRealFrac :: forall a. RealFrac a => a -> [a]
shrinkRealFrac a
x
| Bool -> Bool
not (a
x forall a. Eq a => a -> a -> Bool
== a
x) = a
0 forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
< a
1000) [a]
numbers
| a
x forall a. Ord a => a -> a -> Bool
> a
0 Bool -> Bool -> Bool
&& Bool -> Bool
not (a
2forall a. Num a => a -> a -> a
*a
xforall a. Num a => a -> a -> a
+a
1forall a. Ord a => a -> a -> Bool
>a
x) = a
0 forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
<a
x) [a]
numbers
| a
x forall a. Ord a => a -> a -> Bool
< a
0 = forall a. Num a => a -> a
negate a
xforall a. a -> [a] -> [a]
:forall a b. (a -> b) -> [a] -> [b]
map forall a. Num a => a -> a
negate (forall a. RealFrac a => a -> [a]
shrinkRealFrac (forall a. Num a => a -> a
negate a
x))
| Bool
otherwise =
forall a. (a -> Bool) -> [a] -> [a]
filter (\a
y -> forall a. Num a => a -> a
abs a
y forall a. Ord a => a -> a -> Bool
< forall a. Num a => a -> a
abs a
x) forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map forall a. Num a => Integer -> a
fromInteger (forall a. Arbitrary a => a -> [a]
shrink (forall a b. (RealFrac a, Integral b) => a -> b
truncate a
x) forall a. [a] -> [a] -> [a]
++ [forall a b. (RealFrac a, Integral b) => a -> b
truncate a
x]) forall a. [a] -> [a] -> [a]
++
[forall a. Fractional a => Rational -> a
fromRational (Integer
num' forall a. Integral a => a -> a -> Ratio a
% Integer
denom) | Integer
num' <- forall a. Arbitrary a => a -> [a]
shrink Integer
num] forall a. [a] -> [a] -> [a]
++
[forall a. Fractional a => Rational -> a
fromRational (forall a b. (RealFrac a, Integral b) => a -> b
truncate (Integer
num forall a. Num a => a -> a -> a
* Integer
denom' forall a. Integral a => a -> a -> Ratio a
% Integer
denom) forall a. Integral a => a -> a -> Ratio a
% Integer
denom')
| Integer
denom' <- forall a. Arbitrary a => a -> [a]
shrink Integer
denom, Integer
denom' forall a. Eq a => a -> a -> Bool
/= Integer
0 ]
where
num :: Integer
num = forall a. Ratio a -> a
numerator (forall a. Real a => a -> Rational
toRational a
x)
denom :: Integer
denom = forall a. Ratio a -> a
denominator (forall a. Real a => a -> Rational
toRational a
x)
numbers :: [a]
numbers = forall a. (a -> a) -> a -> [a]
iterate (forall a. Num a => a -> a -> a
*a
2) a
1
shrinkDecimal :: RealFrac a => a -> [a]
shrinkDecimal :: forall a. RealFrac a => a -> [a]
shrinkDecimal a
x
| Bool -> Bool
not (a
x forall a. Eq a => a -> a -> Bool
== a
x) = a
0 forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
< a
1000) [a]
numbers
| Bool -> Bool
not (a
2forall a. Num a => a -> a -> a
*forall a. Num a => a -> a
abs a
xforall a. Num a => a -> a -> a
+a
1forall a. Ord a => a -> a -> Bool
>forall a. Num a => a -> a
abs a
x) = a
0 forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
<a
x) [a]
numbers
| a
x forall a. Ord a => a -> a -> Bool
< a
0 = forall a. Num a => a -> a
negate a
xforall a. a -> [a] -> [a]
:forall a b. (a -> b) -> [a] -> [b]
map forall a. Num a => a -> a
negate (forall a. RealFrac a => a -> [a]
shrinkDecimal (forall a. Num a => a -> a
negate a
x))
| Bool
otherwise =
[ a
y
| Rational
precision <- forall a. Int -> [a] -> [a]
take Int
6 (forall a. (a -> a) -> a -> [a]
iterate (forall a. Num a => a -> a -> a
*Rational
10) Rational
1),
let m :: Integer
m = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a. Real a => a -> Rational
toRational a
x forall a. Num a => a -> a -> a
* Rational
precision),
Rational
precision forall a. Eq a => a -> a -> Bool
== Rational
1 Bool -> Bool -> Bool
|| Integer
m forall a. Integral a => a -> a -> a
`mod` Integer
10 forall a. Eq a => a -> a -> Bool
/= Integer
0,
Integer
n <- Integer
mforall a. a -> [a] -> [a]
:forall a. Arbitrary a => a -> [a]
shrink Integer
m,
let y :: a
y = forall a. Fractional a => Rational -> a
fromRational (forall a. Num a => Integer -> a
fromInteger Integer
n forall a. Fractional a => a -> a -> a
/ Rational
precision),
forall a. Num a => a -> a
abs a
y forall a. Ord a => a -> a -> Bool
< forall a. Num a => a -> a
abs a
x ]
where
numbers :: [a]
numbers = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ forall a. (a -> a) -> a -> [a]
iterate (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Num a => a -> a -> a
*a
10)) (forall a b. (a -> b) -> [a] -> [b]
map forall a. Num a => Integer -> a
fromInteger [Integer
1..Integer
9])
#ifndef NO_GENERICS
#else
#endif
class CoArbitrary a where
coarbitrary :: a -> Gen b -> Gen b
#ifndef NO_GENERICS
default coarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b
coarbitrary = forall a b.
(Generic a, GCoArbitrary (Rep a)) =>
a -> Gen b -> Gen b
genericCoarbitrary
genericCoarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b
genericCoarbitrary :: forall a b.
(Generic a, GCoArbitrary (Rep a)) =>
a -> Gen b -> Gen b
genericCoarbitrary = forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
class GCoArbitrary f where
gCoarbitrary :: f a -> Gen b -> Gen b
instance GCoArbitrary U1 where
gCoarbitrary :: forall (a :: k) b. U1 a -> Gen b -> Gen b
gCoarbitrary U1 a
U1 = forall a. a -> a
id
instance (GCoArbitrary f, GCoArbitrary g) => GCoArbitrary (f :*: g) where
gCoarbitrary :: forall (a :: k) b. (:*:) f g a -> Gen b -> Gen b
gCoarbitrary (f a
l :*: g a
r) = forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary f a
l forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary g a
r
instance (GCoArbitrary f, GCoArbitrary g) => GCoArbitrary (f :+: g) where
gCoarbitrary :: forall (a :: k) b. (:+:) f g a -> Gen b -> Gen b
gCoarbitrary (L1 f a
x) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary f a
x
gCoarbitrary (R1 g a
x) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary g a
x
instance GCoArbitrary f => GCoArbitrary (M1 i c f) where
gCoarbitrary :: forall (a :: k) b. M1 i c f a -> Gen b -> Gen b
gCoarbitrary (M1 f a
x) = forall {k} (f :: k -> *) (a :: k) b.
GCoArbitrary f =>
f a -> Gen b -> Gen b
gCoarbitrary f a
x
instance CoArbitrary a => GCoArbitrary (K1 i a) where
gCoarbitrary :: forall (a :: k) b. K1 i a a -> Gen b -> Gen b
gCoarbitrary (K1 a
x) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
#endif
{-# DEPRECATED (><) "Use ordinary function composition instead" #-}
(><) :: (Gen a -> Gen a) -> (Gen a -> Gen a) -> (Gen a -> Gen a)
>< :: forall a. (Gen a -> Gen a) -> (Gen a -> Gen a) -> Gen a -> Gen a
(><) = forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
instance (Arbitrary a, CoArbitrary b) => CoArbitrary (a -> b) where
coarbitrary :: forall b. (a -> b) -> Gen b -> Gen b
coarbitrary a -> b
f Gen b
gen =
do [a]
xs <- forall a. Arbitrary a => Gen a
arbitrary
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (forall a b. (a -> b) -> [a] -> [b]
map a -> b
f [a]
xs) Gen b
gen
instance CoArbitrary () where
coarbitrary :: forall b. () -> Gen b -> Gen b
coarbitrary ()
_ = forall a. a -> a
id
instance CoArbitrary Bool where
coarbitrary :: forall b. Bool -> Gen b -> Gen b
coarbitrary Bool
False = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0
coarbitrary Bool
True = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1
instance CoArbitrary Ordering where
coarbitrary :: forall b. Ordering -> Gen b -> Gen b
coarbitrary Ordering
GT = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0
coarbitrary Ordering
EQ = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1
coarbitrary Ordering
LT = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
2
instance CoArbitrary a => CoArbitrary (Maybe a) where
coarbitrary :: forall b. Maybe a -> Gen b -> Gen b
coarbitrary Maybe a
Nothing = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0
coarbitrary (Just a
x) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
instance (CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b) where
coarbitrary :: forall b. Either a b -> Gen b -> Gen b
coarbitrary (Left a
x) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
coarbitrary (Right b
y) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary b
y
instance CoArbitrary a => CoArbitrary [a] where
coarbitrary :: forall b. [a] -> Gen b -> Gen b
coarbitrary [] = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0
coarbitrary (a
x:[a]
xs) = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (a
x,[a]
xs)
instance (Integral a, CoArbitrary a) => CoArbitrary (Ratio a) where
coarbitrary :: forall b. Ratio a -> Gen b -> Gen b
coarbitrary Ratio a
r = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (forall a. Ratio a -> a
numerator Ratio a
r,forall a. Ratio a -> a
denominator Ratio a
r)
#ifndef NO_FIXED
instance HasResolution a => CoArbitrary (Fixed a) where
coarbitrary :: forall b. Fixed a -> Gen b -> Gen b
coarbitrary = forall a b. Real a => a -> Gen b -> Gen b
coarbitraryReal
#endif
#if defined(MIN_VERSION_base) && MIN_VERSION_base(4,4,0)
instance CoArbitrary a => CoArbitrary (Complex a) where
#else
instance (RealFloat a, CoArbitrary a) => CoArbitrary (Complex a) where
#endif
coarbitrary :: forall b. Complex a -> Gen b -> Gen b
coarbitrary (a
x :+ a
y) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
y
instance (CoArbitrary a, CoArbitrary b)
=> CoArbitrary (a,b)
where
coarbitrary :: forall b. (a, b) -> Gen b -> Gen b
coarbitrary (a
x,b
y) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary b
y
instance (CoArbitrary a, CoArbitrary b, CoArbitrary c)
=> CoArbitrary (a,b,c)
where
coarbitrary :: forall b. (a, b, c) -> Gen b -> Gen b
coarbitrary (a
x,b
y,c
z) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary b
y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary c
z
instance (CoArbitrary a, CoArbitrary b, CoArbitrary c, CoArbitrary d)
=> CoArbitrary (a,b,c,d)
where
coarbitrary :: forall b. (a, b, c, d) -> Gen b -> Gen b
coarbitrary (a
x,b
y,c
z,d
v) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary b
y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary c
z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary d
v
instance (CoArbitrary a, CoArbitrary b, CoArbitrary c, CoArbitrary d, CoArbitrary e)
=> CoArbitrary (a,b,c,d,e)
where
coarbitrary :: forall b. (a, b, c, d, e) -> Gen b -> Gen b
coarbitrary (a
x,b
y,c
z,d
v,e
w) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary b
y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary c
z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary d
v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary e
w
instance CoArbitrary Integer where
coarbitrary :: forall b. Integer -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Int where
coarbitrary :: forall b. Int -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Int8 where
coarbitrary :: forall b. Int8 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Int16 where
coarbitrary :: forall b. Int16 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Int32 where
coarbitrary :: forall b. Int32 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Int64 where
coarbitrary :: forall b. Int64 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Word where
coarbitrary :: forall b. Word -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Word8 where
coarbitrary :: forall b. Word8 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Word16 where
coarbitrary :: forall b. Word16 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Word32 where
coarbitrary :: forall b. Word32 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Word64 where
coarbitrary :: forall b. Word64 -> Gen b -> Gen b
coarbitrary = forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral
instance CoArbitrary Char where
coarbitrary :: forall b. Char -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord
instance CoArbitrary Float where
coarbitrary :: forall b. Float -> Gen b -> Gen b
coarbitrary = forall a b. Real a => a -> Gen b -> Gen b
coarbitraryReal
instance CoArbitrary Double where
coarbitrary :: forall b. Double -> Gen b -> Gen b
coarbitrary = forall a b. Real a => a -> Gen b -> Gen b
coarbitraryReal
instance CoArbitrary a => CoArbitrary (Set.Set a) where
coarbitrary :: forall b. Set a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitraryforall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toList
instance (CoArbitrary k, CoArbitrary v) => CoArbitrary (Map.Map k v) where
coarbitrary :: forall b. Map k v -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList
instance CoArbitrary IntSet.IntSet where
coarbitrary :: forall b. IntSet -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IntSet.toList
instance CoArbitrary a => CoArbitrary (IntMap.IntMap a) where
coarbitrary :: forall b. IntMap a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IntMap a -> [(Int, a)]
IntMap.toList
instance CoArbitrary a => CoArbitrary (Sequence.Seq a) where
coarbitrary :: forall b. Seq a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
instance CoArbitrary a => CoArbitrary (Tree.Tree a) where
coarbitrary :: forall b. Tree a -> Gen b -> Gen b
coarbitrary (Tree.Node a
val [Tree a]
forest) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary a
val forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary [Tree a]
forest
instance CoArbitrary a => CoArbitrary (ZipList a) where
coarbitrary :: forall b. ZipList a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ZipList a -> [a]
getZipList
#ifndef NO_TRANSFORMERS
instance CoArbitrary a => CoArbitrary (Identity a) where
coarbitrary :: forall b. Identity a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity
instance CoArbitrary a => CoArbitrary (Constant a b) where
coarbitrary :: forall b. Constant a b -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Constant a b -> a
getConstant
#endif
instance CoArbitrary a => CoArbitrary (Const a b) where
coarbitrary :: forall b. Const a b -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Const a b -> a
getConst
instance CoArbitrary a => CoArbitrary (Monoid.Dual a) where
coarbitrary :: forall b. Dual a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Dual a -> a
Monoid.getDual
instance (Arbitrary a, CoArbitrary a) => CoArbitrary (Monoid.Endo a) where
coarbitrary :: forall b. Endo a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Endo a -> a -> a
Monoid.appEndo
instance CoArbitrary Monoid.All where
coarbitrary :: forall b. All -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. All -> Bool
Monoid.getAll
instance CoArbitrary Monoid.Any where
coarbitrary :: forall b. Any -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. Any -> Bool
Monoid.getAny
instance CoArbitrary a => CoArbitrary (Monoid.Sum a) where
coarbitrary :: forall b. Sum a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Sum a -> a
Monoid.getSum
instance CoArbitrary a => CoArbitrary (Monoid.Product a) where
coarbitrary :: forall b. Product a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Product a -> a
Monoid.getProduct
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(3,0,0)
instance CoArbitrary a => CoArbitrary (Monoid.First a) where
coarbitrary :: forall b. First a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. First a -> Maybe a
Monoid.getFirst
instance CoArbitrary a => CoArbitrary (Monoid.Last a) where
coarbitrary :: forall b. Last a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Last a -> Maybe a
Monoid.getLast
#endif
#if MIN_VERSION_base(4,8,0)
instance CoArbitrary (f a) => CoArbitrary (Monoid.Alt f a) where
coarbitrary :: forall b. Alt f a -> Gen b -> Gen b
coarbitrary = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Alt f a -> f a
Monoid.getAlt
#endif
#endif
instance CoArbitrary Version where
coarbitrary :: forall b. Version -> Gen b -> Gen b
coarbitrary (Version [Int]
a [[Char]]
b) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary ([Int]
a, [[Char]]
b)
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,2,0)
instance CoArbitrary Newline where
coarbitrary :: forall b. Newline -> Gen b -> Gen b
coarbitrary Newline
LF = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
0
coarbitrary Newline
CRLF = forall n a. Integral n => n -> Gen a -> Gen a
variant Integer
1
instance CoArbitrary NewlineMode where
coarbitrary :: forall b. NewlineMode -> Gen b -> Gen b
coarbitrary (NewlineMode Newline
inNL Newline
outNL) = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Newline
inNL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Newline
outNL
#endif
#endif
coarbitraryIntegral :: Integral a => a -> Gen b -> Gen b
coarbitraryIntegral :: forall n a. Integral n => n -> Gen a -> Gen a
coarbitraryIntegral = forall n a. Integral n => n -> Gen a -> Gen a
variant
coarbitraryReal :: Real a => a -> Gen b -> Gen b
coarbitraryReal :: forall a b. Real a => a -> Gen b -> Gen b
coarbitraryReal a
x = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (forall a. Real a => a -> Rational
toRational a
x)
coarbitraryShow :: Show a => a -> Gen b -> Gen b
coarbitraryShow :: forall a b. Show a => a -> Gen b -> Gen b
coarbitraryShow a
x = forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (forall a. Show a => a -> [Char]
show a
x)
coarbitraryEnum :: Enum a => a -> Gen b -> Gen b
coarbitraryEnum :: forall a b. Enum a => a -> Gen b -> Gen b
coarbitraryEnum = forall n a. Integral n => n -> Gen a -> Gen a
variant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => a -> Int
fromEnum
vector :: Arbitrary a => Int -> Gen [a]
vector :: forall a. Arbitrary a => Int -> Gen [a]
vector Int
k = forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k forall a. Arbitrary a => Gen a
arbitrary
orderedList :: (Ord a, Arbitrary a) => Gen [a]
orderedList :: forall a. (Ord a, Arbitrary a) => Gen [a]
orderedList = forall a. Ord a => [a] -> [a]
sort forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. Arbitrary a => Gen a
arbitrary
infiniteList :: Arbitrary a => Gen [a]
infiniteList :: forall a. Arbitrary a => Gen [a]
infiniteList = forall a. Gen a -> Gen [a]
infiniteListOf forall a. Arbitrary a => Gen a
arbitrary
infixr 5 :<
data Stream a = !a :< Stream a
streamNth :: Int -> Stream a -> a
streamNth :: forall a. Int -> Stream a -> a
streamNth Int
n (a
x :< Stream a
xs) | Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 = a
x
| Bool
otherwise = forall a. Int -> Stream a -> a
streamNth (Int
n forall a. Num a => a -> a -> a
- Int
1) Stream a
xs
rationalUniverse :: Stream Rational
rationalUniverse :: Stream Rational
rationalUniverse = Rational
0 forall a. a -> Stream a -> Stream a
:< Rational
1 forall a. a -> Stream a -> Stream a
:< (-Rational
1) forall a. a -> Stream a -> Stream a
:< forall {a}. Fractional a => Stream a -> Stream a
go Stream Rational
leftSideStream
where
go :: Stream a -> Stream a
go (a
x :< Stream a
xs) =
let nx :: a
nx = -a
x
rx :: a
rx = forall a. Fractional a => a -> a
recip a
x
nrx :: a
nrx = -a
rx
in a
nx seq :: forall a b. a -> b -> b
`seq` a
rx seq :: forall a b. a -> b -> b
`seq` a
nrx seq :: forall a b. a -> b -> b
`seq` (a
x forall a. a -> Stream a -> Stream a
:< a
rx forall a. a -> Stream a -> Stream a
:< a
nx forall a. a -> Stream a -> Stream a
:< a
nrx forall a. a -> Stream a -> Stream a
:< Stream a -> Stream a
go Stream a
xs)
leftSideStream :: Stream Rational
leftSideStream :: Stream Rational
leftSideStream = (Integer
1 forall a. Integral a => a -> a -> Ratio a
% Integer
2) forall a. a -> Stream a -> Stream a
:< forall {a}. Integral a => Stream (Ratio a) -> Stream (Ratio a)
go Stream Rational
leftSideStream
where
go :: Stream (Ratio a) -> Stream (Ratio a)
go (Ratio a
x :< Stream (Ratio a)
xs) =
Ratio a
lChild seq :: forall a b. a -> b -> b
`seq` Ratio a
rChild seq :: forall a b. a -> b -> b
`seq`
(Ratio a
lChild forall a. a -> Stream a -> Stream a
:< Ratio a
rChild forall a. a -> Stream a -> Stream a
:< Stream (Ratio a) -> Stream (Ratio a)
go Stream (Ratio a)
xs)
where
nd :: a
nd = forall a. Ratio a -> a
numerator Ratio a
x forall a. Num a => a -> a -> a
+ forall a. Ratio a -> a
denominator Ratio a
x
lChild :: Ratio a
lChild = forall a. Ratio a -> a
numerator Ratio a
x forall a. Integral a => a -> a -> Ratio a
% a
nd
rChild :: Ratio a
rChild = a
nd forall a. Integral a => a -> a -> Ratio a
% forall a. Ratio a -> a
denominator Ratio a
x