diff --git a/exercises/bob/.meta/description.md b/exercises/bob/.meta/description.md deleted file mode 100644 index 1072139f..00000000 --- a/exercises/bob/.meta/description.md +++ /dev/null @@ -1,10 +0,0 @@ -Bob is a lackadaisical teenager. In conversation, his responses are very limited. - -Bob answers 'Sure.' if you ask him a question. - -He answers 'Whoa, chill out!' if you yell at him. - -He says 'Fine. Be that way!' if you address him without actually saying -anything. - -He answers 'Whatever.' to anything else. diff --git a/exercises/bob/README.md b/exercises/bob/README.md index 3072e506..3c5af578 100644 --- a/exercises/bob/README.md +++ b/exercises/bob/README.md @@ -1,15 +1,19 @@ # Bob -Bob is a lackadaisical teenager. In conversation, his responses are very limited. - -Bob answers 'Sure.' if you ask him a question. - -He answers 'Whoa, chill out!' if you yell at him. - -He says 'Fine. Be that way!' if you address him without actually saying -anything. - -He answers 'Whatever.' to anything else. +Bob is a lackadaisical teenager. In conversation, his responses are very limited. + +Bob answers 'Sure.' if you ask him a question, such as "How are you?". + +He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals). + +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. + +He answers 'Whatever.' to anything else. + +Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English. ## Getting Started diff --git a/exercises/bob/bob_test.cpp b/exercises/bob/bob_test.cpp index 9924fe81..acde7567 100644 --- a/exercises/bob/bob_test.cpp +++ b/exercises/bob/bob_test.cpp @@ -1,6 +1,8 @@ #include "bob.h" #include "test/catch.hpp" +// Bob exercise test case data version 1.4.0 + TEST_CASE("stating_something") { REQUIRE("Whatever." == bob::hey("Tom-ay-to, tom-aaaah-to.")); @@ -12,11 +14,26 @@ TEST_CASE("shouting") REQUIRE("Whoa, chill out!" == bob::hey("WATCH OUT!")); } +TEST_CASE("shouting_gibberish") +{ + REQUIRE("Whoa, chill out!" == bob::hey("FCECDFCAAB")); +} + TEST_CASE("asking_a_question") { REQUIRE("Sure." == bob::hey("Does this cryogenic chamber make me look fat?")); } +TEST_CASE("asking_a_numeric_question") +{ + REQUIRE("Sure." == bob::hey("You are, what, like 15?")); +} + +TEST_CASE("asking_gibberish") +{ + REQUIRE("Sure." == bob::hey("fffbbcbeab?")); +} + TEST_CASE("talking_forcefully") { REQUIRE("Whatever." == bob::hey("Let's go make out behind the gym!")); @@ -29,7 +46,7 @@ TEST_CASE("using_acronyms_in_regular_speech") TEST_CASE("forceful_questions") { - REQUIRE("Whoa, chill out!" == bob::hey("WHAT THE HELL WERE YOU THINKING?")); + REQUIRE("Calm down, I know what I'm doing!" == bob::hey("WHAT THE HELL WERE YOU THINKING?")); } TEST_CASE("shouting_numbers") @@ -37,12 +54,12 @@ TEST_CASE("shouting_numbers") REQUIRE("Whoa, chill out!" == bob::hey("1, 2, 3 GO!")); } -TEST_CASE("only_numbers") +TEST_CASE("no_letters") { REQUIRE("Whatever." == bob::hey("1, 2, 3")); } -TEST_CASE("question_with_only_numbers") +TEST_CASE("question_with_no_letters") { REQUIRE("Sure." == bob::hey("4?")); } @@ -54,22 +71,22 @@ TEST_CASE("shouting_with_special_characters") TEST_CASE("shouting_with_no_exclamation_mark") { - REQUIRE("Whoa, chill out!" == bob::hey("I HATE YOU")); + REQUIRE("Whoa, chill out!" == bob::hey("I HATE THE DMV")); } TEST_CASE("statement_containing_question_mark") { - REQUIRE("Whatever." == bob::hey("Ending with a ? means a question.")); + REQUIRE("Whatever." == bob::hey("Ending with ? means a question.")); } -TEST_CASE("prattling_on") +TEST_CASE("non_letters_with_question") { - REQUIRE("Sure." == bob::hey("Wait! Hang on. Are you going to be OK?")); + REQUIRE("Sure." == bob::hey(":) ?")); } -TEST_CASE("question_with_trailing_whitespace") +TEST_CASE("prattling_on") { - REQUIRE("Sure." == bob::hey("Are you ok? ")); + REQUIRE("Sure." == bob::hey("Wait! Hang on. Are you going to be OK?")); } TEST_CASE("silence") @@ -79,11 +96,36 @@ TEST_CASE("silence") TEST_CASE("prolonged_silence") { - REQUIRE("Fine. Be that way!" == bob::hey(" ")); + REQUIRE("Fine. Be that way!" == bob::hey(" ")); +} + +TEST_CASE("alternate_silence") +{ + REQUIRE("Fine. Be that way!" == bob::hey("\t\t\t\t\t\t\t\t\t\t")); +} + +TEST_CASE("multiple_line_question") +{ + REQUIRE("Whatever." == bob::hey("\nDoes this cryogenic chamber make me look fat?\nNo.")); +} + +TEST_CASE("starting_with_whitespace") +{ + REQUIRE("Whatever." == bob::hey(" hmmmmmmm...")); +} + +TEST_CASE("ending_with_whitespace") +{ + REQUIRE("Sure." == bob::hey("Okay if like my spacebar quite a bit? ")); +} + +TEST_CASE("other_whitespace") +{ + REQUIRE("Fine. Be that way!" == bob::hey("\n\r \t")); } -TEST_CASE("not_all_silence") +TEST_CASE("non_question_ending_with_whitespace") { - REQUIRE("Whatever." == bob::hey(" A bit of silence can be nice. ")); + REQUIRE("Whatever." == bob::hey("This is a statement ending with whitespace ")); } #endif diff --git a/exercises/bob/example.cpp b/exercises/bob/example.cpp index 793f3e71..563f8178 100644 --- a/exercises/bob/example.cpp +++ b/exercises/bob/example.cpp @@ -14,10 +14,10 @@ string trim_copy(string const& s) { string cpy(s); // Trim front - while (!cpy.empty() && cpy.front() == ' ') + while (!cpy.empty() && std::isspace(static_cast(cpy.front()))) cpy.erase(cpy.begin()); // Trim back - while (!cpy.empty() && cpy.back() == ' ') + while (!cpy.empty() && std::isspace(static_cast(cpy.back()))) cpy.pop_back(); return cpy; } @@ -52,7 +52,7 @@ bool is_silence(string const& text) return trim_copy(text).length() == 0; } -} +} // anonymous namespace string hey(string const& text) { @@ -60,6 +60,8 @@ string hey(string const& text) return "Fine. Be that way!"; } if (is_shouting(text)) { + if (is_question(text)) + return "Calm down, I know what I'm doing!"; return "Whoa, chill out!"; } if (is_question(text)) { @@ -68,4 +70,4 @@ string hey(string const& text) return "Whatever."; } -} +} // namespace bob