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

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

import Test.QuickCheck
import Test.QuickCheck.Function ((:->))

import qualified Data.Vector          as Vector
import qualified Data.Vector.Generic  as GVector
import qualified Data.Vector.Storable as SVector
import qualified Data.Vector.Unboxed  as UVector

-------------------------------------------------------------------------------
-- vector
-------------------------------------------------------------------------------

instance Arbitrary1 Vector.Vector where
    liftArbitrary :: forall a. Gen a -> Gen (Vector a)
liftArbitrary = ([a] -> Vector a) -> Gen [a] -> Gen (Vector a)
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> Vector a
forall a. [a] -> Vector a
Vector.fromList (Gen [a] -> Gen (Vector a))
-> (Gen a -> Gen [a]) -> Gen a -> Gen (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen a -> Gen [a]
forall a. Gen a -> Gen [a]
forall (f :: * -> *) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary
    liftShrink :: forall a. (a -> [a]) -> Vector a -> [Vector a]
liftShrink a -> [a]
shr = ([a] -> Vector a) -> [[a]] -> [Vector a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> Vector a
forall a. [a] -> Vector a
Vector.fromList ([[a]] -> [Vector a])
-> (Vector a -> [[a]]) -> Vector a -> [Vector a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [a]) -> [a] -> [[a]]
forall a. (a -> [a]) -> [a] -> [[a]]
forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr ([a] -> [[a]]) -> (Vector a -> [a]) -> Vector a -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Vector a -> [a]
Vector.toList

instance Arbitrary a => Arbitrary (Vector.Vector a) where
    arbitrary :: Gen (Vector a)
arbitrary = Gen (Vector a)
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => Gen (f a)
arbitrary1
    shrink :: Vector a -> [Vector a]
shrink = Vector a -> [Vector a]
forall (f :: * -> *) a. (Arbitrary1 f, Arbitrary a) => f a -> [f a]
shrink1

instance CoArbitrary a => CoArbitrary (Vector.Vector a) where
    coarbitrary :: forall b. Vector a -> Gen b -> Gen b
coarbitrary = Vector a -> Gen b -> Gen b
forall (v :: * -> *) a b.
(Vector v a, CoArbitrary a) =>
v a -> Gen b -> Gen b
coarbitraryVector

instance Function a => Function (Vector.Vector a) where
    function :: forall b. (Vector a -> b) -> Vector a :-> b
function = (Vector a -> b) -> Vector a :-> b
forall (v :: * -> *) a c.
(Vector v a, Function a) =>
(v a -> c) -> v a :-> c
functionVector


instance (SVector.Storable a, Arbitrary a) => Arbitrary (SVector.Vector a) where
    arbitrary :: Gen (Vector a)
arbitrary = Gen (Vector a)
forall (v :: * -> *) a. (Vector v a, Arbitrary a) => Gen (v a)
arbitraryVector
    shrink :: Vector a -> [Vector a]
shrink = Vector a -> [Vector a]
forall (v :: * -> *) a. (Vector v a, Arbitrary a) => v a -> [v a]
shrinkVector

instance (SVector.Storable a, CoArbitrary a) => CoArbitrary (SVector.Vector a) where
    coarbitrary :: forall b. Vector a -> Gen b -> Gen b
coarbitrary = Vector a -> Gen b -> Gen b
forall (v :: * -> *) a b.
(Vector v a, CoArbitrary a) =>
v a -> Gen b -> Gen b
coarbitraryVector

instance (SVector.Storable a, Function a) => Function (SVector.Vector a) where
    function :: forall b. (Vector a -> b) -> Vector a :-> b
function = (Vector a -> b) -> Vector a :-> b
forall (v :: * -> *) a c.
(Vector v a, Function a) =>
(v a -> c) -> v a :-> c
functionVector

instance (UVector.Unbox a, Arbitrary a) => Arbitrary (UVector.Vector a) where
    arbitrary :: Gen (Vector a)
arbitrary = Gen (Vector a)
forall (v :: * -> *) a. (Vector v a, Arbitrary a) => Gen (v a)
arbitraryVector
    shrink :: Vector a -> [Vector a]
shrink = Vector a -> [Vector a]
forall (v :: * -> *) a. (Vector v a, Arbitrary a) => v a -> [v a]
shrinkVector

instance (UVector.Unbox a, CoArbitrary a) => CoArbitrary (UVector.Vector a) where
    coarbitrary :: forall b. Vector a -> Gen b -> Gen b
coarbitrary = Vector a -> Gen b -> Gen b
forall (v :: * -> *) a b.
(Vector v a, CoArbitrary a) =>
v a -> Gen b -> Gen b
coarbitraryVector

instance (UVector.Unbox a, Function a) => Function (UVector.Vector a) where
    function :: forall b. (Vector a -> b) -> Vector a :-> b
function = (Vector a -> b) -> Vector a :-> b
forall (v :: * -> *) a c.
(Vector v a, Function a) =>
(v a -> c) -> v a :-> c
functionVector

arbitraryVector :: (GVector.Vector v a, Arbitrary a) => Gen (v a)
arbitraryVector :: forall (v :: * -> *) a. (Vector v a, Arbitrary a) => Gen (v a)
arbitraryVector = [a] -> v a
forall (v :: * -> *) a. Vector v a => [a] -> v a
GVector.fromList ([a] -> v a) -> Gen [a] -> Gen (v a)
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Gen [a]
forall a. Arbitrary a => Gen a
arbitrary

shrinkVector :: (GVector.Vector v a, Arbitrary a) => v a -> [v a]
shrinkVector :: forall (v :: * -> *) a. (Vector v a, Arbitrary a) => v a -> [v a]
shrinkVector = ([a] -> v a) -> [[a]] -> [v a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> v a
forall (v :: * -> *) a. Vector v a => [a] -> v a
GVector.fromList ([[a]] -> [v a]) -> (v a -> [[a]]) -> v a -> [v a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [[a]]
forall a. Arbitrary a => a -> [a]
shrink ([a] -> [[a]]) -> (v a -> [a]) -> v a -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
GVector.toList

coarbitraryVector :: (GVector.Vector v a, CoArbitrary a) => v a -> Gen b -> Gen b
coarbitraryVector :: forall (v :: * -> *) a b.
(Vector v a, CoArbitrary a) =>
v a -> Gen b -> Gen b
coarbitraryVector = [a] -> Gen b -> Gen b
forall b. [a] -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary ([a] -> Gen b -> Gen b) -> (v a -> [a]) -> v a -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
GVector.toList

functionVector :: (GVector.Vector v a, Function a) => (v a -> c) -> v a :-> c
functionVector :: forall (v :: * -> *) a c.
(Vector v a, Function a) =>
(v a -> c) -> v a :-> c
functionVector = (v a -> [a]) -> ([a] -> v a) -> (v a -> c) -> v a :-> c
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap v a -> [a]
forall (v :: * -> *) a. Vector v a => v a -> [a]
GVector.toList [a] -> v a
forall (v :: * -> *) a. Vector v a => [a] -> v a
GVector.fromList