{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Constrained.Test where
import Constrained.API
import Constrained.Examples.Basic
import Constrained.Examples.Either
import Constrained.Examples.Fold (
Outcome (..),
evenSpec,
listSumComplex,
logishProp,
oddSpec,
pickProp,
sum3,
sum3WithLength,
sumProp,
sumProp2,
testFoldSpec,
)
import Constrained.Examples.List
import Constrained.Examples.Map
import Constrained.Examples.Set
import Constrained.Examples.Tree
import Constrained.Properties hiding (main)
import Constrained.SumList (narrowByFuelAndSize)
import Control.Monad
import Data.Int
import qualified Data.List.NonEmpty as NE
import Data.Map (Map)
import Data.Set (Set)
import Data.Typeable
import Data.Word
import GHC.Natural
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck hiding (Args, Fun, forAll)
testAll :: IO ()
testAll :: IO ()
testAll = Spec -> IO ()
hspec forall a b. (a -> b) -> a -> b
$ Bool -> Spec
tests Bool
False
tests :: Bool -> Spec
tests :: Bool -> Spec
tests Bool
nightly =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"constrained" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (Int -> Int) -> SpecWith a -> SpecWith a
modifyMaxSuccess (\Int
ms -> if Bool
nightly then Int
ms forall a. Num a => a -> a -> a
* Int
10 else Int
ms) forall a b. (a -> b) -> a -> b
$ do
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"reifiesMultiple" Specification (Int, Int, Int)
reifiesMultiple
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"assertReal" Specification Int
assertReal
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"chooseBackwards" Specification (Int, [Int])
chooseBackwards
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"chooseBackwards'" Specification ([(Int, [Int])], (Int, [Int]))
chooseBackwards'
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"assertRealMultiple" Specification (Int, Int)
assertRealMultiple
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"setSpec" Specification (Set Int)
setSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"leqPair" Specification (Int, Int)
leqPair
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"setPair" Specification (Set (Int, Int))
setPair
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"listEmpty" Specification [Int]
listEmpty
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"compositionalSpec" Specification (Set Int)
compositionalSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"simplePairSpec" Specification (Int, Int)
simplePairSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"trickyCompositional" Specification (Int, Int)
trickyCompositional
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"emptyListSpec" Specification ([Int], NotASet (Either Int Int, Int))
emptyListSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"eitherSpec" Specification (Either Int Int)
eitherSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"maybeSpec" Specification (Set (Maybe Int))
maybeSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"eitherSetSpec" Specification
(Set (Either Int Int), Set (Either Int Int), Set (Either Int Int))
eitherSetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"fooSpec" Specification Foo
fooSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapElemSpec" Specification (Map Int (Bool, Int))
mapElemSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapElemKeySpec" Specification Int
mapElemKeySpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"mapIsJust" Specification (Int, Int)
mapIsJust
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"intSpec" Specification (Int, Int)
intSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"mapPairSpec" Specification (Map Int Int, Set Int)
mapPairSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"mapEmptyDomainSpec" Specification (Map Int Int)
mapEmptyDomainSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"setPairSpec" Specification (Set Int, Set Int)
setPairSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"fixedSetSpec" Specification (Set Int)
fixedSetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"setOfPairLetSpec" Specification (Set (Int, Int))
setOfPairLetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"emptyEitherSpec" Specification (Set (Either Int Int))
emptyEitherSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"emptyEitherMemberSpec" Specification (Set (Either Int Int))
emptyEitherMemberSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"setSingletonSpec" Specification (Set (Int, Int))
setSingletonSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"pairSingletonSpec" Specification (Int, Int)
pairSingletonSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"eitherSimpleSetSpec" Specification (Set (Either Int Int))
eitherSimpleSetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"emptySetSpec" Specification (Set Int)
emptySetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"forAllAnySpec" Specification (Set Int)
forAllAnySpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"notSubsetSpec" Specification (Set Int, Set Int)
notSubsetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"maybeJustSetSpec" Specification (Set (Maybe Int))
maybeJustSetSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"weirdSetPairSpec" Specification ([Int], Set (Either Int Int))
weirdSetPairSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"knownDomainMap" Specification (Map Int Int)
knownDomainMap
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"testRewriteSpec" Specification ((Int, Int), (Int, Int))
testRewriteSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"parallelLet" Specification (Int, Int)
parallelLet
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"letExists" Specification (Int, Int)
letExists
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"letExistsLet" Specification (Int, Int)
letExistsLet
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"notSubset" Specification (Set Int)
notSubset
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"unionSized" Specification (Set Int)
unionSized
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"dependencyWeirdness" Specification (Int, Int, Int)
dependencyWeirdness
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"foldTrueCases" Specification (Either Int Int)
foldTrueCases
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"foldSingleCase" Specification Int
foldSingleCase
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"listSumPair" (forall a. Numbery a => Specification [(a, Int)]
listSumPair @Int)
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"parallelLetPair" Specification (Int, Int)
parallelLetPair
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapSizeConstrained" Specification (Map Three Int)
mapSizeConstrained
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"isAllZeroTree" Specification (Tree Int)
isAllZeroTree
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"noChildrenSameTree" Specification (BinTree Int)
noChildrenSameTree
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"isBST" Specification (BinTree Int)
isBST
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"pairListError" Specification [(Int, Int)]
pairListError
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"listMustSizeIssue" Specification [Int]
listMustSizeIssue
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"successiveChildren" Specification (Tree Int)
successiveChildren
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"successiveChildren8" Specification (Tree Int)
successiveChildren8
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"roseTreeList" Specification [Tree Int]
roseTreeList
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"orPair" Specification (Int, Int)
orPair
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"roseTreePairs" Specification (Tree ([Int], [Int]))
roseTreePairs
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"roseTreeMaybe" Specification (Tree (Maybe (Int, Int)))
roseTreeMaybe
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"badTreeInteraction" Specification (Tree (Either Int Int))
badTreeInteraction
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"sumRange" Specification (Map Word64 Word64)
sumRange
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"sumListBad" Specification [Word64]
sumListBad
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"listExistsUnfree" Specification [Int]
listExistsUnfree
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"existsUnfree" Specification Int
existsUnfree
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"appendSize" Specification ([Int], [Int])
appendSize
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"appendSingleton" Specification Int
appendSingleton
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"singletonSubset" Specification Int
singletonSubset
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"reifyYucky" Specification (Int, Int, Int)
reifyYucky
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"fixedRange" Specification (Map Int Int)
fixedRange
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"rangeHint" Specification (Map Int Int)
rangeHint
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"basicSpec" Specification Int
basicSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"canFollowLike" Specification ((Int, Int), (Int, Int))
canFollowLike
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"ifElseBackwards" Specification (Int, Int)
ifElseBackwards
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"three" Specification Three
three
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"three'" Specification Three
three'
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"threeSpecific" Specification Three
threeSpecific
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"threeSpecific'" Specification Three
threeSpecific'
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"trueSpecUniform" Specification Three
trueSpecUniform
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"ifElseMany" Specification (Bool, Int, Int)
ifElseMany
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"propBack" Specification (Int, Int)
propBack
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"propBack'" Specification (Int, Int)
propBack'
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"propBack''" Specification (Int, Int)
propBack''
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"complexUnion" Specification (Set Int, Set Int)
complexUnion
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"unionBounded" Specification (Set Int)
unionBounded
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"elemSpec" Specification (Int, Int, Map Int Int)
elemSpec
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"lookupSpecific" Specification (Int, Int, Map Int Int)
lookupSpecific
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapRestrictedValues" Specification (Map (Either Int ()) Int)
mapRestrictedValues
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapRestrictedValuesThree" Specification (Map Three Int)
mapRestrictedValuesThree
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapRestrictedValuesBool" Specification (Map Bool Int)
mapRestrictedValuesBool
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"mapSetSmall" Specification (Map (Set Int) Int)
mapSetSmall
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"powersetPickOne" Specification (Set Int)
powersetPickOne
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"appendSuffix" Specification ([Int], [Int])
appendSuffix
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"appendForAll" Specification ([Int], [Int])
appendForAll
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"wtfSpec" Specification ([Int], Maybe ((), [Int]))
wtfSpec
Spec
numberyTests
Spec
sizeTests
Spec
numNumSpecTree
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
[ forall a. HasSpec a => String -> Specification a -> Spec
testSpec (String
"intRangeSpec " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
i) (Int -> Specification Int
intRangeSpec Int
i)
| Int
i <- [-Int
1000, -Int
100, -Int
10, Int
0, Int
10, Int
100, Int
1000]
]
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"prop_conformEmpty" forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => a -> Property
prop_conformEmpty @Int
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => a -> Property
prop_conformEmpty @(Set Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Map Int Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => a -> Property
prop_conformEmpty @(Map Int Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[Int]" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => a -> Property
prop_conformEmpty @[Int]
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[(Int, Int)]" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => a -> Property
prop_conformEmpty @[(Int, Int)]
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_univSound @BaseFn" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess (if Bool
nightly then Int
100_000 else Int
10_000) forall a b. (a -> b) -> a -> b
$
TestableFn -> Property
prop_univSound
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"prop_gen_sound" forall a b. (a -> b) -> a -> b
$ do
forall a. (Int -> Int) -> SpecWith a -> SpecWith a
modifyMaxSuccess (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ if Bool
nightly then Int
10_000 else Int
1000) forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @Int
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Bool" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @Bool
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(Int, Int)" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Int, Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Map Int Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Map Int Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Set Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set Bool" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Set Bool)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[Int]" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @[Int]
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[(Int, Int)]" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @[(Int, Int)]
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Map Bool Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Map Bool Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
xprop String
"Map (Set Int) Int" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Map (Set Int) Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[(Set Int, Set Bool)]" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @[(Set Int, Set Bool)]
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set (Set Bool)" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_gen_sound @(Set (Set Bool))
Spec
negativeTests
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_noNarrowLoop" forall a b. (a -> b) -> a -> b
$ forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
1000 Int -> Int -> Specification Int -> Specification Int -> Property
prop_noNarrowLoop
Spec
conformsToSpecESpec
Spec
foldWithSizeTests
negativeTests :: Spec
negativeTests :: Spec
negativeTests =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"negative tests" forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"reifies 10 x id" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => prop -> Property
expectFailure forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_complete @Int forall a b. (a -> b) -> a -> b
$
forall a p.
(IsPred p, HasSpec a) =>
(Term a -> p) -> Specification a
constrained forall a b. (a -> b) -> a -> b
$
\Term Int
x ->
NonEmpty String -> Pred -> Pred
explanation (forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"The value is decided before reifies happens") forall a b. (a -> b) -> a -> b
$
forall a b.
(HasSpec a, HasSpec b) =>
Term b -> Term a -> (a -> b) -> Pred
reifies Term Int
10 Term Int
x forall a. a -> a
id
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"reify overconstrained" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => prop -> Property
expectFailure forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_complete @Int forall a b. (a -> b) -> a -> b
$
forall a p.
(IsPred p, HasSpec a) =>
(Term a -> p) -> Specification a
constrained forall a b. (a -> b) -> a -> b
$ \Term Int
x ->
NonEmpty String -> Pred -> Pred
explanation
(forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"You can't constrain the variable introduced by reify as its already decided")
forall a b. (a -> b) -> a -> b
$ forall a b p.
(HasSpec a, HasSpec b, IsPred p) =>
Term a -> (a -> b) -> (Term b -> p) -> Pred
reify Term Int
x forall a. a -> a
id
forall a b. (a -> b) -> a -> b
$ \Term Int
y -> Term Int
y forall a. HasSpec a => Term a -> Term a -> Term Bool
==. Term Int
10
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"singletonErrorTooMany" Specification Int
singletonErrorTooMany
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"singletonErrorTooLong" Specification Int
singletonErrorTooLong
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"appendTooLong" Specification [Int]
appendTooLong
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"overconstrainedAppend" Specification ([Int], [Int])
overconstrainedAppend
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"overconstrainedPrefixes" Specification ([Int], [Int], [Int])
overconstrainedPrefixes
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"overconstrainedSuffixes" Specification ([Int], [Int], [Int])
overconstrainedSuffixes
forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
"appendForAllBad" Specification ([Int], [Int])
appendForAllBad
testSpecFail :: HasSpec a => String -> Specification a -> Spec
testSpecFail :: forall a. HasSpec a => String -> Specification a -> Spec
testSpecFail String
s Specification a
spec =
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop (String
s forall a. [a] -> [a] -> [a]
++ String
" fails") forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => prop -> Property
expectFailure forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
1 forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_complete Specification a
spec
numberyTests :: Spec
numberyTests :: Spec
numberyTests =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"numbery tests" forall a b. (a -> b) -> a -> b
$ do
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec String
"listSum" forall a. Numbery a => Specification [a]
listSum
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpecNoShrink String
"listSumForall" forall a. Numbery a => Specification [a]
listSumForall
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec String
"listSumRange" forall a. Numbery a => Specification [a]
listSumRange
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec String
"listSumRangeUpper" forall a. Numbery a => Specification [a]
listSumRangeUpper
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec String
"listSumRangeRange" forall a. Numbery a => Specification [a]
listSumRangeRange
String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec String
"listSumElemRange" forall a. Numbery a => Specification [a]
listSumElemRange
sizeTests :: Spec
sizeTests :: Spec
sizeTests =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"SizeTests" forall a b. (a -> b) -> a -> b
$ do
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub1" Specification Integer
sizeAddOrSub1
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub2" Specification Integer
sizeAddOrSub2
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub3" Specification Integer
sizeAddOrSub3
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub4 returns Negative Size" Specification Integer
sizeAddOrSub4
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub5" Specification Integer
sizeAddOrSub5
forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink String
"sizeAddOrSub5" Specification Integer
sizeAddOrSub5
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"listSubSize" Specification [Int]
listSubSize
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"listSubSize" Specification (Set Int)
setSubSize
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"listSubSize" Specification (Map Int Int)
mapSubSize
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"hasSizeList" Specification [Int]
hasSizeList
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"hasSizeSet" Specification (Set Int)
hasSizeSet
forall a. HasSpec a => String -> Specification a -> Spec
testSpec String
"hasSizeMap" Specification (Map Int Int)
hasSizeMap
data NumberyType where
N :: (Typeable a, Numbery a) => Proxy a -> NumberyType
testNumberyListSpec :: String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec :: String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec = Bool
-> String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec' Bool
True
testNumberyListSpecNoShrink :: String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpecNoShrink :: String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpecNoShrink = Bool
-> String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec' Bool
False
testNumberyListSpec' :: Bool -> String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec' :: Bool
-> String -> (forall a. Numbery a => Specification [a]) -> Spec
testNumberyListSpec' Bool
withShrink String
n forall a. Numbery a => Specification [a]
p =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
n forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
[ forall a. HasSpec a => Bool -> String -> Specification a -> Spec
testSpec' Bool
withShrink (forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep Proxy a
proxy) (forall a. Numbery a => Specification [a]
p @a)
| N (Proxy a
proxy :: Proxy a) <- [NumberyType]
numberyTypes
]
where
numberyTypes :: [NumberyType]
numberyTypes =
[ forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Int forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Integer forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Natural forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Word64 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Word32 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Word16 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Word8 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Int64 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Int32 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Int16 forall {k} (t :: k). Proxy t
Proxy
, forall a. (Typeable a, Numbery a) => Proxy a -> NumberyType
N @Int8 forall {k} (t :: k). Proxy t
Proxy
]
testSpec :: HasSpec a => String -> Specification a -> Spec
testSpec :: forall a. HasSpec a => String -> Specification a -> Spec
testSpec = forall a. HasSpec a => Bool -> String -> Specification a -> Spec
testSpec' Bool
True
testSpecNoShrink :: HasSpec a => String -> Specification a -> Spec
testSpecNoShrink :: forall a. HasSpec a => String -> Specification a -> Spec
testSpecNoShrink = forall a. HasSpec a => Bool -> String -> Specification a -> Spec
testSpec' Bool
False
testSpec' :: HasSpec a => Bool -> String -> Specification a -> Spec
testSpec' :: forall a. HasSpec a => Bool -> String -> Specification a -> Spec
testSpec' Bool
withShrink String
n Specification a
s = do
let checkCoverage' :: Property -> Property
checkCoverage' = forall prop. Testable prop => Confidence -> prop -> Property
checkCoverageWith Confidence
stdConfidence {certainty :: Integer
certainty = Integer
1_000_000}
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
n forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_sound" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
within Int
10_000_000 forall a b. (a -> b) -> a -> b
$
Property -> Property
checkCoverage' forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_sound Specification a
s
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_constrained_satisfies_sound" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
within Int
10_000_000 forall a b. (a -> b) -> a -> b
$
Property -> Property
checkCoverage' forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound Specification a
s
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_constrained_explained" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
within Int
10_000_0000 forall a b. (a -> b) -> a -> b
$
Property -> Property
checkCoverage' forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_constrained_explained Specification a
s
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
withShrink forall a b. (a -> b) -> a -> b
$
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"prop_shrink_sound" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
discardAfter Int
100_000 forall a b. (a -> b) -> a -> b
$
Property -> Property
checkCoverage' forall a b. (a -> b) -> a -> b
$
forall a. HasSpec a => Specification a -> Property
prop_shrink_sound Specification a
s
noInfinity :: Gen (NumSpec Integer)
noInfinity :: Gen (NumSpec Integer)
noInfinity = do
Integer
lo <- forall a. Arbitrary a => Gen a
arbitrary
Integer
hi <- forall a. Gen a -> (a -> Bool) -> Gen a
suchThat forall a. Arbitrary a => Gen a
arbitrary (forall a. Ord a => a -> a -> Bool
> Integer
lo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall n. Maybe n -> Maybe n -> NumSpec n
NumSpecInterval (forall a. a -> Maybe a
Just Integer
lo) (forall a. a -> Maybe a
Just Integer
hi)
plusNegate :: NumSpec Integer -> NumSpec Integer -> Property
plusNegate :: NumSpec Integer -> NumSpec Integer -> Property
plusNegate NumSpec Integer
x NumSpec Integer
y = NumSpec Integer
x forall a. Num a => a -> a -> a
- NumSpec Integer
y forall a. (Eq a, Show a) => a -> a -> Property
=== NumSpec Integer
x forall a. Num a => a -> a -> a
+ forall a. Num a => a -> a
negate NumSpec Integer
y
commutesNumSpec :: NumSpec Integer -> NumSpec Integer -> Property
commutesNumSpec :: NumSpec Integer -> NumSpec Integer -> Property
commutesNumSpec NumSpec Integer
x NumSpec Integer
y = NumSpec Integer
x forall a. Num a => a -> a -> a
+ NumSpec Integer
y forall a. (Eq a, Show a) => a -> a -> Property
=== NumSpec Integer
y forall a. Num a => a -> a -> a
+ NumSpec Integer
x
assocNumSpec :: NumSpec Integer -> NumSpec Integer -> NumSpec Integer -> Property
assocNumSpec :: NumSpec Integer -> NumSpec Integer -> NumSpec Integer -> Property
assocNumSpec NumSpec Integer
x NumSpec Integer
y NumSpec Integer
z = NumSpec Integer
x forall a. Num a => a -> a -> a
+ (NumSpec Integer
y forall a. Num a => a -> a -> a
+ NumSpec Integer
z) forall a. (Eq a, Show a) => a -> a -> Property
=== (NumSpec Integer
x forall a. Num a => a -> a -> a
+ NumSpec Integer
y) forall a. Num a => a -> a -> a
+ NumSpec Integer
z
commuteTimes :: NumSpec Integer -> NumSpec Integer -> Property
commuteTimes :: NumSpec Integer -> NumSpec Integer -> Property
commuteTimes NumSpec Integer
x NumSpec Integer
y = NumSpec Integer
x forall a. Num a => a -> a -> a
* NumSpec Integer
y forall a. (Eq a, Show a) => a -> a -> Property
=== NumSpec Integer
y forall a. Num a => a -> a -> a
* NumSpec Integer
x
assocNumSpecTimes :: Gen Property
assocNumSpecTimes :: Gen Property
assocNumSpecTimes = do
NumSpec Integer
x <- Gen (NumSpec Integer)
noInfinity
NumSpec Integer
y <- Gen (NumSpec Integer)
noInfinity
NumSpec Integer
z <- Gen (NumSpec Integer)
noInfinity
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NumSpec Integer
x forall a. Num a => a -> a -> a
* (NumSpec Integer
y forall a. Num a => a -> a -> a
* NumSpec Integer
z) forall a. (Eq a, Show a) => a -> a -> Property
=== (NumSpec Integer
x forall a. Num a => a -> a -> a
* NumSpec Integer
y) forall a. Num a => a -> a -> a
* NumSpec Integer
z)
negNegate :: NumSpec Integer -> Property
negNegate :: NumSpec Integer -> Property
negNegate NumSpec Integer
x = NumSpec Integer
x forall a. (Eq a, Show a) => a -> a -> Property
=== forall a. Num a => a -> a
negate (forall a. Num a => a -> a
negate NumSpec Integer
x)
scaleNumSpec :: NumSpec Integer -> Property
scaleNumSpec :: NumSpec Integer -> Property
scaleNumSpec NumSpec Integer
y = NumSpec Integer
y forall a. Num a => a -> a -> a
+ NumSpec Integer
y forall a. (Eq a, Show a) => a -> a -> Property
=== NumSpec Integer
2 forall a. Num a => a -> a -> a
* NumSpec Integer
y
scaleOne :: NumSpec Integer -> Property
scaleOne :: NumSpec Integer -> Property
scaleOne NumSpec Integer
y = NumSpec Integer
y forall a. (Eq a, Show a) => a -> a -> Property
=== NumSpec Integer
1 forall a. Num a => a -> a -> a
* NumSpec Integer
y
numNumSpecTree :: Spec
numNumSpecTree :: Spec
numNumSpecTree =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Num (NumSpec Integer) properties" forall a b. (a -> b) -> a -> b
$
forall a. (Int -> Int) -> SpecWith a -> SpecWith a
modifyMaxSuccess (forall a b. a -> b -> a
const Int
10000) forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"plusNegate(x - y == x + negate y)" NumSpec Integer -> NumSpec Integer -> Property
plusNegate
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"scaleNumSpec(y + y = 2 * y)" NumSpec Integer -> Property
scaleNumSpec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"scaleOne(y = 1 * y)" NumSpec Integer -> Property
scaleOne
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negNagate(x = x == negate (negate x))" NumSpec Integer -> Property
negNegate
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"commutesNumSpec(x+y = y+x)" NumSpec Integer -> NumSpec Integer -> Property
commutesNumSpec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"assocNumSpec(x+(y+z) == (x+y)+z)" NumSpec Integer -> NumSpec Integer -> NumSpec Integer -> Property
assocNumSpec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"assocNumSpecTimes(x*(y*z) == (x*y)*z)" Gen Property
assocNumSpecTimes
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"commuteTimes" NumSpec Integer -> NumSpec Integer -> Property
commuteTimes
hasSizeList :: Specification [Int]
hasSizeList :: Specification [Int]
hasSizeList = forall t.
(HasSpec t, Sized t) =>
NumSpec Integer -> Specification t
hasSize (Integer -> Integer -> NumSpec Integer
rangeSize Integer
0 Integer
4)
hasSizeSet :: Specification (Set Int)
hasSizeSet :: Specification (Set Int)
hasSizeSet = forall t.
(HasSpec t, Sized t) =>
NumSpec Integer -> Specification t
hasSize (Integer -> Integer -> NumSpec Integer
rangeSize Integer
1 Integer
3)
hasSizeMap :: Specification (Map Int Int)
hasSizeMap :: Specification (Map Int Int)
hasSizeMap = forall t.
(HasSpec t, Sized t) =>
NumSpec Integer -> Specification t
hasSize (Integer -> Integer -> NumSpec Integer
rangeSize Integer
1 Integer
3)
prop_noNarrowLoop :: Int -> Int -> Specification Int -> Specification Int -> Property
prop_noNarrowLoop :: Int -> Int -> Specification Int -> Specification Int -> Property
prop_noNarrowLoop Int
f Int
s Specification Int
eSpec Specification Int
fSpec =
Int
f forall a. Ord a => a -> a -> Bool
>= Int
0 forall prop. Testable prop => Bool -> prop -> Property
==>
forall prop. Testable prop => Int -> prop -> Property
discardAfter Int
100_000 forall a b. (a -> b) -> a -> b
$
forall a.
(TypeSpec a ~ NumSpec a, Arbitrary a, Integral a, Random a,
MaybeBounded a, Complete a) =>
a
-> Int
-> (Specification a, Specification a)
-> (Specification a, Specification a)
narrowByFuelAndSize Int
f Int
s (Specification Int
eSpec, Specification Int
fSpec) seq :: forall a b. a -> b -> b
`seq`
forall prop. Testable prop => prop -> Property
property Bool
True
conformsToSpecETest :: forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest :: forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest a
a Specification a
speca =
let resultE :: Maybe (NonEmpty String)
resultE = forall a.
HasSpec a =>
a -> Specification a -> NonEmpty String -> Maybe (NonEmpty String)
conformsToSpecE a
a Specification a
speca (forall (f :: * -> *) a. Applicative f => a -> f a
pure (String
"ConformsToSpecETest " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show a
a forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Specification a
speca))
in if forall a. HasSpec a => a -> Specification a -> Bool
conformsToSpec a
a Specification a
speca
then case Maybe (NonEmpty String)
resultE of
Maybe (NonEmpty String)
Nothing -> forall prop. Testable prop => prop -> Property
property (forall a prop. (Show a, Testable prop) => a -> prop -> Property
collect (forall a. Specification a -> String
specType Specification a
speca forall a. [a] -> [a] -> [a]
++ String
" both conform") Bool
True)
Just NonEmpty String
xs -> forall prop. Testable prop => String -> prop -> Property
counterexample ([String] -> String
unlines (forall a. NonEmpty a -> [a]
NE.toList NonEmpty String
xs)) Bool
False
else case Maybe (NonEmpty String)
resultE of
Maybe (NonEmpty String)
Nothing ->
forall prop. Testable prop => String -> prop -> Property
counterexample (String
"conformstoSpec returns False, but conformsToSpecE returns no explanations") Bool
False
Just NonEmpty String
_ -> forall prop. Testable prop => prop -> Property
property (forall a prop. (Show a, Testable prop) => a -> prop -> Property
collect (forall a. Specification a -> String
specType Specification a
speca forall a. [a] -> [a] -> [a]
++ String
" both fail to conform") Bool
True)
conformsToSpecESpec :: Spec
conformsToSpecESpec :: Spec
conformsToSpecESpec =
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Testing alignment of conformsToSpec and conformsToSpecE" forall a b. (a -> b) -> a -> b
$
forall a. (Int -> Int) -> SpecWith a -> SpecWith a
modifyMaxSuccess (forall a b. a -> b -> a
const Int
1000) forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Int" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Word64" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @Word64)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Bool" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @Bool)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"[Int]" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @[Int])
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(Int,Bool)" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @(Int, Bool))
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set Integer" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @(Set Integer))
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Set[Int]" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @(Set [Int]))
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Map Int Int" (forall a. HasSpec a => a -> Specification a -> Property
conformsToSpecETest @(Map Int Int))
foldWithSizeTests :: Spec
foldWithSizeTests :: Spec
foldWithSizeTests = do
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Summation tests with size. " forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"logish is sound" Gen Property
logishProp
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"small odd/even tests" Gen Property
pickProp
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negative small" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp (-Int
1000) Int
100 forall a. Specification a
TrueSpec (-Int
400 :: Int) Int
4 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negative sum too small" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp (-Int
1000) Int
0 forall a. Specification a
TrueSpec (-Int
8002 :: Int) Int
4 Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negative large" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp (-Int
60000 :: Int) Int
0 forall a. Specification a
TrueSpec (-Int
1000) Int
4 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(between 50 60) small enough" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
10 (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between Int
50 Int
60) (Int
200 :: Int) Int
4 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(between 50 60) too large" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
10 (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between Int
50 Int
60) (Int
400 :: Int) Int
4 Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(count 2) large is fast" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
5000000 forall a. Specification a
TrueSpec (Int
5000000 :: Int) Int
2 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(count 5) large is fast" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
5000000 forall a. Specification a
TrueSpec (Int
5000000 :: Int) Int
5 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"even succeeds on even" forall a b. (a -> b) -> a -> b
$ forall t.
(Show t, Integral t, Random t) =>
t
-> t -> (String, t -> Bool) -> t -> Int -> Outcome -> Gen Property
sumProp2 Int
1 Int
50000 (String
"even", forall a. Integral a => a -> Bool
even) (Int
45876 :: Int) Int
5 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"even succeeds on even spec" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
50000 forall n.
(TypeSpec n ~ NumSpec n, Integral n, HasSpec n, MaybeBounded n) =>
Specification n
evenSpec (Int
45876 :: Int) Int
5 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"even fails on odd total, odd count" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
50000 forall n.
(TypeSpec n ~ NumSpec n, Integral n, HasSpec n, MaybeBounded n) =>
Specification n
evenSpec (Int
45875 :: Int) Int
3 Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"odd fails on odd total, even count" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
50000 Specification Int
oddSpec (Int
45878 :: Int) Int
3 Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"odd succeeds on odd total, odd count" forall a b. (a -> b) -> a -> b
$ forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
50000 Specification Int
oddSpec (Int
45871 :: Int) Int
3 Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
xprop String
"succeeds with large count" forall a b. (a -> b) -> a -> b
$
forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
100 (forall t.
(Integral t, Random t, HasSpec t) =>
t -> t -> Specification t -> t -> Int -> Outcome -> Gen Property
sumProp Int
1 Int
1500567 forall a. Specification a
TrueSpec (Int
1500567 :: Int) Int
20 Outcome
Succeed)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"sum3 is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound Specification [Int]
sum3
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(sum3WithLength 3) is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (Integer -> Specification ([Int], Int, Int, Int)
sum3WithLength Integer
3)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(sum3WithLength 4) is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (Integer -> Specification ([Int], Int, Int, Int)
sum3WithLength Integer
4)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(sum3WithLength 7) is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (Integer -> Specification ([Int], Int, Int, Int)
sum3WithLength Integer
7)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"listSum is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (forall a. Numbery a => Specification [a]
listSum @Int)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"listSumPair is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (forall a. Numbery a => Specification [(a, Int)]
listSumPair @Word64)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"listSumComplex is sound" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (forall a. Numbery a => a -> Specification [a]
listSumComplex @Integer Integer
7)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"All sizes are negative" forall a b. (a -> b) -> a -> b
$
forall a.
(Foldy a, Random a, Integral a, TypeSpec a ~ NumSpec a,
Arbitrary a, MaybeBounded a) =>
Specification Integer
-> Specification a -> Specification a -> Outcome -> Gen Property
testFoldSpec @Int (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between (-Integer
5) (-Integer
2)) forall n.
(TypeSpec n ~ NumSpec n, Integral n, HasSpec n, MaybeBounded n) =>
Specification n
evenSpec (forall a. NonEmpty a -> Specification a
MemberSpec (forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
100)) Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Only some sizes are negative" forall a b. (a -> b) -> a -> b
$
forall a.
(Foldy a, Random a, Integral a, TypeSpec a ~ NumSpec a,
Arbitrary a, MaybeBounded a) =>
Specification Integer
-> Specification a -> Specification a -> Outcome -> Gen Property
testFoldSpec @Int (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between (-Integer
5) Integer
0) forall n.
(TypeSpec n ~ NumSpec n, Integral n, HasSpec n, MaybeBounded n) =>
Specification n
evenSpec (forall a. NonEmpty a -> Specification a
MemberSpec (forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
100)) Outcome
Fail
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"total and count can only be 0 in Word type" forall a b. (a -> b) -> a -> b
$
forall a.
(Foldy a, Random a, Integral a, TypeSpec a ~ NumSpec a,
Arbitrary a, MaybeBounded a) =>
Specification Integer
-> Specification a -> Specification a -> Outcome -> Gen Property
testFoldSpec @Word64 (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between Integer
0 Integer
0) forall n.
(TypeSpec n ~ NumSpec n, Integral n, HasSpec n, MaybeBounded n) =>
Specification n
evenSpec (forall a. NonEmpty a -> Specification a
MemberSpec (forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64
0)) Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"something of size 2, can add to 0 in type with negative values." forall a b. (a -> b) -> a -> b
$
forall a.
(Foldy a, Random a, Integral a, TypeSpec a ~ NumSpec a,
Arbitrary a, MaybeBounded a) =>
Specification Integer
-> Specification a -> Specification a -> Outcome -> Gen Property
testFoldSpec @Int (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between Integer
2 Integer
2) (forall a.
(HasSpec a, TypeSpec a ~ NumSpec a) =>
a -> a -> Specification a
between (-Int
10) Int
10) (forall a. NonEmpty a -> Specification a
MemberSpec (forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0)) Outcome
Succeed
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"TEST listSum" forall a b. (a -> b) -> a -> b
$ forall a. HasSpec a => Specification a -> Property
prop_constrained_satisfies_sound (forall a. Numbery a => Specification [a]
listSum @Int)