Skip to content

Commit

Permalink
fix bug which caused bad foldMap/fold to pass if they evaluated thing…
Browse files Browse the repository at this point in the history
…s in a weird order
  • Loading branch information
chessai committed Mar 24, 2019
1 parent 562cc94 commit 05329b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Hedgehog/Classes/Common/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Hedgehog.Classes.Common.Gen
( genSmallList
, genVerySmallList
, genSmallNonEmptyList
, genShowReadPrecedence
, genSmallString
Expand Down Expand Up @@ -37,6 +38,9 @@ genSmallNonEmptyList gen = Gen.list (Range.linear 1 7) gen
genSmallList :: Gen a -> Gen [a]
genSmallList gen = Gen.list (Range.linear 0 6) gen

genVerySmallList :: Gen a -> Gen [a]
genVerySmallList gen = Gen.list (Range.linear 0 2) gen

genSmallString :: Gen String
genSmallString = Gen.string (Range.linear 0 6) Gen.ascii

Expand Down
6 changes: 3 additions & 3 deletions src/Hedgehog/Classes/Foldable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ foldableFold ::
, forall x. Eq x => Eq (f x), forall x. Show x => Show (f x)
) => (forall x. Gen x -> Gen (f x)) -> Property
foldableFold fgen = property $ do
a <- forAll $ fgen genSmallSum
a <- forAll $ fgen $ genVerySmallList genSmallInteger
let lhs = Foldable.fold a
let rhs = Foldable.foldMap id a
let ctx = contextualise $ LawContext
Expand All @@ -76,7 +76,7 @@ foldableFoldMap ::
foldableFoldMap fgen = property $ do
a <- forAll $ fgen genSmallInteger
e <- forAll genQuadraticEquation
let f = Sum . runQuadraticEquation e
let f = (:[]) . runQuadraticEquation e
let lhs = Foldable.foldMap f a
let rhs = Foldable.foldr (mappend . f) mempty a
let ctx = contextualise $ LawContext
Expand All @@ -85,7 +85,7 @@ foldableFoldMap fgen = property $ do
, lawContextTcName = "Foldable"
, lawContextTcProp =
let showA = show a
showF = "Sum $ " ++ show e
showF = "(:[]) $ " ++ show e
in lawWhere
[ "foldMap f a" `congruency` "foldr (mappend . f) mempty a, where"
, "f = " ++ showF
Expand Down

0 comments on commit 05329b5

Please sign in to comment.