import Examples (Bert (Add, Bert, Num), Ernie (Ernie, Multiply),
collapseBertSyntaxTree, collapseErnieSyntaxTree,
collapseErnieSyntaxTree')
import Test.Hspec (describe, hspec, it, parallel, shouldBe)
bertSum :: Bert
bertSum = Add (Num 2) (Num 3)
ernieMult :: Ernie
ernieMult = Multiply (Ernie bertSum) (Ernie (Num 3))
bertNothing :: Bert
bertNothing = Bert ernieMult
ernieComplex :: Ernie
ernieComplex = Ernie bertNothing
bertComplex :: Bert
bertComplex = Add (Num 3) (Bert ernieMult)
resultErnie :: Ernie
resultErnie = Ernie (Num 15)
main :: IO ()
main = hspec $
describe "dendro" $ parallel $ do
it "collapses a simple syntax tree" $
collapseBertSyntaxTree bertSum `shouldBe` Num 5
it "collapses both parts of a syntax tree" $
collapseErnieSyntaxTree ernieMult `shouldBe` resultErnie
it "matches solution via catamorphism" $
collapseErnieSyntaxTree' ernieMult `shouldBe` collapseErnieSyntaxTree ernieMult
it "collapses complex syntax trees" $
collapseBertSyntaxTree bertComplex `shouldBe` Num 18
it "should work would when triply wrapped (1/4)" $
collapseErnieSyntaxTree (Ernie (Bert (Ernie (Num 15)))) `shouldBe` resultErnie
it "should work would when doubly wrapped" $
collapseBertSyntaxTree (Bert (Ernie (Num 15))) `shouldBe` (Num 15)
it "should work would when triply wrapped (2/4)" $
collapseBertSyntaxTree (Bert (Ernie bertComplex)) `shouldBe` (Num 18)
it "should work would when triply wrapped (3/4)" $
collapseBertSyntaxTree (Bert ernieComplex) `shouldBe` (Num 15)
it "should work would when triply wrapped (4/4)" $
collapseErnieSyntaxTree (Ernie (Bert ernieComplex)) `shouldBe` resultErnie