{-# 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 :: Gen a -> Gen b -> Gen (Pair a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = a -> b -> Pair a b
forall a b. a -> b -> Pair a b
(S.:!:) (a -> b -> Pair a b) -> Gen a -> Gen (b -> Pair a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA Gen (b -> Pair a b) -> Gen b -> Gen (Pair a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen b
arbB

    liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Pair a b -> [Pair a b]
liftShrink2  a -> [a]
shrA b -> [b]
shrB (a
x S.:!: b
y) = (a -> b -> Pair a b) -> (a, b) -> Pair a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Pair a b
forall a b. a -> b -> Pair a b
(S.:!:) ((a, b) -> Pair a b) -> [(a, b)] -> [Pair a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 
        (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, 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 :: Gen a -> Gen (Pair a a)
liftArbitrary = Gen a -> Gen a -> Gen (Pair a a)
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 Gen a
forall a. Arbitrary a => Gen a
arbitrary
    liftShrink :: (a -> [a]) -> Pair a a -> [Pair a a]
liftShrink = (a -> [a]) -> (a -> [a]) -> Pair a a -> [Pair a a]
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
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 = Gen (Pair a b)
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Pair a b -> [Pair a b]
shrink = Pair a b -> [Pair a b]
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 :: (Pair a b -> b) -> Pair a b :-> b
function = (Pair a b -> (a, b))
-> ((a, b) -> Pair a b) -> (Pair a b -> b) -> Pair a b :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Pair a b -> (a, b)
forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy (a, b) -> Pair a b
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 :: Gen a -> Gen (Maybe a)
liftArbitrary Gen a
arb = [(Int, Gen (Maybe a))] -> Gen (Maybe a)
forall a. [(Int, Gen a)] -> Gen a
frequency
        [ (Int
1, Maybe a -> Gen (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
S.Nothing)
        , (Int
9, a -> Maybe a
forall a. a -> Maybe a
S.Just (a -> Maybe a) -> Gen a -> Gen (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arb)
        ]

    liftShrink :: (a -> [a]) -> Maybe a -> [Maybe a]
liftShrink a -> [a]
_shr Maybe a
S.Nothing  = []
    liftShrink  a -> [a]
shr (S.Just a
x) = Maybe a
forall a. Maybe a
S.Nothing Maybe a -> [Maybe a] -> [Maybe a]
forall a. a -> [a] -> [a]
: (a -> Maybe a) -> [a] -> [Maybe a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Maybe a
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 = Gen (Maybe a)
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Maybe a -> [Maybe a]
shrink = Maybe a -> [Maybe a]
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 :: (Maybe a -> b) -> Maybe a :-> b
function = (Maybe a -> Maybe a)
-> (Maybe a -> Maybe a) -> (Maybe a -> b) -> Maybe a :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Maybe a -> Maybe a
forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy Maybe a -> Maybe a
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 :: Gen a -> Gen b -> Gen (Either a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = [Gen (Either a b)] -> Gen (Either a b)
forall a. [Gen a] -> Gen a
oneof
        [ a -> Either a b
forall a b. a -> Either a b
S.Left (a -> Either a b) -> Gen a -> Gen (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA
        , b -> Either a b
forall a b. b -> Either a b
S.Right (b -> Either a b) -> Gen b -> Gen (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen b
arbB
        ]

    liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Either a b -> [Either a b]
liftShrink2  a -> [a]
shrA b -> [b]
_shrB (S.Left a
x)  = a -> Either a b
forall a b. a -> Either a b
S.Left (a -> Either a b) -> [a] -> [Either a b]
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) = b -> Either a b
forall a b. b -> Either a b
S.Right (b -> Either a b) -> [b] -> [Either a b]
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 :: Gen a -> Gen (Either a a)
liftArbitrary = Gen a -> Gen a -> Gen (Either a a)
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 Gen a
forall a. Arbitrary a => Gen a
arbitrary
    liftShrink :: (a -> [a]) -> Either a a -> [Either a a]
liftShrink = (a -> [a]) -> (a -> [a]) -> Either a a -> [Either a a]
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
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 = Gen (Either a b)
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Either a b -> [Either a b]
shrink = Either a b -> [Either a b]
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 :: (Either a b -> b) -> Either a b :-> b
function = (Either a b -> Either a b)
-> (Either a b -> Either a b)
-> (Either a b -> b)
-> Either a b :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Either a b -> Either a b
forall lazy strict. Strict lazy strict => strict -> lazy
S.toLazy Either a b -> Either a b
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 :: Gen a -> Gen b -> Gen (These a b)
liftArbitrary2 Gen a
arbA Gen b
arbB = [Gen (These a b)] -> Gen (These a b)
forall a. [Gen a] -> Gen a
oneof
        [ a -> These a b
forall a b. a -> These a b
S.This (a -> These a b) -> Gen a -> Gen (These a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA
        , b -> These a b
forall a b. b -> These a b
S.That (b -> These a b) -> Gen b -> Gen (These a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen b
arbB
        , a -> b -> These a b
forall a b. a -> b -> These a b
S.These (a -> b -> These a b) -> Gen a -> Gen (b -> These a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
arbA Gen (b -> These a b) -> Gen b -> Gen (These a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen b
arbB
        ]

    liftShrink2 :: (a -> [a]) -> (b -> [b]) -> These a b -> [These a b]
liftShrink2  a -> [a]
shrA b -> [b]
_shrB (S.This a
x) = a -> These a b
forall a b. a -> These a b
S.This (a -> These a b) -> [a] -> [These a b]
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) = b -> These a b
forall a b. b -> These a b
S.That (b -> These a b) -> [b] -> [These a b]
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) =
        [a -> These a b
forall a b. a -> These a b
S.This a
x, b -> These a b
forall a b. b -> These a b
S.That b
y] [These a b] -> [These a b] -> [These a b]
forall a. [a] -> [a] -> [a]
++ [a -> b -> These a b
forall a b. a -> b -> These a b
S.These a
x' b
y' | (a
x', b
y') <- (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, 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.These a) where
    liftArbitrary :: Gen a -> Gen (These a a)
liftArbitrary = Gen a -> Gen a -> Gen (These a a)
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 Gen a
forall a. Arbitrary a => Gen a
arbitrary
    liftShrink :: (a -> [a]) -> These a a -> [These a a]
liftShrink = (a -> [a]) -> (a -> [a]) -> These a a -> [These a a]
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
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 = Gen (These a b)
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: These a b -> [These a b]
shrink = These a b -> [These a b]
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 :: (These a b -> b) -> These a b :-> b
function = (These a b -> Either a (Either b (a, b)))
-> (Either a (Either b (a, b)) -> These a b)
-> (These a b -> b)
-> These a b :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap These a b -> Either a (Either b (a, b))
forall a b. These a b -> Either a (Either b (a, b))
g Either a (Either b (a, b)) -> These a b
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)    = a -> Either a (Either b (a, b))
forall a b. a -> Either a b
Left a
a
        g (S.That b
b)    = Either b (a, b) -> Either a (Either b (a, b))
forall a b. b -> Either a b
Right (b -> Either b (a, b)
forall a b. a -> Either a b
Left b
b)
        g (S.These a
a b
b) = Either b (a, b) -> Either a (Either b (a, b))
forall a b. b -> Either a b
Right ((a, b) -> Either b (a, b)
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)               = a -> These a b
forall a b. a -> These a b
S.This a
a
        f (Right (Left b
b))       = b -> These a b
forall a b. b -> These a b
S.That b
b
        f (Right (Right (a
a, b
b))) = a -> b -> These a 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)