Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# Fall-2018

[website](http://www.cs.bu.edu/fac/snyder/cs320/) [piazza](https://piazza.com/class/jlpaiu7tfht5ro?cid=15)

The notes and assignments for 320

## Forking and Adding tests
We will allow you to share tests with the class. These instructions are a work in progress, please add to them.
### Small changes
1. Click the pencil in the upper right corner
1. edit the file
1. press "Create a new branch for this commit and start a pull request"
1. click the make pull request button
1. wait for aproval, you will see your request under "Pull requests"
1. Someone will merge you commit or comment about why it can't be merged
1. if there are problems with you commit you will need to follow some of the instructions bellow to fix it

### Large changes
* 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/week2/lab2/tests)
* add a test
* push the test up to your fork
* https://help.github.com/articles/creating-a-pull-request/
* If your test looks good we will accept it

Once you have followed the steps for forking a repository all you need to do now is clone the forked repository into your terminal. Then follow these steps:
1. Need to add the ability to update your forked repository to keep it up to date with the master branch
1. '''cd'' into your forked repo
1. type '''git remote add upstream https://github.com/BU-CS320/Fall-2018.git'''
1. type '''git fetch upstream''' then '''git pull upstream''' to update your forked repository with the master branch
1. Now just make your edits, whether it be fixing typos, adding test cases, etc.
1. Once you have made your changes, all you need to is push your changes to your forked repo to save your work.
1. Pushing your work to the masterbranch
1. Once you push your changes, go onto github and click the tab pull requests.
1. Once in this tab, hit the button that says __New pull request__
1. Once you get to this page, you will see this at the top ![](ing/gitpullrequest.JPG). This will compare your forked repository with the master branch.
1. Then click __Create a new pull__
1. Add any comment you want
1. Then click __Create a new pull__ at the bottom of the page ![](ing/push-and-pull.gif)
1. After this you should have successfully put in the pull request, and now just wait for the person with the access to the master branch to accept the request.
# Fall-2018
[website](http://www.cs.bu.edu/fac/snyder/cs320/) [piazza](https://piazza.com/class/jlpaiu7tfht5ro?cid=15)
The notes and assignments for 320
## Forking and Adding tests
We will allow you to share tests with the class. These instructions are a work in progress, please add to them.
### Small changes
1. Click the pencil in the upper right corner
1. edit the file
1. press "Create a new branch for this commit and start a pull request"
1. click the make pull request button
1. wait for aproval, you will see your request under "Pull requests"
1. Someone will merge you commit or comment about why it can't be merged
1. if there are problems with you commit you will need to follow some of the instructions bellow to fix it
### Large changes
* 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/week2/lab2/tests)
* add a test
* push the test up to your fork
* https://help.github.com/articles/creating-a-pull-request/
* If your test looks good we will accept it
Once you have followed the steps for forking a repository all you need to do now is clone the forked repository into your terminal. Then follow these steps:
1. Need to add the ability to update your forked repository to keep it up to date with the master branch
1. '''cd'' into your forked repo
1. type '''git remote add upstream https://github.com/BU-CS320/Fall-2018.git'''
1. type '''git fetch upstream''' then '''git pull upstream''' to update your forked repository with the master branch
1. Now just make your edits, whether it be fixing typos, adding test cases, etc.
1. Once you have made your changes, all you need to is push your changes to your forked repo to save your work.
1. Pushing your work to the masterbranch
1. Once you push your changes, go onto github and click the tab pull requests.
1. Once in this tab, hit the button that says __New pull request__
1. Once you get to this page, you will see this at the top ![](ing/gitpullrequest.JPG). This will compare your forked repository with the master branch.
1. Then click __Create a new pull__
1. Add any comment you want
1. Then click __Create a new pull__ at the bottom of the page ![](ing/push-and-pull.gif)
1. After this you should have successfully put in the pull request, and now just wait for the person with the access to the master branch to accept the request.
10 changes: 7 additions & 3 deletions assignments/week1/lab1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ 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
<<<<<<< HEAD
* 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 (or cabal repl if gets "Failed to load interface")``` in the terminal (it is important that you do this in the ```lab1``` directory). You should see
>>>>>>> 2971d6e0044f83cf5c055ea1d6ad2f05fcf6fcf0
```
Preprocessing library for lab1-0.1.0.0..
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Expand All @@ -37,7 +41,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```
Expand All @@ -57,7 +61,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)
Expand Down
165 changes: 92 additions & 73 deletions assignments/week10/hw/tests/LangParserTest.hs
Original file line number Diff line number Diff line change
@@ -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)

Loading