Skip to content

bob 1.1.0.4: Add yelling question rule #632

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

Merged
merged 1 commit into from
Dec 17, 2017
Merged
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
2 changes: 2 additions & 0 deletions exercises/bob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question.

He answers 'Whoa, chill out!' if you yell at him.

He answers 'Calm down, I know what I'm doing!' if you yell a question at him.

He says 'Fine. Be that way!' if you address him without actually saying
anything.

Expand Down
10 changes: 7 additions & 3 deletions exercises/bob/examples/success-standard/src/Bob.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module Bob (responseFor) where
import Data.Char (isSpace, isUpper, isAlpha)

data Prompt = Silence | Yell | Question | Other
data Prompt = Silence | YellQuestion | Yell | Question | Other

classify :: String -> Prompt
classify s | all isSpace s = Silence
| any isAlpha s && all isUpper (filter isAlpha s) = Yell
| '?' == last (filter (not . isSpace) s) = Question
| yell && question = YellQuestion
| yell = Yell
| question = Question
| otherwise = Other
where yell = any isAlpha s && all isUpper (filter isAlpha s)
question = '?' == last (filter (not . isSpace) s)

response :: Prompt -> String
response Silence = "Fine. Be that way!"
response YellQuestion = "Calm down, I know what I'm doing!"
response Yell = "Whoa, chill out!"
response Question = "Sure."
response Other = "Whatever."
Expand Down
2 changes: 1 addition & 1 deletion exercises/bob/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bob
version: 1.0.0.3
version: 1.1.0.4

dependencies:
- base
Expand Down
2 changes: 1 addition & 1 deletion exercises/bob/test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cases = [ Case { description = "stating something"
}
, Case { description = "forceful question"
, input = "WHAT THE HELL WERE YOU THINKING?"
, expected = "Whoa, chill out!"
, expected = "Calm down, I know what I'm doing!"
}
, Case { description = "shouting numbers"
, input = "1, 2, 3 GO!"
Expand Down