From 03bc93a07740cff754f5d147ce0cf31b8640716c Mon Sep 17 00:00:00 2001 From: Abdulshaheed Alqunber Date: Wed, 5 Sep 2018 16:24:29 -0400 Subject: [PATCH 1/2] removed an extra word --- assignments/week1/lab1/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assignments/week1/lab1/README.md b/assignments/week1/lab1/README.md index 2434597..9250ff5 100644 --- a/assignments/week1/lab1/README.md +++ b/assignments/week1/lab1/README.md @@ -19,10 +19,10 @@ If you are a mac user and you are may need to follow the instructions under [mac * ```cd``` into the newly created directory by typing ```cd week1-username``` with ```username``` replaced with your user name * You always want to take advantage of the latest corrections to the assignments and shared tests so we will add the main repository as a source * In your terminal type ```git remote add upstream https://github.com/BU-CS320/Fall-2018.git``` - * check that it worked by typing ```git remote -v```. You should see see the line ```upstream https://github.com/BU-CS320/Fall-2018.git (fetch)``` + * check that it worked by typing ```git remote -v```. You should see the line ```upstream https://github.com/BU-CS320/Fall-2018.git (fetch)``` * You always want to keep your assignment up to date by running ```git pull upstream master```, do that now * ```cd``` into this assignment (```cd assignments/week1/lab1```), first we will write a greeting - * run ```cabal new-repl``` in the terminal (it is important that you do this in the ```lab1``` directory). You should see + * run ```cabal new-repl``` in the terminal (it is important that you do this in the ```lab1``` directory). You should see ``` Preprocessing library for lab1-0.1.0.0.. GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help @@ -37,7 +37,7 @@ Ok, one module loaded. * Haskell is a functional language so define the identity function by changing ```ident x = undefined``` to ```ident x = x``` * reset the terminal by typing ```:reload``` * Haskell doesn't let us see the definition of functions, but we can test by running ```ident greeting``` and see if we get back the greeting we expect - * type ```:q``` to quit the REPL in the + * type ```:q``` to quit the REPL in the * run the tests by running ```cabal test```, some students need to run ```cabal configure --enable-tests``` first * make a commit by typing ```git commit -a -m "my first commit"``` into the console * submit your work by typing ```git push``` @@ -57,7 +57,7 @@ Complete the survey by adding your answers to [survey.md](survey.md). You may d If you are having ```git``` issues run ```git status``` and call on Mark for help. ## Optional Bonus: Sharing Tests, and correcting my spelling -We will allow you to share tests with the class. To do this +We will allow you to share tests with the class. To do this * Make a fork of the class repo: https://github.com/BU-CS320/Fall-2018 * clone your fork locally (keep it separate from your assignment clone) * go to the test directory (in this case Fall-2018/assignments/week1/lab1/tests) From 49609b74bdc47251950df63e2c3a277ebe6c2e21 Mon Sep 17 00:00:00 2001 From: Abdulshaheed Alqunber Date: Tue, 27 Nov 2018 19:34:21 -0500 Subject: [PATCH 2/2] fixed cons tests and added few extra tests --- assignments/week10/hw/tests/LangParserTest.hs | 165 ++++++++++-------- 1 file changed, 92 insertions(+), 73 deletions(-) diff --git a/assignments/week10/hw/tests/LangParserTest.hs b/assignments/week10/hw/tests/LangParserTest.hs index e7c11b4..3620ddd 100644 --- a/assignments/week10/hw/tests/LangParserTest.hs +++ b/assignments/week10/hw/tests/LangParserTest.hs @@ -1,75 +1,94 @@ module LangParserTest where -import Test.Tasty (testGroup) -import Test.Tasty.HUnit (assertEqual, assertBool, testCase) -import Test.Tasty.QuickCheck - - -import ParserMonad - -import Lang -import LangParser - - - - ---TODO: move the generator to a shared place - -instance Arbitrary Ast where - arbitrary = sized arbitrarySizedAst --- TODO: implement shrink for better error messages --- see http://hackage.haskell.org/package/QuickCheck-2.12.6.1/docs/Test-QuickCheck-Arbitrary.html#v:shrink - -arbitrarySizedAst :: Int -> Gen Ast -arbitrarySizedAst m | m < 1 = do i <- arbitrary - b <- arbitrary - node <- elements [ValInt i, ValBool b, Nil] - return $ node -arbitrarySizedAst m | otherwise = do l <- arbitrarySizedAst (m `div` 2) - r <- arbitrarySizedAst (m `div` 2) - str <- elements ["x","y","z"] - ifast <- arbitrarySizedIf m - node <- elements [And l r, Or l r, Not l, - Plus l r, Minus l r, Mult l r, Div l r, - Cons l r, - ifast, - Let str l r, - Lam str l, - App l r, - Var str - ] - return node - --- it would be better if every branch were built like this so the balance would be maintained -arbitrarySizedIf :: Int -> Gen Ast -arbitrarySizedIf m = do b <- arbitrarySizedAst (m `div` 3) - t <- arbitrarySizedAst (m `div` 3) - e <- arbitrarySizedAst (m `div` 3) - return $ If b t e - -unitTests = - testGroup - "LangParserTest" - [instructorTests, - -- TODO: your tests here!!! - somemoreTests] - -instructorTests = testGroup - "instructorTests" - [ - testProperty "parse should return the same AST when fully parenthisized" $ ((\ x -> Just (x , "") == (parse parser $ fullyParenthesized x)) :: Ast -> Bool), - testProperty "parse should return the same AST when pretty printed" $ ((\ x -> Just (x , "") == (parse parser $ prettyShow x 0)) :: Ast -> Bool) - ] - - --- TODO: your tests here!!! --- TODO: Many, many more example test cases (every simple thing, many normal things, some extreme things) - -somemoreTests = testGroup - "somemoreTests" - [ - testCase "bool precedence test" $ assertEqual [] (Just((And (Not (ValBool False)) (ValBool True)), "")) $ (parse parser "! false && true"), - testCase "parens and bool precedence test" $ assertEqual [] (Just((Not (And (ValBool False) (ValBool True))), "")) $ (parse parser "! (false && true)"), - testCase "cons right associativity test" $ assertEqual [] (Just (Cons (ValInt 1) (Cons (ValInt 4) (Cons (Plus (ValInt 3) (ValInt 5)) Nil)),"")) $ (parse parser "1 : 4 : 3 + 5"), - testCase "cons different types test" $ assertEqual [] (Just (Cons (ValInt 1) (Cons (ValInt 4) (Cons (ValBool True) Nil)),"")) $ (parse parser "1 : 4 : true") - ] + import Test.Tasty (testGroup) + import Test.Tasty.HUnit (assertEqual, assertBool, testCase) + import Test.Tasty.QuickCheck + + + import ParserMonad + + import Lang + import LangParser + + + + + --TODO: move the generator to a shared place + + instance Arbitrary Ast where + arbitrary = sized arbitrarySizedAst + + arbitrarySizedAst :: Int -> Gen Ast + arbitrarySizedAst m | m < 1 = do i <- arbitrary + b <- arbitrary + node <- elements [ValInt i, ValBool b, Nil] + return $ node + arbitrarySizedAst m | otherwise = do l <- arbitrarySizedAst (m `div` 2) + r <- arbitrarySizedAst (m `div` 2) + str <- elements ["x","y","z"] + ifast <- arbitrarySizedIf m + node <- elements [And l r, Or l r, Not l, + Plus l r, Minus l r, Mult l r, Div l r, + Cons l r, + ifast, + Let str l r, + Lam str l, + App l r, + Var str + ] + return node + + -- it would be better if every branch were built like this so the balance would be maintained + arbitrarySizedIf :: Int -> Gen Ast + arbitrarySizedIf m = do b <- arbitrarySizedAst (m `div` 3) + t <- arbitrarySizedAst (m `div` 3) + e <- arbitrarySizedAst (m `div` 3) + return $ If b t e + + unitTests = + testGroup + "LangParserTest" + [instructorTests + ,somemoreTests + ,myTests + -- TODO: your tests here!!! + ] + + instructorTests = testGroup + "instructorTests" + [ + testProperty "parse should return the same AST when fully parenthisized" $ ((\ x -> Just (x , "") == (parse parser $ fullyParenthesized x)) :: Ast -> Bool), + testProperty "parse should return the same AST when pretty printed" $ ((\ x -> Just (x , "") == (parse parser $ prettyShow x 0)) :: Ast -> Bool) + ] + + somemoreTests = testGroup + "somemoreTests" + [ + testCase "bool precedence test" $ assertEqual [] (Just((And (Not (ValBool False)) (ValBool True)), "")) $ (parse parser "! false && true"), + testCase "parens and bool precedence test" $ assertEqual [] (Just((Not (And (ValBool False) (ValBool True))), "")) $ (parse parser "! (false && true)"), + testCase "cons right associativity test" $ assertEqual [] (Just (Cons (ValInt 1) (Cons (ValInt 4) (Cons (Plus (ValInt 3) (ValInt 5)) Nil)),"")) $ (parse parser "1 : 4 : 3 + 5 : []"), + testCase "cons different types test" $ assertEqual [] (Just (Cons (ValInt 1) (Cons (ValInt 4) (Cons (ValBool True) Nil)),"")) $ (parse parser "1 : 4 : true : []") + ] + + string1 = "let x = 10 in if (\\x -> \\y -> x && y) true false then 0 else let y = 4 in x + y" + ast1 = Let "x" (ValInt 10) (If (App (App (Lam "x" (Lam "y" (And (Var "x") (Var "y")))) (ValBool True)) (ValBool False)) (ValInt 0) (Let "y" (ValInt 4) (Plus (Var "x") (Var "y")))) + string2 = "!false && 3 + 5*4" + ast2 = And (Not (ValBool False)) (Plus (ValInt 3) (Mult (ValInt 5) (ValInt 4))) + string3 = "let z = \\y -> \\x -> y && ! x in if let x = false in x then 10 : 15:[] else z true false" + ast3 = Let "z" (Lam "y" (Lam "x" (And (Var "y") (Not (Var "x"))))) (If (Let "x" (ValBool False) (Var "x")) (Cons (ValInt 10) (Cons (ValInt 15) Nil)) (App (App (Var "z") (ValBool True)) (ValBool False))) + string4 = "10 : true&&false : 1 * 3 : []" + ast4 = Cons (ValInt 10) (Cons (And (ValBool True) (ValBool False)) (Cons (Mult (ValInt 1) (ValInt 3)) Nil)) + string5 = "( (( []) ) )" + ast5 = Nil + + + checkStrings = map (\(str, ast) -> testProperty str $ Just (ast, "") == parse parser str) + + myTests = testGroup + "myTests" + (checkStrings [(string1, ast1), (string2, ast2), (string3, ast3), (string4, ast4), (string5, ast5)]) + + + -- TODO: your tests here!!! + -- TODO: Many, many more example test cases (every simple thing, many normal things, some extreme things) + \ No newline at end of file