summary refs log tree commit diff stats
path: root/raku/bob
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
committerAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
commit321825828ac918bad28d0597a8616c6dc9802c3c (patch)
tree0b8e9cb1012197750eb58e972736319b2a6abac2 /raku/bob
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'raku/bob')
-rw-r--r--raku/bob/Bob.rakumod15
-rw-r--r--raku/bob/README.md39
-rw-r--r--raku/bob/bob.rakutest226
3 files changed, 280 insertions, 0 deletions
diff --git a/raku/bob/Bob.rakumod b/raku/bob/Bob.rakumod
new file mode 100644
index 0000000..ab6fa66
--- /dev/null
+++ b/raku/bob/Bob.rakumod
@@ -0,0 +1,15 @@
+unit class Bob;
+
+method hey (Str $msg is copy) {
+    $msg .= trim;
+
+    given $msg.trim {
+        when .chars == 0 { "Fine. Be that way!" }
+        when $_ eq .uc && $_ ~~ /<[a..zA..Z]>/ {
+            return "Calm down, I know what I'm doing!" if $_.ends-with("?");
+            "Whoa, chill out!";
+        }
+        when .ends-with("?") { "Sure." }
+        default { "Whatever." }
+    }
+}
diff --git a/raku/bob/README.md b/raku/bob/README.md
new file mode 100644
index 0000000..01800c5
--- /dev/null
+++ b/raku/bob/README.md
@@ -0,0 +1,39 @@
+# Bob
+
+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.
+
+## Resources
+
+Remember to check out the Raku [documentation](https://docs.raku.org/) and
+[resources](https://raku.org/resources/) pages for information, tips, and
+examples if you get stuck.
+
+## Running the tests
+
+There is a test suite and module included with the exercise.
+The test suite (a file with the extension `.rakutest`) will attempt to run routines
+from the module (a file with the extension `.rakumod`).
+Add/modify routines in the module so that the tests will pass! You can view the
+test data by executing the command `raku --doc *.rakutest` (\* being the name of the
+test suite), and run the test suite for the exercise by executing the command
+`prove6 .` in the exercise directory.
+
+## Source
+
+Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/raku/bob/bob.rakutest b/raku/bob/bob.rakutest
new file mode 100644
index 0000000..a540719
--- /dev/null
+++ b/raku/bob/bob.rakutest
@@ -0,0 +1,226 @@
+#!/usr/bin/env raku
+use Test;
+use JSON::Fast;
+use lib $?FILE.IO.dirname; #`[Look for the module inside the same directory as this test file.]
+use Bob;
+plan 26; #`[This is how many tests we expect to run.]
+
+#`[Check that the class 'Bob' can use all of the methods
+needed in the tests (only 'hey' for this one).]
+subtest 'Class methods', {
+  for <hey> -> $method {
+    can-ok Bob, $method;
+  }
+} or bail-out 'Cannot run expected method(s).';
+
+my @test-cases = from-json($=pod.pop.contents).List;
+# Go through the cases and check that Bob gives us the correct responses.
+for @test-cases -> %case {
+  is Bob.hey(%case<input><heyBob>), |%case<expected description>;
+}
+
+=head2 Test Cases
+=begin code
+[
+  {
+    "description": "stating something",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "Tom-ay-to, tom-aaaah-to."
+    },
+    "property": "response"
+  },
+  {
+    "description": "shouting",
+    "expected": "Whoa, chill out!",
+    "input": {
+      "heyBob": "WATCH OUT!"
+    },
+    "property": "response"
+  },
+  {
+    "description": "shouting gibberish",
+    "expected": "Whoa, chill out!",
+    "input": {
+      "heyBob": "FCECDFCAAB"
+    },
+    "property": "response"
+  },
+  {
+    "description": "asking a question",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "Does this cryogenic chamber make me look fat?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "asking a numeric question",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "You are, what, like 15?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "asking gibberish",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "fffbbcbeab?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "talking forcefully",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "Hi there!"
+    },
+    "property": "response"
+  },
+  {
+    "description": "using acronyms in regular speech",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "It's OK if you don't want to go work for NASA."
+    },
+    "property": "response"
+  },
+  {
+    "description": "forceful question",
+    "expected": "Calm down, I know what I'm doing!",
+    "input": {
+      "heyBob": "WHAT'S GOING ON?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "shouting numbers",
+    "expected": "Whoa, chill out!",
+    "input": {
+      "heyBob": "1, 2, 3 GO!"
+    },
+    "property": "response"
+  },
+  {
+    "description": "no letters",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "1, 2, 3"
+    },
+    "property": "response"
+  },
+  {
+    "description": "question with no letters",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "4?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "shouting with special characters",
+    "expected": "Whoa, chill out!",
+    "input": {
+      "heyBob": "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
+    },
+    "property": "response"
+  },
+  {
+    "description": "shouting with no exclamation mark",
+    "expected": "Whoa, chill out!",
+    "input": {
+      "heyBob": "I HATE THE DENTIST"
+    },
+    "property": "response"
+  },
+  {
+    "description": "statement containing question mark",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "Ending with ? means a question."
+    },
+    "property": "response"
+  },
+  {
+    "description": "non-letters with question",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": ":) ?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "prattling on",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "Wait! Hang on. Are you going to be OK?"
+    },
+    "property": "response"
+  },
+  {
+    "description": "silence",
+    "expected": "Fine. Be that way!",
+    "input": {
+      "heyBob": ""
+    },
+    "property": "response"
+  },
+  {
+    "description": "prolonged silence",
+    "expected": "Fine. Be that way!",
+    "input": {
+      "heyBob": "          "
+    },
+    "property": "response"
+  },
+  {
+    "description": "alternate silence",
+    "expected": "Fine. Be that way!",
+    "input": {
+      "heyBob": "\t\t\t\t\t\t\t\t\t\t"
+    },
+    "property": "response"
+  },
+  {
+    "description": "multiple line question",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "\nDoes this cryogenic chamber make me look fat?\nNo."
+    },
+    "property": "response"
+  },
+  {
+    "description": "starting with whitespace",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "         hmmmmmmm..."
+    },
+    "property": "response"
+  },
+  {
+    "description": "ending with whitespace",
+    "expected": "Sure.",
+    "input": {
+      "heyBob": "Okay if like my  spacebar  quite a bit?   "
+    },
+    "property": "response"
+  },
+  {
+    "description": "other whitespace",
+    "expected": "Fine. Be that way!",
+    "input": {
+      "heyBob": "\n\r \t"
+    },
+    "property": "response"
+  },
+  {
+    "description": "non-question ending with whitespace",
+    "expected": "Whatever.",
+    "input": {
+      "heyBob": "This is a statement ending with whitespace      "
+    },
+    "property": "response"
+  }
+]
+=end code