diff options
author | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
commit | 321825828ac918bad28d0597a8616c6dc9802c3c (patch) | |
tree | 0b8e9cb1012197750eb58e972736319b2a6abac2 /raku/two-fer | |
parent | 2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff) | |
download | exercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz |
Add solved exercises
Diffstat (limited to 'raku/two-fer')
-rw-r--r-- | raku/two-fer/README.md | 49 | ||||
-rw-r--r-- | raku/two-fer/TwoFer.rakumod | 5 | ||||
-rw-r--r-- | raku/two-fer/two-fer.rakutest | 49 |
3 files changed, 103 insertions, 0 deletions
diff --git a/raku/two-fer/README.md b/raku/two-fer/README.md new file mode 100644 index 0000000..51dfd1d --- /dev/null +++ b/raku/two-fer/README.md @@ -0,0 +1,49 @@ +# Two Fer + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +Given a name, return a string with the message: + +```text +One for name, one for me. +``` + +Where "name" is the given name. + +However, if the name is missing, return the string: + +```text +One for you, one for me. +``` + +Here are some examples: + +|Name |String to return +|:-------|:------------------ +|Alice |One for Alice, one for me. +|Bob |One for Bob, one for me. +| |One for you, one for me. +|Zaphod |One for Zaphod, one for me. + +## 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 + +[https://github.com/exercism/problem-specifications/issues/757](https://github.com/exercism/problem-specifications/issues/757) + +## 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/two-fer/TwoFer.rakumod b/raku/two-fer/TwoFer.rakumod new file mode 100644 index 0000000..cf07952 --- /dev/null +++ b/raku/two-fer/TwoFer.rakumod @@ -0,0 +1,5 @@ +unit module TwoFer; + +sub two-fer ($name?) is export { + return "One for {$name // "you"}, one for me."; +} diff --git a/raku/two-fer/two-fer.rakutest b/raku/two-fer/two-fer.rakutest new file mode 100644 index 0000000..f79c03e --- /dev/null +++ b/raku/two-fer/two-fer.rakutest @@ -0,0 +1,49 @@ +#!/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 TwoFer; +plan 3; #`[This is how many tests we expect to run.] + +my @test-cases = from-json($=pod.pop.contents).List; +# Go through the cases and check that &two-fer gives us the correct response. +for @test-cases -> %case { + is do { + with %case<input><name> { + .&two-fer; + } + else { + two-fer; + } + }, |%case<expected description>; +} + +=head2 Test Cases +=begin code +[ + { + "description": "no name given", + "expected": "One for you, one for me.", + "input": { + "name": null + }, + "property": "twoFer" + }, + { + "description": "a name given", + "expected": "One for Alice, one for me.", + "input": { + "name": "Alice" + }, + "property": "twoFer" + }, + { + "description": "another name given", + "expected": "One for Bob, one for me.", + "input": { + "name": "Bob" + }, + "property": "twoFer" + } +] +=end code |