-
Notifications
You must be signed in to change notification settings - Fork 9
Tests for CIS 194 homework assignments (1 to 6) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghost
wants to merge
1
commit into
stackbuilders:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,19 @@ | ||
| *.swp | ||
| dist | ||
| dist-* | ||
| cabal-dev | ||
| *.o | ||
| *.hi | ||
| *.chi | ||
| *.chs.h | ||
| *.dyn_o | ||
| *.dyn_hi | ||
| .hpc | ||
| .hsenv | ||
| .cabal-sandbox/ | ||
| cabal.sandbox.config | ||
| *.prof | ||
| *.aux | ||
| *.hp | ||
| *.eventlog | ||
| .stack-work/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| resolver: lts-5.6 | ||
| resolver: lts-7.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,65 @@ | ||
| module Main | ||
| ( main | ||
| ) | ||
| where | ||
|
|
||
| -- doctest | ||
| import qualified Test.DocTest as DocTest | ||
| ( main ) | ||
| where | ||
|
|
||
| import Basis | ||
| import Test.Hspec | ||
|
|
||
| main :: IO () | ||
| main = | ||
| DocTest.doctest | ||
| [ "-isrc" | ||
| , "src/Basis.hs" | ||
| ] | ||
| main = hspec $ do | ||
|
|
||
| describe "toDigits" $ do | ||
| context "when the number is greater than 0" $ | ||
| it "returns a list of digits" $ | ||
| toDigits 1234 `shouldBe` [1, 2, 3, 4] | ||
|
|
||
| context "when the number is 0" $ | ||
| it "returns an empty list" $ | ||
| toDigits 0 `shouldBe` [] | ||
|
|
||
| context "when the number is less than 0" $ | ||
| it "returns an empty list" $ | ||
| toDigits (-17) `shouldBe` [] | ||
|
|
||
| describe "toDigitsRev" $ do | ||
| context "when the number is greater than 0" $ | ||
| it "returns a list of digits reversed" $ | ||
| toDigitsRev 9876 `shouldBe` [6, 7, 8, 9] | ||
|
|
||
| context "when the number is 0" $ | ||
| it "returns an empty list" $ | ||
| toDigitsRev 0 `shouldBe` [] | ||
|
|
||
| context "when the number is less than 0" $ | ||
| it "returns an empty list" $ | ||
| toDigitsRev (-1) `shouldBe` [] | ||
|
|
||
| describe "doubleEveryOther" $ do | ||
| context "when the list has an even number of elements" $ | ||
| it "doubles every other number beginning from the right" $ | ||
| doubleEveryOther [8, 7, 6, 5] `shouldBe` [16, 7, 12, 5] | ||
|
|
||
| context "when the list has an odd number of elements" $ | ||
| it "doubles every other number beginning from the right" $ | ||
| doubleEveryOther [1, 2, 3] `shouldBe` [1, 4, 3] | ||
|
|
||
| describe "sumDigits" $ | ||
| it "calculates the sum of sums of the digits of each element in a list" $ | ||
| sumDigits [16, 7, 12, 5] `shouldBe` 22 | ||
|
|
||
| describe "validate" $ do | ||
| context "when the credit card number is valid" $ | ||
| it "returns True" $ | ||
| validate 4012888888881881 `shouldBe` True | ||
|
|
||
| context "when the credit card number is invalid" $ | ||
| it "returns False" $ | ||
| validate 4012888888881882 `shouldBe` False | ||
|
|
||
| describe "hanoi" $ | ||
| context "when the stack discs moves from first peg to second" $ do | ||
| it "gets a list of moves whit 2 discs" $ | ||
| hanoi 2 "a" "b" "c" `shouldBe` [("a", "c"), ("a", "b"), ("c", "b")] | ||
|
|
||
| it "gets a list of moves whit 3 discs" $ | ||
| hanoi 3 "a" "b" "c" `shouldBe` [("a","b"),("a","c"),("b","c"),("a","b"),("c","a"),("c","b"),("a","b")] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| resolver: lts-5.6 | ||
| resolver: lts-7.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,45 @@ | ||
| module Main | ||
| ( main | ||
| ) | ||
| where | ||
|
|
||
| -- doctest | ||
| import qualified Test.DocTest as DocTest | ||
| ( main ) | ||
| where | ||
|
|
||
| import Log | ||
| import LogAnalysis | ||
| import Test.Hspec | ||
|
|
||
| main :: IO () | ||
| main = | ||
| DocTest.doctest | ||
| [ "-isrc" | ||
| , "src/LogAnalysis.hs" | ||
| ] | ||
| main = hspec $ do | ||
|
|
||
| describe "parseMessage" $ do | ||
| it "parses an error message" $ | ||
| parseMessage "E 2 562 help help" `shouldBe` LogMessage (Error 2) 562 "help help" | ||
|
|
||
| it "parses an info message" $ | ||
| parseMessage "I 29 la la la" `shouldBe` LogMessage Info 29 "la la la" | ||
|
|
||
| it "parses an Unknown message" $ | ||
| parseMessage "This is not in the right format" `shouldBe` Unknown "This is not in the right format" | ||
|
|
||
| describe "insert" $ | ||
| it "returns a tree with LogMessage inserted" $ do | ||
| let tree = Node Leaf (LogMessage (Error 2) 562 "help help") Leaf | ||
| insert (LogMessage Info 29 "la") tree | ||
| `shouldBe` Node (Node Leaf (LogMessage Info 29 "la") Leaf) (LogMessage (Error 2) 562 "help help") Leaf | ||
|
|
||
| describe "build" $ | ||
| it "builds up a MessageTree containing the messages in a list" $ do | ||
| let messageTreeSet = [LogMessage (Error 2) 562 "help help", LogMessage Info 29 "la"] | ||
| build messageTreeSet | ||
| `shouldBe` Node (Node Leaf (LogMessage Info 29 "la") Leaf) (LogMessage (Error 2) 562 "help help") Leaf | ||
|
|
||
| describe "inOrder" $ | ||
| it "produces a list of all LogMessages it contains, sorted by timestamp from smallest to biggest" $ do | ||
| let messageTreeSet = [LogMessage (Error 2) 562 "help help",LogMessage Info 29 "la"] | ||
| inOrder (build messageTreeSet) | ||
| `shouldBe` [LogMessage Info 29 "la",LogMessage (Error 2) 562 "help help"] | ||
|
|
||
| describe "whatWentWrong" $ | ||
| context "with a severity of 50 or greater" $ | ||
| it "returns a list of the messages corresponding to any errors sorted by timestamp" $ do | ||
| parseTest <- testWhatWentWrong parse whatWentWrong "src/sample.log" | ||
| parseTest | ||
| `shouldBe` ["Way too many pickles","Bad pickle-flange interaction detected","Flange failed!"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| resolver: lts-5.6 | ||
| resolver: lts-7.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,41 @@ | ||
| module Main | ||
| ( main | ||
| ) | ||
| where | ||
|
|
||
| -- doctest | ||
| import qualified Test.DocTest as DocTest | ||
| ( main ) | ||
| where | ||
|
|
||
| import Golf | ||
| import Test.Hspec | ||
|
|
||
| main :: IO () | ||
| main = | ||
| DocTest.doctest | ||
| [ "-isrc" | ||
| , "src/Golf.hs" | ||
| ] | ||
| main = hspec $ do | ||
|
|
||
| describe "skips" $ do | ||
| it "skips list of Chars (length 4)" $ | ||
| skips "ABCD" `shouldBe` ["ABCD", "BD", "C", "D"] | ||
|
|
||
| it "skips list of Chars (length 6)" $ | ||
| skips "hello!" `shouldBe` ["hello!", "el!", "l!", "l", "o", "!"] | ||
|
|
||
| it "skips list of one element" $ | ||
| skips [1] `shouldBe` [[1]] | ||
|
|
||
| it "skips list of Booleans" $ | ||
| skips [True,False] `shouldBe` [[True,False], [False]] | ||
|
|
||
| it "skips empty list" $ | ||
| skips ([] :: [String]) `shouldBe` ([] :: [[String]]) | ||
|
|
||
| describe "localMaxima" $ do | ||
| context "when at least one element of list is greater than both elements immediately before and after it" $ do | ||
| it "returns two local maximums" $ | ||
| localMaxima [2,9,5,6,1] `shouldBe` [9,6] | ||
|
|
||
| it "returns one local maximum" $ | ||
| localMaxima [2,3,4,1,5] `shouldBe` [4] | ||
|
|
||
| context "when no element of list is greater than both elements immediately before and after it" $ | ||
| it "returns zero local maximum" $ | ||
| localMaxima [1,2,3,4,5] `shouldBe` [] | ||
|
|
||
| describe "histogram" $ | ||
| it "outputs a vertical histogram" $ | ||
| histogram [1,1,1,5] `shouldBe` " * \n * \n * * \n==========\n0123456789\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| resolver: lts-5.10 | ||
| resolver: lts-7.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,45 @@ | ||
| module Main | ||
| ( main | ||
| ) | ||
| where | ||
|
|
||
| -- doctest | ||
| import qualified Test.DocTest as DocTest | ||
| ( main ) | ||
| where | ||
|
|
||
| import Wholemeal | ||
| import Test.Hspec | ||
|
|
||
| main :: IO () | ||
| main = | ||
| DocTest.doctest | ||
| [ "-isrc" | ||
| , "src/Wholemeal.hs" | ||
| ] | ||
| main = hspec $ do | ||
|
|
||
| describe "fun1'" $ | ||
| it "returns same output of fun1" $ | ||
| fun1' [1,3,5,7] `shouldBe` fun1 [1,3,5,7] | ||
|
|
||
| describe "fun2'" $ | ||
| it "returns same output of fun2" $ | ||
| fun2' 10 `shouldBe` fun2 10 | ||
|
|
||
| describe "foldTree" $ | ||
| -- Because you can have many implementations of foldTree, you will only test the height of the tree | ||
| it "returns heigh of a balanced binary tree" $ do | ||
| let height (Node x _ _ _) = x | ||
| height (foldTree "ABCDEFGHIJ") `shouldBe` 3 | ||
|
|
||
| describe "xor" $ do | ||
| context "when list has an odd number of True values" $ | ||
| it "returns True" $ | ||
| xor [False, True, False] `shouldBe` True | ||
|
|
||
| context "when list has an even number of True values" $ | ||
| it "returns False" $ | ||
| xor [False, True, False, False, True] `shouldBe` False | ||
|
|
||
| describe "map'" $ do | ||
| context "when list is not empty" $ | ||
| it "returns same output of standard map function" $ | ||
| map' (+1) [1,2,3] `shouldBe` map (+1) [1,2,3] | ||
|
|
||
| context "when list is empty" $ | ||
| it "returns same output of standard map function" $ | ||
| map' (*2) [] `shouldBe` map (*2) [] | ||
|
|
||
| describe "sieveSundaram" $ | ||
| it "returns a list of prime numbers less than 2*n + 2" $ | ||
| sieveSundaram 20 `shouldBe` [3,5,7,11,13,17,19,23,29,31,37,41] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| resolver: lts-5.10 | ||
| resolver: lts-7.14 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's important, but what about the case for numbers starting with
0like01234There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of
toDigitsfunction istoDigits :: Integer -> [Integer]. Haskell don't use leading zeros, sotoDigits 01234 == toDigits 1234.