{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Test.Validity.Arbitrary
( arbitrarySpec,
arbitraryGeneratesOnlyValid,
)
where
import Data.Data
import Data.GenValidity
import Test.Hspec
import Test.QuickCheck
import Test.Validity.GenValidity
import Test.Validity.Utils
arbitrarySpec ::
forall a.
(Typeable a, Show a, Validity a, Arbitrary a) =>
Spec
arbitrarySpec :: Spec
arbitrarySpec = do
let name :: String
name = Typeable a => String
forall k (a :: k). Typeable a => String
nameOf @a
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe (String
"Arbitrary " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name) (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe (String
"arbitrary :: Gen " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name) (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"only generates valid values" (Property -> SpecWith (Arg Property))
-> Property -> SpecWith (Arg Property)
forall a b. (a -> b) -> a -> b
$ (Show a, Validity a, Arbitrary a) => Property
forall a. (Show a, Validity a, Arbitrary a) => Property
arbitraryGeneratesOnlyValid @a
arbitraryGeneratesOnlyValid ::
forall a.
(Show a, Validity a, Arbitrary a) =>
Property
arbitraryGeneratesOnlyValid :: Property
arbitraryGeneratesOnlyValid = Gen a -> Property
forall a. (Show a, Validity a) => Gen a -> Property
genGeneratesValid @a Gen a
forall a. Arbitrary a => Gen a
arbitrary