-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Applicative GenT to use zippping
- Loading branch information
1 parent
0c4b0b9
commit b08ff0c
Showing
7 changed files
with
132 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module Test.Hedgehog.Zip where | ||
|
||
import Control.Monad.Zip (mzip) | ||
|
||
import Data.Maybe (fromJust) | ||
import Data.Foldable (toList) | ||
|
||
import Hedgehog | ||
import qualified Hedgehog.Range as Range | ||
|
||
import qualified Hedgehog.Internal.Gen as Gen | ||
import Hedgehog.Internal.Tree (Tree) | ||
import Hedgehog.Internal.Source (HasCallStack, withFrozenCallStack) | ||
import qualified Hedgehog.Internal.Tree as Tree | ||
import qualified Hedgehog.Internal.Shrink as Shrink | ||
|
||
|
||
mkTree :: Int -> Tree Int | ||
mkTree n = | ||
Tree.expand (Shrink.towards 0) (pure n) | ||
|
||
mkGen :: Int -> Gen Int | ||
mkGen = | ||
Gen.liftTreeT . mkTree | ||
|
||
prop_gen_applicative :: Property | ||
prop_gen_applicative = | ||
property $ do | ||
let | ||
treeApplicative n m = | ||
(,) <$> mkTree n <*> mkTree m | ||
|
||
treeZip n m = | ||
mzip (mkTree n) (mkTree m) | ||
|
||
genApplicative n m = | ||
fromJust . | ||
Gen.runGen 0 (Seed 0 0) $ | ||
(,) <$> mkGen n <*> mkGen m | ||
|
||
count00 = | ||
length . | ||
filter (== (0,0)) . | ||
toList | ||
|
||
render :: HasCallStack => Tree (Int, Int) -> PropertyT IO () | ||
render x = | ||
withFrozenCallStack $ do | ||
annotate . Tree.render $ fmap show x | ||
annotate $ "---" | ||
annotate $ "count (0,0) = " ++ show (count00 x) | ||
|
||
n <- forAll $ Gen.int (Range.constant 1 5) | ||
m <- forAll $ Gen.int (Range.constant 1 5) | ||
|
||
render $ genApplicative n m | ||
render $ treeZip n m | ||
render $ treeApplicative n m | ||
|
||
genApplicative n m === treeZip n m | ||
genApplicative n m /== treeApplicative n m | ||
|
||
success | ||
|
||
tests :: IO Bool | ||
tests = | ||
checkParallel $$(discover) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters