From b3f7b8927f8ecbaf12b4eb06a009dbc083b925cb Mon Sep 17 00:00:00 2001 From: glaxxie <86179463+glaxxie@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:18:25 -0600 Subject: [PATCH 1/2] [New Exercise]: Bob --- config.json | 8 + exercises/practice/bob/.docs/instructions.md | 19 +++ exercises/practice/bob/.docs/introduction.md | 10 ++ exercises/practice/bob/.meta/config.json | 19 +++ exercises/practice/bob/.meta/example.gd | 14 ++ exercises/practice/bob/.meta/tests.toml | 85 +++++++++++ exercises/practice/bob/bob.gd | 2 + exercises/practice/bob/bob_test.gd | 149 +++++++++++++++++++ 8 files changed, 306 insertions(+) create mode 100644 exercises/practice/bob/.docs/instructions.md create mode 100644 exercises/practice/bob/.docs/introduction.md create mode 100644 exercises/practice/bob/.meta/config.json create mode 100644 exercises/practice/bob/.meta/example.gd create mode 100644 exercises/practice/bob/.meta/tests.toml create mode 100644 exercises/practice/bob/bob.gd create mode 100644 exercises/practice/bob/bob_test.gd diff --git a/config.json b/config.json index 87a05ba..cb93fac 100644 --- a/config.json +++ b/config.json @@ -163,6 +163,14 @@ "prerequisites": [], "difficulty": 2 }, + { + "slug": "bob", + "name": "Bob", + "uuid": "e635e0f6-8265-412f-b36e-e10b2079b74f", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "luhn", "name": "Luhn", diff --git a/exercises/practice/bob/.docs/instructions.md b/exercises/practice/bob/.docs/instructions.md new file mode 100644 index 0000000..bb702f7 --- /dev/null +++ b/exercises/practice/bob/.docs/instructions.md @@ -0,0 +1,19 @@ +# Instructions + +Your task is to determine what Bob will reply to someone when they say something to him or ask him a question. + +Bob only ever answers one of five things: + +- **"Sure."** + This is his response if you ask him a question, such as "How are you?" + The convention used for questions is that it ends with a question mark. +- **"Whoa, chill out!"** + This is his answer if you YELL AT HIM. + The convention used for yelling is ALL CAPITAL LETTERS. +- **"Calm down, I know what I'm doing!"** + This is what he says if you yell a question at him. +- **"Fine. Be that way!"** + This is how he responds to silence. + The convention used for silence is nothing, or various combinations of whitespace characters. +- **"Whatever."** + This is what he answers to anything else. diff --git a/exercises/practice/bob/.docs/introduction.md b/exercises/practice/bob/.docs/introduction.md new file mode 100644 index 0000000..ea4a807 --- /dev/null +++ b/exercises/practice/bob/.docs/introduction.md @@ -0,0 +1,10 @@ +# Introduction + +Bob is a [lackadaisical][] teenager. +He likes to think that he's very cool. +And he definitely doesn't get excited about things. +That wouldn't be cool. + +When people talk to him, his responses are pretty limited. + +[lackadaisical]: https://www.collinsdictionary.com/dictionary/english/lackadaisical diff --git a/exercises/practice/bob/.meta/config.json b/exercises/practice/bob/.meta/config.json new file mode 100644 index 0000000..7a35552 --- /dev/null +++ b/exercises/practice/bob/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "glaxxie" + ], + "files": { + "solution": [ + "bob.gd" + ], + "test": [ + "bob_test.gd" + ], + "example": [ + ".meta/example.gd" + ] + }, + "blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.", + "source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.", + "source_url": "https://pine.fm/LearnToProgram/?Chapter=06" +} diff --git a/exercises/practice/bob/.meta/example.gd b/exercises/practice/bob/.meta/example.gd new file mode 100644 index 0000000..abb50c8 --- /dev/null +++ b/exercises/practice/bob/.meta/example.gd @@ -0,0 +1,14 @@ +func response(greeting): + var trimmed = greeting.strip_edges() + var test_chars = RegEx.new() + test_chars.compile("\\p{L}") + + var is_silence = trimmed.is_empty() + var is_yelling = test_chars.search(trimmed) + var is_question = trimmed.ends_with("?") + + if is_yelling && is_question: return "Calm down, I know what I'm doing!" + if is_question: return "Sure." + if is_yelling: return "Whoa, chill out!" + if is_silence: return "Fine. Be that way!" + return "Whatever." diff --git a/exercises/practice/bob/.meta/tests.toml b/exercises/practice/bob/.meta/tests.toml new file mode 100644 index 0000000..ea47d6b --- /dev/null +++ b/exercises/practice/bob/.meta/tests.toml @@ -0,0 +1,85 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[e162fead-606f-437a-a166-d051915cea8e] +description = "stating something" + +[73a966dc-8017-47d6-bb32-cf07d1a5fcd9] +description = "shouting" + +[d6c98afd-df35-4806-b55e-2c457c3ab748] +description = "shouting gibberish" + +[8a2e771d-d6f1-4e3f-b6c6-b41495556e37] +description = "asking a question" + +[81080c62-4e4d-4066-b30a-48d8d76920d9] +description = "asking a numeric question" + +[2a02716d-685b-4e2e-a804-2adaf281c01e] +description = "asking gibberish" + +[c02f9179-ab16-4aa7-a8dc-940145c385f7] +description = "talking forcefully" + +[153c0e25-9bb5-4ec5-966e-598463658bcd] +description = "using acronyms in regular speech" + +[a5193c61-4a92-4f68-93e2-f554eb385ec6] +description = "forceful question" + +[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc] +description = "shouting numbers" + +[f7bc4b92-bdff-421e-a238-ae97f230ccac] +description = "no letters" + +[bb0011c5-cd52-4a5b-8bfb-a87b6283b0e2] +description = "question with no letters" + +[496143c8-1c31-4c01-8a08-88427af85c66] +description = "shouting with special characters" + +[e6793c1c-43bd-4b8d-bc11-499aea73925f] +description = "shouting with no exclamation mark" + +[aa8097cc-c548-4951-8856-14a404dd236a] +description = "statement containing question mark" + +[9bfc677d-ea3a-45f2-be44-35bc8fa3753e] +description = "non-letters with question" + +[8608c508-f7de-4b17-985b-811878b3cf45] +description = "prattling on" + +[bc39f7c6-f543-41be-9a43-fd1c2f753fc0] +description = "silence" + +[d6c47565-372b-4b09-b1dd-c40552b8378b] +description = "prolonged silence" + +[4428f28d-4100-4d85-a902-e5a78cb0ecd3] +description = "alternate silence" + +[66953780-165b-4e7e-8ce3-4bcb80b6385a] +description = "multiple line question" + +[5371ef75-d9ea-4103-bcfa-2da973ddec1b] +description = "starting with whitespace" + +[05b304d6-f83b-46e7-81e0-4cd3ca647900] +description = "ending with whitespace" + +[72bd5ad3-9b2f-4931-a988-dce1f5771de2] +description = "other whitespace" + +[12983553-8601-46a8-92fa-fcaa3bc4a2a0] +description = "non-question ending with whitespace" diff --git a/exercises/practice/bob/bob.gd b/exercises/practice/bob/bob.gd new file mode 100644 index 0000000..d109dc1 --- /dev/null +++ b/exercises/practice/bob/bob.gd @@ -0,0 +1,2 @@ +func response(greeting): + pass diff --git a/exercises/practice/bob/bob_test.gd b/exercises/practice/bob/bob_test.gd new file mode 100644 index 0000000..da50d99 --- /dev/null +++ b/exercises/practice/bob/bob_test.gd @@ -0,0 +1,149 @@ +func test_stating_something(solution_script): + var value = "Tom-ay-to, tom-aaaah-to." + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_shouting(solution_script): + var value = "WATCH OUT!" + var expected = "Whoa, chill out!" + return [solution_script.response(value), expected] + + +func test_shouting_gibberish(solution_script): + var value = "FCECDFCAAB" + var expected = "Whoa, chill out!" + return [solution_script.response(value), expected] + + +func test_asking_a_question(solution_script): + var value = "Does this cryogenic chamber make me look fat?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_asking_a_numeric_question(solution_script): + var value = "You are, what, like 15?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_asking_gibberish(solution_script): + var value = "fffbbcbeab?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_talking_forcefully(solution_script): + var value = "Hi there!" + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_using_acronyms_in_regular_speech(solution_script): + var value = "It's OK if you don't want to go work for NASA." + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_forceful_question(solution_script): + var value = "WHAT'S GOING ON?" + var expected = "Calm down, I know what I'm doing!" + return [solution_script.response(value), expected] + + +func test_shouting_numbers(solution_script): + var value = "1, 2, 3 GO!" + var expected = "Whoa, chill out!" + return [solution_script.response(value), expected] + + +func test_no_letters(solution_script): + var value = "1, 2, 3" + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_question_with_no_letters(solution_script): + var value = "4?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_shouting_with_special_characters(solution_script): + var value = "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" + var expected = "Whoa, chill out!" + return [solution_script.response(value), expected] + + +func test_shouting_with_no_exclamation_mark(solution_script): + var value = "I HATE THE DENTIST" + var expected = "Whoa, chill out!" + return [solution_script.response(value), expected] + + +func test_statement_containing_question_mark(solution_script): + var value = "Ending with ? means a question." + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_non_letters_with_question(solution_script): + var value = ":) ?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_prattling_on(solution_script): + var value = "Wait! Hang on. Are you going to be OK?" + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_silence(solution_script): + var value = "" + var expected = "Fine. Be that way!" + return [solution_script.response(value), expected] + + +func test_prolonged_silence(solution_script): + var value = " " + var expected = "Fine. Be that way!" + return [solution_script.response(value), expected] + + +func test_alternate_silence(solution_script): + var value = "\t\t\t\t\t\t\t\t\t\t" + var expected = "Fine. Be that way!" + return [solution_script.response(value), expected] + + +func test_multiple_line_question(solution_script): + var value = "\nDoes this cryogenic chamber make me look fat?\nNo." + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_starting_with_whitespace(solution_script): + var value = " hmmmmmmm..." + var expected = "Whatever." + return [solution_script.response(value), expected] + + +func test_ending_with_whitespace(solution_script): + var value = "Okay if like my spacebar quite a bit? " + var expected = "Sure." + return [solution_script.response(value), expected] + + +func test_other_whitespace(solution_script): + var value = "\n\r \t" + var expected = "Fine. Be that way!" + return [solution_script.response(value), expected] + + +func test_non_question_ending_with_whitespace(solution_script): + var value = "This is a statement ending with whitespace " + var expected = "Whatever." + return [solution_script.response(value), expected] + From 9987f722fd62a72b7456bf90e4395ac6d9ab14c0 Mon Sep 17 00:00:00 2001 From: glaxxie <86179463+glaxxie@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:38:09 -0600 Subject: [PATCH 2/2] Update example.gd fix example --- exercises/practice/bob/.meta/example.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/bob/.meta/example.gd b/exercises/practice/bob/.meta/example.gd index abb50c8..0b30b30 100644 --- a/exercises/practice/bob/.meta/example.gd +++ b/exercises/practice/bob/.meta/example.gd @@ -4,7 +4,7 @@ func response(greeting): test_chars.compile("\\p{L}") var is_silence = trimmed.is_empty() - var is_yelling = test_chars.search(trimmed) + var is_yelling = test_chars.search(trimmed) && (trimmed.to_upper() == trimmed) var is_question = trimmed.ends_with("?") if is_yelling && is_question: return "Calm down, I know what I'm doing!"