This file contains hidden or 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
joinTree :: Tree (Tree Result) -> Tree Result | |
joinTree (Tree (Tree innerArgResult innerArgShrinks) outerArgShrinks) = | |
Tree innerArgResult | |
(map joinTree outerArgShrinks ++ innerArgShrinks) |
This file contains hidden or 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
buildTree :: Shrink a -> a -> Tree a | |
buildTree shrinker = build where | |
build x = Tree x (map build (shrinker x)) | |
addCounterExample :: (Show a) => a -> Tree Result -> Tree Result | |
addCounterExample arg = fmap (\r -> overFailure r addToFailure) | |
where addToFailure f = f { counterExample = show arg : counterExample f } |
This file contains hidden or 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
925396436 234647012 | |
925436450 1835767207 | |
0 1835767207 | |
462718225 1835767207 | |
0 1835767207 | |
231359113 1835767207 | |
... | |
4 1835767207 | |
0 1835767207 | |
2 1835767207 |
This file contains hidden or 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
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
module RapidCheck where | |
import Data.List | |
import Data.Monoid((<>)) | |
import System.Random | |
import Text.Show.Functions |
This file contains hidden or 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
let e = add [ cst(1) | |
, cst(2) | |
, mul [cst(0), var("x"), var("y")] | |
, mul [cst(1), var("y"), cst(2)] | |
, add [cst(0), var("x") ] | |
] | |
-- Pretty printing an expression | |
prn e | |
> "(+ 1 2 (* 0 x y) (* 1 y 2) (+ 0 x))" |
This file contains hidden or 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
genCst :: Gen Expr | |
genCst = fmap cst arbitrary | |
varNames :: [String] | |
varNames = [[v] | v <- ['a'..'z']] | |
genVar :: Gen Expr | |
genVar = fmap var (elements varNames) |
This file contains hidden or 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
genSimpleTerm :: Gen Expr | |
genSimpleTerm = oneof [genVar, genCst] |
This file contains hidden or 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
opsGen :: Gen Expr -> Int -> Gen Expr | |
opsGen simpleTermGen = go where | |
go n = do | |
m <- choose (0, n) | |
if m == 0 | |
then simpleTermGen | |
else elements [add, mul] <*> replicateM m (go (div n (m + 1))) |
This file contains hidden or 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
genExpr :: Int -> Gen Expr | |
genExpr = opsGen genSimpleTerm | |
genCstExpr :: Int -> Gen Expr | |
genCstExpr = opsGen genCst |
This file contains hidden or 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
type Id = String -- Variable identifier | |
type Env = -- Environment of evaluation | |
Map Id Int | |
data OpType -- Types of operations | |
= Add -- * Addition | |
| Mul -- * Multiplication | |
deriving (Show, Eq, Ord) | |
data ExprR r -- Open recursive expression type |