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
makeEnvWith :: Set.Set String -> Gen Env | |
makeEnvWith deps = do | |
let n = Set.size deps | |
values <- replicateM n arbitrary | |
return $ Map.fromList (zip (Set.toList deps) values) | |
genTotalEnv :: Gen Env | |
genTotalEnv = makeEnvWith (Set.fromList 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
prop_optimize_eval :: Expr -> Property | |
prop_optimize_eval e = | |
forAll genTotalEnv $ \env -> | |
eval env e == eval env (optimize e) | |
quickCheck prop_optimize_eval | |
> +++ OK, passed 100 tests. |
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
prop_optimize_constant :: Property | |
prop_optimize_constant = | |
forAll (sized genCstExpr) (isCst . optimize) | |
prop_partial_constant :: Property | |
prop_partial_constant = | |
forAll (sized genCstExpr) (isCst . partial Map.empty) |
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
prop_dependencies_allow_eval :: Property | |
prop_dependencies_allow_eval = | |
forAll (sized genExpr) $ \e -> | |
forAll (makeEnvWith (dependencies e)) $ \env -> | |
isCst (partial env e) |
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
quickCheck prop_missing_dependencies_forbid_eval | |
> *** Failed! Falsifiable (after 4 tests): | |
> (* g x) | |
> fromList [("x",0)] | |
quickCheck prop_missing_dependencies_forbid_eval | |
> *** Failed! Falsifiable (after 4 tests): | |
> (* 0 b q) | |
> fromList [("b",2)] |
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
makePartialEnv :: Set.Set Id -> Gen Env | |
makePartialEnv deps = do | |
v <- elements (Set.toList deps) | |
makeEnvWith (Set.delete v deps) | |
prop_missing_dependencies_forbid_eval :: Property | |
prop_missing_dependencies_forbid_eval = | |
forAll (sized genExpr) $ \e -> | |
let deps = dependencies e | |
in Set.size deps > 0 ==> |
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
prop_optimize_preserves_dependencies :: Property | |
prop_optimize_preserves_dependencies = | |
forAll (sized genExpr) $ \e -> | |
dependencies e == dependencies (optimize e) | |
quickCheck (expectFailure prop_optimize_preserves_dependencies) | |
> +++ OK, failed as expected. Falsifiable (after 8 tests): | |
> (* g r e m (* 0)) |
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
toClojureFunction :: String -> Expr -> String | |
toClojureFunction name e = | |
unwords | |
["(defn", name, | |
"[" ++ unwords (Set.toList $ dependencies e) ++ "]", | |
prn e, ")"] |
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
genName :: Gen String | |
genName = do | |
n <- elements [5..10] | |
replicateM n (elements ['a'..'z']) |
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
clojureFunctionGen :: Int -> Gen String | |
clojureFunctionGen size = | |
toClojureFunction | |
<$> genName | |
<*> fmap optimize (genExpr size) | |
generate (clojureFunctionGen 30) | |
> "(defn ptvkegely [c j m n t u y] (+ -64 m c t y n j u) )" |