{-# LANGUAGE CPP              #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Test.QuickCheck.Instances.Strict () where

import Prelude ()
import Test.QuickCheck.Instances.CustomPrelude

import Test.QuickCheck

import qualified Data.Strict as S

-------------------------------------------------------------------------------
-- Pair
-------------------------------------------------------------------------------

-- | @since 0.3.24
instance Arbitrary2 S.Pair where
    liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (Pair a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = forall a b. a -> b -> Pair a b
(S.:!:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen b
arbB

    liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> Pair a b -> [Pair a b]
liftShrink2  a -> [a]
shrA b -> [b]
shrB (a
x S.:!: b
y) = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. a -> b -> Pair a b
(S.:!:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 
        forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
shrA b -> [b]
shrB (a
x, b
y)

-- | @since 0.3.24
instance (Arbitrary a) => Arbitrary1 (S.Pair a) where
    liftArbitrary :: forall a. Gen a -> Gen (Pair 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]) -> Pair a a -> [Pair 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

-- | @since 0.3.24
instance (Arbitrary a, Arbitrary b) => Arbitrary (S.Pair a b) where
    arbitrary :: Gen (Pair a b)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Pair a b -> [Pair a b]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1

-- | @since 0.3.24
instance (Function a, Function b) => Function (S.Pair a b) where
    function :: forall b. (Pair a b -> b) -> Pair a b :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy forall lazy strict. Strict lazy strict => lazy -> strict
S.toStrict

-- | @since 0.3.24
instance (CoArbitrary a, CoArbitrary b) => CoArbitrary (S.Pair a b)

-------------------------------------------------------------------------------
-- Maybe
-------------------------------------------------------------------------------

-- | @since 0.3.24
instance Arbitrary1 S.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 (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
S.Nothing)
        , (Int
9, forall a. a -> Maybe a
S.Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arb)
        ]

    liftShrink :: forall a. (a -> [a]) -> Maybe a -> [Maybe a]
liftShrink a -> [a]
_shr Maybe a
S.Nothing  = []
    liftShrink  a -> [a]
shr (S.Just a
x) = forall a. Maybe a
S.Nothing forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Maybe a
S.Just (a -> [a]
shr a
x)

-- | @since 0.3.24
instance (Arbitrary a) => Arbitrary (S.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

-- | @since 0.3.24
instance (Function a) => Function (S.Maybe a) where
    function :: forall b. (Maybe a -> b) -> Maybe a :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy forall lazy strict. Strict lazy strict => lazy -> strict
S.toStrict

-- | @since 0.3.24
instance (CoArbitrary a) => CoArbitrary (S.Maybe a)

-------------------------------------------------------------------------------
-- Either
-------------------------------------------------------------------------------

-- | @since 0.3.24
instance Arbitrary2 S.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 a b. a -> Either a b
S.Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA
        , forall a b. b -> Either a b
S.Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen b
arbB
        ]

    liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> Either a b -> [Either a b]
liftShrink2  a -> [a]
shrA b -> [b]
_shrB (S.Left a
x)  = forall a b. a -> Either a b
S.Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> [a]
shrA a
x
    liftShrink2 a -> [a]
_shrA  b -> [b]
shrB (S.Right b
y) = forall a b. b -> Either a b
S.Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> [b]
shrB b
y

-- | @since 0.3.24
instance (Arbitrary a) => Arbitrary1 (S.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

-- | @since 0.3.24
instance (Arbitrary a, Arbitrary b) => Arbitrary (S.Either a b) where
    arbitrary :: Gen (Either a b)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Either a b -> [Either a b]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1

-- | @since 0.3.24
instance (Function a, Function b) => Function (S.Either a b) where
    function :: forall b. (Either a b -> b) -> Either a b :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy forall lazy strict. Strict lazy strict => lazy -> strict
S.toStrict

-- | @since 0.3.24
instance (CoArbitrary a, CoArbitrary b) => CoArbitrary (S.Either a b)

-------------------------------------------------------------------------------
-- These
-------------------------------------------------------------------------------

-- | @since 0.3.24
instance Arbitrary2 S.These where
    liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (These a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = forall a. [Gen a] -> Gen a
oneof
        [ forall a b. a -> These a b
S.This forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA
        , forall a b. b -> These a b
S.That forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen b
arbB
        , forall a b. a -> b -> These a b
S.These forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen b
arbB
        ]

    liftShrink2 :: forall a b. (a -> [a]) -> (b -> [b]) -> These a b -> [These a b]
liftShrink2  a -> [a]
shrA b -> [b]
_shrB (S.This a
x) = forall a b. a -> These a b
S.This forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> [a]
shrA a
x
    liftShrink2 a -> [a]
_shrA  b -> [b]
shrB (S.That b
y) = forall a b. b -> These a b
S.That forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> [b]
shrB b
y
    liftShrink2  a -> [a]
shrA  b -> [b]
shrB (S.These a
x b
y) =
        [forall a b. a -> These a b
S.This a
x, forall a b. b -> These a b
S.That b
y] forall a. [a] -> [a] -> [a]
++ [forall a b. a -> b -> These a b
S.These a
x' b
y' | (a
x', b
y') <- forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
shrA b -> [b]
shrB (a
x, b
y)]

-- | @since 0.3.24
instance (Arbitrary a) => Arbitrary1 (S.These a) where
    liftArbitrary :: forall a. Gen a -> Gen (These 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]) -> These a a -> [These 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

-- | @since 0.3.24
instance (Arbitrary a, Arbitrary b) => Arbitrary (S.These a b) where
    arbitrary :: Gen (These a b)
arbitrary = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: These a b -> [These a b]
shrink = forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1

-- | @since 0.3.24
instance (Function a, Function b) => Function (S.These a b) where
    function :: forall b. (These a b -> b) -> These a b :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap forall {a} {b}. These a b -> Either a (Either b (a, b))
g forall {a} {b}. Either a (Either b (a, b)) -> These a b
f
      where
        g :: These a b -> Either a (Either b (a, b))
g (S.This a
a)    = forall a b. a -> Either a b
Left a
a
        g (S.That b
b)    = forall a b. b -> Either a b
Right (forall a b. a -> Either a b
Left b
b)
        g (S.These a
a b
b) = forall a b. b -> Either a b
Right (forall a b. b -> Either a b
Right (a
a, b
b))

        f :: Either a (Either b (a, b)) -> These a b
f (Left a
a)               = forall a b. a -> These a b
S.This a
a
        f (Right (Left b
b))       = forall a b. b -> These a b
S.That b
b
        f (Right (Right (a
a, b
b))) = forall a b. a -> b -> These a b
S.These a
a b
b

-- | @since 0.3.24
instance (CoArbitrary a, CoArbitrary b) => CoArbitrary (S.These a b)