summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-11 18:51:23 +0530
committerAndinus <andinus@nand.sh>2021-09-11 18:51:23 +0530
commitf73d1a4b3fef52efe0190c086264d6f5f755a9e2 (patch)
tree4938a525e9efdb2ba5cc3651ee544997a627fd9b
parenta1ee4822771957e34d6990e35c272c8da183027d (diff)
downloadexercism-f73d1a4b3fef52efe0190c086264d6f5f755a9e2.tar.gz
Raku: Add Allergies
-rw-r--r--README.org1
-rw-r--r--raku/allergies/Allergies.rakumod18
-rw-r--r--raku/allergies/HELP.md32
-rw-r--r--raku/allergies/README.md50
-rw-r--r--raku/allergies/allergies.rakutest498
5 files changed, 599 insertions, 0 deletions
diff --git a/README.org b/README.org
index 35b637f..60b130f 100644
--- a/README.org
+++ b/README.org
@@ -89,6 +89,7 @@ My solutions for [[https://exercism.io][Exercism]] exercises.
 - [X] Phone Number
 - [X] RNA Transcription
 - [ ] Acronym
+- [ ] Allergies
 
 * Rust [2/4]
 
diff --git a/raku/allergies/Allergies.rakumod b/raku/allergies/Allergies.rakumod
new file mode 100644
index 0000000..9fda548
--- /dev/null
+++ b/raku/allergies/Allergies.rakumod
@@ -0,0 +1,18 @@
+unit module Allergies;
+
+constant %allergens = (
+    eggs         => 0b1,
+    peanuts      => 0b10,
+    shellfish    => 0b100,
+    strawberries => 0b1000,
+    tomatoes     => 0b10000,
+    chocolate    => 0b100000,
+    pollen       => 0b1000000,
+    cats         => 0b10000000,
+);
+
+sub allergic-to( :$item, :$score ) is export {
+}
+
+sub list-allergies($score) is export {
+}
diff --git a/raku/allergies/HELP.md b/raku/allergies/HELP.md
new file mode 100644
index 0000000..415d277
--- /dev/null
+++ b/raku/allergies/HELP.md
@@ -0,0 +1,32 @@
+# Help
+
+## Running the tests
+
+You can run the test suite for the exercise by executing the command
+`prove6 .` in the exercise directory.
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit Allergies.rakumod` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Raku track's documentation](https://exercism.org/docs/tracks/raku)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [Raku resources](https://raku.org/resources/)
+- [/r/rakulang](https://www.reddit.com/r/rakulang) is the Raku subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/raku) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
\ No newline at end of file
diff --git a/raku/allergies/README.md b/raku/allergies/README.md
new file mode 100644
index 0000000..c35e79a
--- /dev/null
+++ b/raku/allergies/README.md
@@ -0,0 +1,50 @@
+# Allergies
+
+Welcome to Allergies on Exercism's Raku Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
+
+An allergy test produces a single numeric score which contains the
+information about all the allergies the person has (that they were
+tested for).
+
+The list of items (and their value) that were tested are:
+
+* eggs (1)
+* peanuts (2)
+* shellfish (4)
+* strawberries (8)
+* tomatoes (16)
+* chocolate (32)
+* pollen (64)
+* cats (128)
+
+So if Tom is allergic to peanuts and chocolate, he gets a score of 34.
+
+Now, given just that score of 34, your program should be able to say:
+
+- Whether Tom is allergic to any one of those allergens listed above.
+- All the allergens Tom is allergic to.
+
+Note: a given score may include allergens **not** listed above (i.e.
+allergens that score 256, 512, 1024, etc.).  Your program should
+ignore those components of the score.  For example, if the allergy
+score is 257, your program should only report the eggs (1) allergy.
+
+## Source
+
+### Created by
+
+- @yanick
+
+### Contributed to by
+
+- @kotp
+- @m-dango
+
+### Based on
+
+Jumpstart Lab Warm-up - http://jumpstartlab.com
\ No newline at end of file
diff --git a/raku/allergies/allergies.rakutest b/raku/allergies/allergies.rakutest
new file mode 100644
index 0000000..df98cfa
--- /dev/null
+++ b/raku/allergies/allergies.rakutest
@@ -0,0 +1,498 @@
+#!/usr/bin/env raku
+use Test;
+use JSON::Fast;
+use lib $?FILE.IO.dirname;
+use Allergies;
+plan 49;
+
+my @test-cases = from-json($=pod[*-1].contents).List;
+for @test-cases -> %case {
+  given %case<property> {
+    when 'allergicTo' {
+      subtest %case<description>, {
+        plan 2;
+        isa-ok ( my $result := allergic-to |%case<input>:p ), Bool;
+        is-deeply $result, %case<expected>, 'Result matches expected';
+      }
+    }
+
+    when 'list' {
+      cmp-ok list-allergies(%case<input><score>),
+        '~~', %case<expected>.Set, %case<description>;
+    }
+  }
+}
+
+=head2 Test Cases
+=begin code
+[
+  {
+    "description": "testing for eggs allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "eggs",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for eggs allergy: allergic only to eggs",
+    "expected": true,
+    "input": {
+      "item": "eggs",
+      "score": 1
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for eggs allergy: allergic to eggs and something else",
+    "expected": true,
+    "input": {
+      "item": "eggs",
+      "score": 3
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for eggs allergy: allergic to something, but not eggs",
+    "expected": false,
+    "input": {
+      "item": "eggs",
+      "score": 2
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for eggs allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "eggs",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for peanuts allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "peanuts",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for peanuts allergy: allergic only to peanuts",
+    "expected": true,
+    "input": {
+      "item": "peanuts",
+      "score": 2
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for peanuts allergy: allergic to peanuts and something else",
+    "expected": true,
+    "input": {
+      "item": "peanuts",
+      "score": 7
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for peanuts allergy: allergic to something, but not peanuts",
+    "expected": false,
+    "input": {
+      "item": "peanuts",
+      "score": 5
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for peanuts allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "peanuts",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for shellfish allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "shellfish",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for shellfish allergy: allergic only to shellfish",
+    "expected": true,
+    "input": {
+      "item": "shellfish",
+      "score": 4
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for shellfish allergy: allergic to shellfish and something else",
+    "expected": true,
+    "input": {
+      "item": "shellfish",
+      "score": 14
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for shellfish allergy: allergic to something, but not shellfish",
+    "expected": false,
+    "input": {
+      "item": "shellfish",
+      "score": 10
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for shellfish allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "shellfish",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for strawberries allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "strawberries",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for strawberries allergy: allergic only to strawberries",
+    "expected": true,
+    "input": {
+      "item": "strawberries",
+      "score": 8
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for strawberries allergy: allergic to strawberries and something else",
+    "expected": true,
+    "input": {
+      "item": "strawberries",
+      "score": 28
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for strawberries allergy: allergic to something, but not strawberries",
+    "expected": false,
+    "input": {
+      "item": "strawberries",
+      "score": 20
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for strawberries allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "strawberries",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for tomatoes allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "tomatoes",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for tomatoes allergy: allergic only to tomatoes",
+    "expected": true,
+    "input": {
+      "item": "tomatoes",
+      "score": 16
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for tomatoes allergy: allergic to tomatoes and something else",
+    "expected": true,
+    "input": {
+      "item": "tomatoes",
+      "score": 56
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for tomatoes allergy: allergic to something, but not tomatoes",
+    "expected": false,
+    "input": {
+      "item": "tomatoes",
+      "score": 40
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for tomatoes allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "tomatoes",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for chocolate allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "chocolate",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for chocolate allergy: allergic only to chocolate",
+    "expected": true,
+    "input": {
+      "item": "chocolate",
+      "score": 32
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for chocolate allergy: allergic to chocolate and something else",
+    "expected": true,
+    "input": {
+      "item": "chocolate",
+      "score": 112
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for chocolate allergy: allergic to something, but not chocolate",
+    "expected": false,
+    "input": {
+      "item": "chocolate",
+      "score": 80
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for chocolate allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "chocolate",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for pollen allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "pollen",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for pollen allergy: allergic only to pollen",
+    "expected": true,
+    "input": {
+      "item": "pollen",
+      "score": 64
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for pollen allergy: allergic to pollen and something else",
+    "expected": true,
+    "input": {
+      "item": "pollen",
+      "score": 224
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for pollen allergy: allergic to something, but not pollen",
+    "expected": false,
+    "input": {
+      "item": "pollen",
+      "score": 160
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for pollen allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "pollen",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for cats allergy: not allergic to anything",
+    "expected": false,
+    "input": {
+      "item": "cats",
+      "score": 0
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for cats allergy: allergic only to cats",
+    "expected": true,
+    "input": {
+      "item": "cats",
+      "score": 128
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for cats allergy: allergic to cats and something else",
+    "expected": true,
+    "input": {
+      "item": "cats",
+      "score": 192
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for cats allergy: allergic to something, but not cats",
+    "expected": false,
+    "input": {
+      "item": "cats",
+      "score": 64
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "testing for cats allergy: allergic to everything",
+    "expected": true,
+    "input": {
+      "item": "cats",
+      "score": 255
+    },
+    "property": "allergicTo"
+  },
+  {
+    "description": "list when: no allergies",
+    "expected": [
+    ],
+    "input": {
+      "score": 0
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: just eggs",
+    "expected": [
+      "eggs"
+    ],
+    "input": {
+      "score": 1
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: just peanuts",
+    "expected": [
+      "peanuts"
+    ],
+    "input": {
+      "score": 2
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: just strawberries",
+    "expected": [
+      "strawberries"
+    ],
+    "input": {
+      "score": 8
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: eggs and peanuts",
+    "expected": [
+      "eggs",
+      "peanuts"
+    ],
+    "input": {
+      "score": 3
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: more than eggs but not peanuts",
+    "expected": [
+      "eggs",
+      "shellfish"
+    ],
+    "input": {
+      "score": 5
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: lots of stuff",
+    "expected": [
+      "strawberries",
+      "tomatoes",
+      "chocolate",
+      "pollen",
+      "cats"
+    ],
+    "input": {
+      "score": 248
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: everything",
+    "expected": [
+      "eggs",
+      "peanuts",
+      "shellfish",
+      "strawberries",
+      "tomatoes",
+      "chocolate",
+      "pollen",
+      "cats"
+    ],
+    "input": {
+      "score": 255
+    },
+    "property": "list"
+  },
+  {
+    "description": "list when: no allergen score parts",
+    "expected": [
+      "eggs",
+      "shellfish",
+      "strawberries",
+      "tomatoes",
+      "chocolate",
+      "pollen",
+      "cats"
+    ],
+    "input": {
+      "score": 509
+    },
+    "property": "list"
+  }
+]
+=end code