summary refs log tree commit diff stats
path: root/raku/pangram
diff options
context:
space:
mode:
Diffstat (limited to 'raku/pangram')
-rw-r--r--raku/pangram/Pangram.rakumod5
-rw-r--r--raku/pangram/README.md32
-rw-r--r--raku/pangram/pangram.rakutest101
3 files changed, 138 insertions, 0 deletions
diff --git a/raku/pangram/Pangram.rakumod b/raku/pangram/Pangram.rakumod
new file mode 100644
index 0000000..30618c8
--- /dev/null
+++ b/raku/pangram/Pangram.rakumod
@@ -0,0 +1,5 @@
+unit module Pangram;
+
+sub is-pangram (Str $string) is export {
+    $string.lc.comb ⊇ ('a'..'z');
+}
diff --git a/raku/pangram/README.md b/raku/pangram/README.md
new file mode 100644
index 0000000..09c35b7
--- /dev/null
+++ b/raku/pangram/README.md
@@ -0,0 +1,32 @@
+# Pangram
+
+Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma,
+"every letter") is a sentence using every letter of the alphabet at least once.
+The best known English pangram is:
+> The quick brown fox jumps over the lazy dog.
+
+The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
+insensitive. Input will not contain non-ASCII symbols.
+
+## 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
+
+Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)
+
+## 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/pangram/pangram.rakutest b/raku/pangram/pangram.rakutest
new file mode 100644
index 0000000..29725bd
--- /dev/null
+++ b/raku/pangram/pangram.rakutest
@@ -0,0 +1,101 @@
+#!/usr/bin/env raku
+use Test;
+use JSON::Fast;
+use lib $?FILE.IO.dirname;
+use Pangram;
+plan 10;
+
+my @test-cases = from-json($=pod.pop.contents).List;
+for @test-cases -> %case {
+  subtest %case<description>, {
+    plan 2;
+    isa-ok ( my $result := is-pangram %case<input><sentence> ), Bool;
+    is-deeply $result, %case<expected>, 'Result matches expected';
+  }
+}
+
+=head2 Test Cases
+=begin code
+[
+  {
+    "description": "empty sentence",
+    "expected": false,
+    "input": {
+      "sentence": ""
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "perfect lower case",
+    "expected": true,
+    "input": {
+      "sentence": "abcdefghijklmnopqrstuvwxyz"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "only lower case",
+    "expected": true,
+    "input": {
+      "sentence": "the quick brown fox jumps over the lazy dog"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "missing the letter 'x'",
+    "expected": false,
+    "input": {
+      "sentence": "a quick movement of the enemy will jeopardize five gunboats"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "missing the letter 'h'",
+    "expected": false,
+    "input": {
+      "sentence": "five boxing wizards jump quickly at it"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "with underscores",
+    "expected": true,
+    "input": {
+      "sentence": "the_quick_brown_fox_jumps_over_the_lazy_dog"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "with numbers",
+    "expected": true,
+    "input": {
+      "sentence": "the 1 quick brown fox jumps over the 2 lazy dogs"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "missing letters replaced by numbers",
+    "expected": false,
+    "input": {
+      "sentence": "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "mixed case and punctuation",
+    "expected": true,
+    "input": {
+      "sentence": "\"Five quacking Zephyrs jolt my wax bed.\""
+    },
+    "property": "isPangram"
+  },
+  {
+    "description": "case insensitive",
+    "expected": false,
+    "input": {
+      "sentence": "the quick brown fox jumps over with lazy FX"
+    },
+    "property": "isPangram"
+  }
+]
+=end code