From d004e3d47f73ad119fc2cd86b2707a216ef40a96 Mon Sep 17 00:00:00 2001
From: ik1g19 <ik1g19@soton.ac.uk>
Date: Wed, 13 Jan 2021 23:19:33 +0000
Subject: [PATCH] starting writing tests for 5 and 6

---
 cw/test/Spec.hs | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/cw/test/Spec.hs b/cw/test/Spec.hs
index 0c6674d..e0dc388 100644
--- a/cw/test/Spec.hs
+++ b/cw/test/Spec.hs
@@ -51,6 +51,18 @@ ex4'6Ans = Nothing
 ex4'7Ans = Just (LamDef [ ( "F",LamAbs 1 (LamApp (LamVar 1) (LamVar 1)) ), ( "G",LamAbs 2 (LamVar 2) ) ] (LamApp (LamMacro "F") (LamMacro "G")))
 
 
+exId =  (LamAbs 1 (LamVar 1))
+ex5'1 = LamDef [] (LamApp (LamVar 1) (LamVar 2))
+ex5'2 = (LamDef [ ("F", exId) ] (LamVar 2) )
+ex5'3 = (LamDef [ ("F", exId) ] (LamMacro "F") )
+ex5'4 = (LamDef [ ("F", exId) ] (LamApp (LamMacro "F") (LamMacro "F"))
+
+ex5'1Ans = LJust (LamDef [] (LamAbs 3 (LamApp (LamAbs 6 (LamApp (LamVar 6) (LamVar 1))) (LamAbs 4 (LamApp (LamAbs 7 (LamApp (LamVar 7) (LamVar 2))) (LamAbs 5 (LamApp (LamApp (LamVar 4) (LamVar 5)) (LamVar 3))))))))
+ex5'2Ans = (LamDef [ ("F", exId) ] (LamVar 2) )
+ex5'3Ans = (LamDef [ ("F", exId) ] (LamMacro "F") )
+ex5'4Ans = (LamDef [ ("F", exId) ] (LamApp (LamMacro "F") (LamMacro "F")))
+
+
 ------------------------------Printing Functions--------------------------------
 
 
@@ -214,4 +226,32 @@ challenge4Test = do putStrLn "========================================="
                     assert4 ex4'7 ex4'7Ans (parseLamMacro ex4'7)
                     putStrLn "========================================="
                     putStrLn "Challenge 4 End Test"
+                    putStrLn "=========================================\n"
+
+
+-----------------------------Challenge 5 Testing--------------------------------
+
+
+assert5 :: LamMacroExpr -> LamMacroExpr -> LamMacroExpr -> IO ()
+assert5 macro expected result = do putStrLn "CPS Translating:"
+                                   putStrLn $ prettyPrint macro ++ "\n"
+                                   putStrLn "(Actual Internal Value):"
+                                   putStrLn $ show macro ++ "\n"
+                                   putStrLn "Expected Result:"
+                                   putStrLn $ show expected ++ "\n"
+                                   if expected == result then
+                                     putStrLn "Passed! Result:"
+                                   else
+                                     putStrLn "Failed! Result:"
+                                   putStrLn $ show result
+
+challenge5Test :: IO ()
+challenge5Test = do putStrLn "========================================="
+                    putStrLn "Challenge 5 Start Test"
+                    putStrLn "========================================="
+                    assert5 ex5'1 ex5'1Ans (parseLamMacro ex4'1)
+                    putStrLn "\n- - - - - - - - - - - - - - - - - -\n"
+                    
+                    putStrLn "========================================="
+                    putStrLn "Challenge 5 End Test"
                     putStrLn "=========================================\n"
\ No newline at end of file
-- 
GitLab