Skip to content

Commit cf88060

Browse files
authored
bob 1.1.0.4: Add yelling question rule (#632)
Closes exercism/problem-specifications#943. It was possible for a message directed to Bob to be both a question and yelling, which meant it was unclear which rule should take effect. Resolve ambiguity by simply adding a rule for that case. exercism/problem-specifications#1025
1 parent 465cf57 commit cf88060

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

exercises/bob/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question.
66

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

9+
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
10+
911
He says 'Fine. Be that way!' if you address him without actually saying
1012
anything.
1113

exercises/bob/examples/success-standard/src/Bob.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
module Bob (responseFor) where
22
import Data.Char (isSpace, isUpper, isAlpha)
33

4-
data Prompt = Silence | Yell | Question | Other
4+
data Prompt = Silence | YellQuestion | Yell | Question | Other
55

66
classify :: String -> Prompt
77
classify s | all isSpace s = Silence
8-
| any isAlpha s && all isUpper (filter isAlpha s) = Yell
9-
| '?' == last (filter (not . isSpace) s) = Question
8+
| yell && question = YellQuestion
9+
| yell = Yell
10+
| question = Question
1011
| otherwise = Other
12+
where yell = any isAlpha s && all isUpper (filter isAlpha s)
13+
question = '?' == last (filter (not . isSpace) s)
1114

1215
response :: Prompt -> String
1316
response Silence = "Fine. Be that way!"
17+
response YellQuestion = "Calm down, I know what I'm doing!"
1418
response Yell = "Whoa, chill out!"
1519
response Question = "Sure."
1620
response Other = "Whatever."

exercises/bob/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: bob
2-
version: 1.0.0.3
2+
version: 1.1.0.4
33

44
dependencies:
55
- base

exercises/bob/test/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cases = [ Case { description = "stating something"
5454
}
5555
, Case { description = "forceful question"
5656
, input = "WHAT THE HELL WERE YOU THINKING?"
57-
, expected = "Whoa, chill out!"
57+
, expected = "Calm down, I know what I'm doing!"
5858
}
5959
, Case { description = "shouting numbers"
6060
, input = "1, 2, 3 GO!"

0 commit comments

Comments
 (0)