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

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

import Data.Word (Word64)

import Test.QuickCheck
import Test.QuickCheck.Gen (chooseUpTo)

import qualified Data.UUID.Types as UUID

-------------------------------------------------------------------------------
-- uuid
-------------------------------------------------------------------------------

uuidFromWords64 :: (Word64, Word64) -> UUID.UUID
uuidFromWords64 :: (Word64, Word64) -> UUID
uuidFromWords64 (Word64
a,Word64
b) = Word64 -> Word64 -> UUID
UUID.fromWords64 Word64
a Word64
b

uniformWord64 :: Gen Word64
uniformWord64 :: Gen Word64
uniformWord64 = Word64 -> Gen Word64
chooseUpTo forall a. Bounded a => a
maxBound

-- | Uniform distribution.
instance Arbitrary UUID.UUID where
    arbitrary :: Gen UUID
arbitrary = Word64 -> Word64 -> UUID
UUID.fromWords64 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
uniformWord64 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Word64
uniformWord64
    shrink :: UUID -> [UUID]
shrink = forall a b. (a -> b) -> [a] -> [b]
map (Word64, Word64) -> UUID
uuidFromWords64 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
. UUID -> (Word64, Word64)
UUID.toWords64

instance CoArbitrary UUID.UUID where
    coarbitrary :: forall b. UUID -> 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
. UUID -> (Word32, Word32, Word32, Word32)
UUID.toWords

instance Function UUID.UUID where
    function :: forall b. (UUID -> b) -> UUID :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap UUID -> (Word64, Word64)
UUID.toWords64 (Word64, Word64) -> UUID
uuidFromWords64