From 1606fd3bda448693ea2a5789b215127bab5379e1 Mon Sep 17 00:00:00 2001 From: Matthaus Owens Date: Sat, 5 May 2018 12:21:15 -0700 Subject: [PATCH] Issue #214: Update bob for ambiguous case This commit updates the bob exercise to take into account the shouting question case, which involves updating the readme, test, and example solution. --- exercises/bob/README.md | 2 ++ exercises/bob/src/example.clj | 4 ++++ exercises/bob/test/bob_test.clj | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises/bob/README.md b/exercises/bob/README.md index 54cc1d41b..1755559ad 100644 --- a/exercises/bob/README.md +++ b/exercises/bob/README.md @@ -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. diff --git a/exercises/bob/src/example.clj b/exercises/bob/src/example.clj index 7dffb9543..fd4d2d4fb 100644 --- a/exercises/bob/src/example.clj +++ b/exercises/bob/src/example.clj @@ -10,8 +10,12 @@ (defn- shouting? [msg] (and (= msg (str/upper-case msg)) (has-letter? msg))) +(defn- forceful-question? [msg] + (and (shouting? msg) (question? msg))) + (defn response-for [input] (cond + (forceful-question? input) "Calm down, I know what I'm doing!" (silence? input) "Fine. Be that way!" (shouting? input) "Whoa, chill out!" (question? input) "Sure." diff --git a/exercises/bob/test/bob_test.clj b/exercises/bob/test/bob_test.clj index 317b68e3b..2e774ebbf 100644 --- a/exercises/bob/test/bob_test.clj +++ b/exercises/bob/test/bob_test.clj @@ -20,7 +20,7 @@ (bob/response-for "It's OK if you don't want to go to the DMV.")))) (deftest responds-to-forceful-questions - (is (= "Whoa, chill out!" + (is (= "Calm down, I know what I'm doing!" (bob/response-for "WHAT THE HELL WERE YOU THINKING?")))) (deftest responds-to-shouting-with-special-characters