"size" function nodes down from 454 to 321
This commit is contained in:
41
test/Spec.hs
41
test/Spec.hs
@ -35,7 +35,8 @@ tests = testGroup "Tricu Tests"
|
||||
, modules
|
||||
, demos
|
||||
, decoding
|
||||
, elimLambdaSingle
|
||||
, elimLambdaSingle
|
||||
, stressElimLambda
|
||||
]
|
||||
|
||||
lexer :: TestTree
|
||||
@ -534,7 +535,7 @@ demos = testGroup "Test provided demo functionality"
|
||||
decodeResult res @?= "\"(t (t (t t) (t t t)) (t t (t t t)))\""
|
||||
, testCase "Determining the size of functions" $ do
|
||||
res <- liftIO $ evaluateFileResult "./demos/size.tri"
|
||||
decodeResult res @?= "454"
|
||||
decodeResult res @?= "321"
|
||||
, testCase "Level Order Traversal demo" $ do
|
||||
res <- liftIO $ evaluateFileResult "./demos/levelOrderTraversal.tri"
|
||||
decodeResult res @?= "\"\n1 \n2 3 \n4 5 6 7 \n8 11 10 9 12 \""
|
||||
@ -604,3 +605,39 @@ elimLambdaSingle = testCase "elimLambda preserves eval, fires eta, and SDef bind
|
||||
evalBefore = result (evalTricu Map.empty prog)
|
||||
evalAfter = result (evalTricu Map.empty progElim)
|
||||
evalAfter @?= evalBefore
|
||||
|
||||
stressElimLambda :: TestTree
|
||||
stressElimLambda = testCase "stress elimLambda on wide list under deep curried lambda" $ do
|
||||
let numVars = 200
|
||||
numBody = 800
|
||||
vars = [ "x" ++ show i | i <- [1..numVars] ]
|
||||
body = "(" ++ unwords (replicate numBody "t") ++ ")"
|
||||
etaOne = "h : f h"
|
||||
etaTwo = "k : id k"
|
||||
defId = "id = a : a"
|
||||
lambda = unwords vars ++ " : " ++ body
|
||||
src = unlines
|
||||
[ defId
|
||||
, etaOne
|
||||
, "compose = f g x : f (g x)"
|
||||
, "f = t t"
|
||||
, etaTwo
|
||||
, lambda
|
||||
, "main = compose id id (" ++ head vars ++ " : f " ++ head vars ++ ")"
|
||||
]
|
||||
prog = parseTricu src
|
||||
|
||||
let out = map elimLambda prog
|
||||
let noLambda term = case term of
|
||||
SLambda _ _ -> False
|
||||
SApp f g -> noLambda f && noLambda g
|
||||
SList xs -> all noLambda xs
|
||||
TFork l r -> noLambda l && noLambda r
|
||||
TStem u -> noLambda u
|
||||
_ -> True
|
||||
|
||||
assertBool "all lambdas eliminated" (all noLambda out)
|
||||
|
||||
let before = result (evalTricu Map.empty prog)
|
||||
after = result (evalTricu Map.empty out)
|
||||
after @?= before
|
||||
|
Reference in New Issue
Block a user