foundation-0.0.30: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | Foundation maintainers
Safe Haskell | None
Language | Haskell2010

Foundation.Check

Contents

- Property
- Check Plan

Description

An implementation of a test framework and property expression & testing

Synopsis

- data Gen a
- class Arbitrary a where
  - arbitrary :: Gen a
- oneof :: NonEmpty [Gen a] -> Gen a
- elements :: NonEmpty [a] -> Gen a
- frequency :: NonEmpty [(Word, Gen a)] -> Gen a
- between :: (Word, Word) -> Gen Word
- data Test where
  - Unit :: String -> IO () -> Test
  - Property :: forall prop. IsProperty prop => String -> prop -> Test
  - Group :: String -> [Test] -> Test
  - CheckPlan :: String -> Check () -> Test
- testName :: Test -> String
- data PropertyCheck
- data Property = Prop {
  - unProp :: Gen PropertyTestArg
  }
- class IsProperty p where
  - property :: p -> Property
- (===) :: (Show a, Eq a, Typeable a) => a -> a -> PropertyCheck
- propertyCompare :: (Show a, Typeable a) => String -> (a -> a -> Bool) -> a -> a -> PropertyCheck
- propertyCompareWith :: String -> (a -> a -> Bool) -> (a -> String) -> a -> a -> PropertyCheck
- propertyAnd :: PropertyCheck -> PropertyCheck -> PropertyCheck
- propertyFail :: String -> PropertyCheck
- forAll :: (Show a, IsProperty prop) => Gen a -> (a -> prop) -> Property
- data Check a
- validate :: IsProperty prop => String -> prop -> Check ()
- pick :: String -> IO a -> Check a
- iterateProperty :: CountOf TestResult -> GenParams -> (Word64 -> GenRng) -> Property -> IO (PropertyResult, CountOf TestResult)

# Documentation

data Gen a #

Generator monad

#### Instances

Instances details

Applicative Gen # |
Instance details Defined in Foundation.Check.Gen Methods pure :: a -> Gen a # (<*>) :: Gen (a -> b) -> Gen a -> Gen b # liftA2 :: (a -> b -> c) -> Gen a -> Gen b -> Gen c # (*>) :: Gen a -> Gen b -> Gen b # (<*) :: Gen a -> Gen b -> Gen a #
Functor Gen # |
Instance details Defined in Foundation.Check.Gen Methods fmap :: (a -> b) -> Gen a -> Gen b # (<$) :: a -> Gen b -> Gen a #
Monad Gen # |
Instance details Defined in Foundation.Check.Gen Methods (>>=) :: Gen a -> (a -> Gen b) -> Gen b # (>>) :: Gen a -> Gen b -> Gen b # return :: a -> Gen a #

class Arbitrary a where #

How to generate an arbitrary value for `a`

Methods

arbitrary :: Gen a #

#### Instances

Instances details

Arbitrary AsciiString # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen AsciiString #
Arbitrary Char7 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Char7 #
Arbitrary Word128 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word128 #
Arbitrary Word256 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word256 #
Arbitrary String # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen String #
Arbitrary Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods arbitrary :: Gen Field #
Arbitrary Int16 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int16 #
Arbitrary Int32 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int32 #
Arbitrary Int64 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int64 #
Arbitrary Int8 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int8 #
Arbitrary Word16 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word16 #
Arbitrary Word32 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word32 #
Arbitrary Word64 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word64 #
Arbitrary Word8 # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word8 #
Arbitrary Integer # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Integer #
Arbitrary Natural # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Natural #
Arbitrary Bool # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Bool #
Arbitrary Char # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Char #
Arbitrary Double # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Double #
Arbitrary Float # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Float #
Arbitrary Int # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Int #
Arbitrary Word # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen Word #
KnownNat n => Arbitrary (Zn n) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Zn n) #
(NatWithinBound Word64 n, KnownNat n) => Arbitrary (Zn64 n) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Zn64 n) #
Arbitrary (CountOf ty) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (CountOf ty) #
Arbitrary a => Arbitrary (Maybe a) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Maybe a) #
Arbitrary a => Arbitrary [a] # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen [a] #
(Arbitrary a, KnownNat n, NatWithinBound Int n) => Arbitrary (ListN n a) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (ListN n a) #
(Arbitrary l, Arbitrary r) => Arbitrary (Either l r) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (Either l r) #
(Arbitrary a, Arbitrary b) => Arbitrary (a, b) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b) #
(Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (a, b, c) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c) #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => Arbitrary (a, b, c, d) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d) #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e) => Arbitrary (a, b, c, d, e) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d, e) #
(Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, Arbitrary f) => Arbitrary (a, b, c, d, e, f) # |
Instance details Defined in Foundation.Check.Arbitrary Methods arbitrary :: Gen (a, b, c, d, e, f) #

