Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Mar 24, 2023
1 parent 24bee9e commit da9a9b4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ unrollRecursion tab =
modify (\mp -> foldr (mapSymbol freshSyms) mp syms)
where
unrollLimit :: Int
unrollLimit = 100
unrollLimit = 140

mapSymbol :: HashMap (Symbol, Int) Symbol -> Symbol -> HashMap Symbol Symbol -> HashMap Symbol Symbol
mapSymbol freshSyms sym = HashMap.insert sym (fromJust $ HashMap.lookup (sym, unrollLimit) freshSyms)
Expand Down
4 changes: 3 additions & 1 deletion test/Core/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Core.Transformation.Identity qualified as Identity
import Core.Transformation.Lifting qualified as Lifting
import Core.Transformation.Pipeline qualified as Pipeline
import Core.Transformation.TopEtaExpand qualified as TopEtaExpand
import Core.Transformation.Unrolling qualified as Unrolling

allTests :: TestTree
allTests =
Expand All @@ -13,5 +14,6 @@ allTests =
[ Identity.allTests,
TopEtaExpand.allTests,
Lifting.allTests,
Pipeline.allTests
Pipeline.allTests,
Unrolling.allTests
]
49 changes: 49 additions & 0 deletions test/Core/Transformation/Unrolling.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Core.Transformation.Unrolling (allTests) where

import Base
import Core.Eval.Positive qualified as Eval
import Core.Transformation.Base
import Juvix.Compiler.Core.Data.IdentDependencyInfo
import Juvix.Compiler.Core.Transformation

allTests :: TestTree
allTests =
testGroup
"Recursion unrolling"
( map
liftTest
( -- filter out tests which require recursion deeper than 140
Eval.filterOutTests
[ "Recursion",
"Tail recursion",
"Tail recursion: Fibonacci numbers in linear time",
"Tail recursion through higher-order functions",
"Recursive functions: McCarthy's 91 function, subtraction by increments",
"Lists",
"Streams without memoization",
"Ackermann function (higher-order definition)",
"Merge sort",
"Big numbers"
]
Eval.tests
)
)

pipe :: [TransformationId]
pipe = [UnrollRecursion]

liftTest :: Eval.PosTest -> TestTree
liftTest _testEval =
fromTest
Test
{ _testTransformations = pipe,
_testAssertion = checkNoRecursion,
_testEval
}

checkNoRecursion :: InfoTable -> Assertion
checkNoRecursion tab
| isCyclic (createIdentDependencyInfo tab) =
assertFailure "recursion detected"
| otherwise =
return ()

0 comments on commit da9a9b4

Please sign in to comment.