2017-08-15

This commit is contained in:
2017-08-15 10:04:10 -05:00
parent 63b955575a
commit 88b47de8c8
24 changed files with 3100 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
#`(
This is a 'stub' file. It's a little start on your solution.
It is not a complete solution though; you will have to write some code.
The ':ver<>' adverb defines the version of a module or class.
The version is checked in the test suite to ensure the exercise
and test suite line up. If the test is updated, it will indicate
to others who test your code that some tests may no longer pass.
)
unit module HelloWorld:ver<2>;
sub hello is export {
# Write your solution to pass the test suite here.
# Be sure to remove all stock comments once you are done!
}

View File

@@ -0,0 +1,36 @@
# Hello World
The classical introductory exercise. Just say "Hello, World!".
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
The objectives are simple:
- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.
If everything goes well, you will be ready to fetch your first real exercise.
## Resources
Remember to check out the Perl 6 [documentation](https://docs.perl6.org/) and
[resources](https://perl6.org/resources/) pages for information, tips, and
examples if you get stuck.
## Running the tests
There is a test script included with the exercise; a file with the extension
`.t`. You can run the test script for the exercise by executing the command
`prove . --exec=perl6` in the exercise directory. You can also add the `-v` flag
e.g. `prove . --exec=perl6 -v` to display all tests, including any optional
tests marked as 'TODO'.
## Source
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env perl6
use v6;
use Test;
use lib my $dir = $?FILE.IO.dirname; #`[Look for the module inside the same directory as this test file.]
use JSON::Fast;
my $exercise = 'HelloWorld'; #`[The name of this exercise.]
my $version = v2; #`[The version we will be matching against the exercise.]
my $module = %*ENV<EXERCISM> ?? 'Example' !! $exercise; #`[%*ENV<EXERCISM> is for tests not directly for the exercise, don't worry about these :)]
plan 3; #`[This is how many tests we expect to run.]
#`[Check that the module can be use-d.]
use-ok $module or bail-out;
require ::($module);
#`[If the exercise is updated, we want to make sure other people testing
your code don't think you've made a mistake if things have changed!]
if ::($exercise).^ver !~~ $version {
warn "\nExercise version mismatch. Further tests may fail!"
~ "\n$exercise is $(::($exercise).^ver.gist). "
~ "Test is $($version.gist).\n";
bail-out 'Example version must match test version.' if %*ENV<EXERCISM>;
}
#`[Import '&hello' from 'HelloWorld']
require ::($module) <&hello>;
my $c-data;
#`[Go through the cases (hiding at the bottom of this file)
and check that &hello gives us the correct response.]
is &::('hello')(), |.<expected description> for @($c-data<cases>);
#`[Ignore this for your exercise! Tells Exercism folks when exercise cases become out of date.]
if %*ENV<EXERCISM> {
if (my $c-data-file = "$dir/../../problem-specifications/exercises/{$dir.IO.resolve.basename}/canonical-data.json".IO.resolve) ~~ :f {
is-deeply $c-data, EVAL('use JSON::Fast; from-json($c-data-file.slurp);'), 'canonical-data';
} else { flunk 'canonical-data' }
} else { skip }
done-testing; #`[There are no more tests after this :)]
#`['INIT' is a phaser, it makes sure that the test data is available before everything else
starts running (otherwise we'd have to shove the test data into the middle of the file!)]
INIT {
$c-data := from-json q:to/END/;
{
"exercise": "hello-world",
"version": "1.0.0",
"cases": [
{
"description": "Say Hi!",
"property": "hello",
"expected": "Hello, World!"
}
]
}
END
}