oneof :: NonEmpty [Gen a] -> Gen a #

elements :: NonEmpty [a] -> Gen a #

frequency :: NonEmpty [(Word, Gen a)] -> Gen a #

Call one of the generator weighted

between :: (Word, Word) -> Gen Word #

data Test where #

different type of tests supported

Constructors

Unit :: String -> IO () -> Test |
Property :: forall prop. IsProperty prop => String -> prop -> Test |
Group :: String -> [Test] -> Test |
CheckPlan :: String -> Check () -> Test |

testName :: Test -> String #

Name of a test

# Property

data PropertyCheck #

The type of check this test did for a property

#### Instances

Instances details

IsProperty PropertyCheck # |
Instance details Defined in Foundation.Check.Property Methods property :: PropertyCheck -> Property #

data Property #

Constructors

Prop |
Fields unProp :: Gen PropertyTestArg

#### Instances

Instances details

IsProperty Property # |
Instance details Defined in Foundation.Check.Property Methods property :: Property -> Property #

class IsProperty p where #

Methods

property :: p -> Property #

#### Instances

Instances details

IsProperty Property # |
Instance details Defined in Foundation.Check.Property Methods property :: Property -> Property #
IsProperty PropertyCheck # |
Instance details Defined in Foundation.Check.Property Methods property :: PropertyCheck -> Property #
IsProperty Bool # |
Instance details Defined in Foundation.Check.Property Methods property :: Bool -> Property #
IsProperty (String, Bool) # |
Instance details Defined in Foundation.Check.Property Methods property :: (String, Bool) -> Property #
(Show a, Arbitrary a, IsProperty prop) => IsProperty (a -> prop) # |
Instance details Defined in Foundation.Check.Property Methods property :: (a -> prop) -> Property #

(===) :: (Show a, Eq a, Typeable a) => a -> a -> PropertyCheck infix 4 #

A property that check for equality of its 2 members.

propertyCompare #

Arguments

:: (Show a, Typeable a) |
=> String | name of the function used for comparaison, e.g. (<)
-> (a -> a -> Bool) | function used for value comparaison
-> a | value left of the operator
-> a | value right of the operator
-> PropertyCheck |

A property that check for a specific comparaison of its 2 members.

This is equivalent to `===` but with `compare`

propertyCompareWith #

Arguments

:: String | name of the function used for comparaison, e.g. (<)
-> (a -> a -> Bool) | function used for value comparaison
-> (a -> String) | function used to pretty print the values
-> a | value left of the operator
-> a | value right of the operator
-> PropertyCheck |

A property that check for a specific comparaison of its 2 members.

This is equivalent to `===` but with `compare` and a given method to pretty print the values.

propertyAnd :: PropertyCheck -> PropertyCheck -> PropertyCheck #

A conjuctive property composed of 2 properties that need to pass

propertyFail :: String -> PropertyCheck #

forAll :: (Show a, IsProperty prop) => Gen a -> (a -> prop) -> Property #

Running a generator for a specific type under a property

# Check Plan

data Check a #

#### Instances

Instances details

MonadState Check # |
Instance details Defined in Foundation.Check.Types Associated Types
type State Check |
Instance details Defined in Foundation.Check.Types type State Check
Methods withState :: (State Check -> (a, State Check)) -> Check a #
Applicative Check # |
Instance details Defined in Foundation.Check.Types Methods pure :: a -> Check a # (<*>) :: Check (a -> b) -> Check a -> Check b # liftA2 :: (a -> b -> c) -> Check a -> Check b -> Check c # (*>) :: Check a -> Check b -> Check b # (<*) :: Check a -> Check b -> Check a #
Functor Check # |
Instance details Defined in Foundation.Check.Types Methods fmap :: (a -> b) -> Check a -> Check b # (<$) :: a -> Check b -> Check a #
Monad Check # |
Instance details Defined in Foundation.Check.Types Methods (>>=) :: Check a -> (a -> Check b) -> Check b # (>>) :: Check a -> Check b -> Check b # return :: a -> Check a #
type State Check # |
Instance details Defined in Foundation.Check.Types type State Check

validate :: IsProperty prop => String -> prop -> Check () #

pick :: String -> IO a -> Check a #

iterateProperty :: CountOf TestResult -> GenParams -> (Word64 -> GenRng) -> Property -> IO (PropertyResult, CountOf TestResult) #