exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs | README

commit 81e5ae2aa9124ee756b5f7c29940a1b8e86db849
parent cc87233946533fe478bcf1dd05b0dfe5513ea5a9
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Tue, 25 Jan 2022 15:18:37 +0000

initial commit for grade-school

Diffstat:
Agrade-school/GradeSchool.pm | 12++++++++++++
Agrade-school/HELP.md | 36++++++++++++++++++++++++++++++++++++
Agrade-school/README.md | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agrade-school/grade-school.t | 170+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 278 insertions(+), 0 deletions(-)

diff --git a/grade-school/GradeSchool.pm b/grade-school/GradeSchool.pm @@ -0,0 +1,12 @@ +package GradeSchool; +use strict; +use warnings; +use Exporter qw<import>; +our @EXPORT_OK = qw<roster>; + +sub roster { + my ( $students, $grade ) = @_; + return undef; +} + +1; diff --git a/grade-school/HELP.md b/grade-school/HELP.md @@ -0,0 +1,35 @@ +# Help + +## Running the tests + +There is a Perl 5 script with the extension `.t`, which will be used to test +your solution. You can run through the tests by using the command: + +```bash +`prove .` +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit GradeSchool.pm` 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 [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5) +- [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: + +- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) 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/grade-school/README.md b/grade-school/README.md @@ -0,0 +1,59 @@ +# Grade School + +Welcome to Grade School on Exercism's Perl 5 Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given students' names along with the grade that they are in, create a roster +for the school. + +In the end, you should be able to: + +- Add a student's name to the roster for a grade + - "Add Jim to grade 2." + - "OK." +- Get a list of all students enrolled in a grade + - "Which students are in grade 2?" + - "We've only got Jim just now." +- Get a sorted list of all students in all grades. Grades should sort + as 1, 2, 3, etc., and students within a grade should be sorted + alphabetically by name. + - "Who all is enrolled in school right now?" + - "Let me think. We have + Anna, Barb, and Charlie in grade 1, + Alex, Peter, and Zoe in grade 2 + and Jim in grade 5. + So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe and Jim" + +Note that all our students only have one name. (It's a small town, what +do you want?) + +## For bonus points + +Did you get the tests passing and the code clean? If you want to, these +are some additional things you could try: + +- If you're working in a language with mutable data structures and your + implementation allows outside code to mutate the school's internal DB + directly, see if you can prevent this. Feel free to introduce additional + tests. + +Then please share your thoughts in a comment on the submission. Did this +experiment make the code better? Worse? Did you learn anything from it? + +## Source + +### Created by + +- @bentglasstube + +### Contributed to by + +- @kytrinyx +- @m-dango +- @rfilipo + +### Based on + +A pairing session with Phil Battos at gSchool - http://gschool.it +\ No newline at end of file diff --git a/grade-school/grade-school.t b/grade-school/grade-school.t @@ -0,0 +1,170 @@ +#!/usr/bin/env perl +use Test2::V0; +use JSON::PP; +use constant JSON => JSON::PP->new; + +use FindBin qw<$Bin>; +use lib $Bin, "$Bin/local/lib/perl5"; + +use GradeSchool qw<roster>; + +my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; }; +plan 8; + +imported_ok qw<roster> or bail_out; + +for my $case (@test_cases) { + is roster( $case->{input}{students}, $case->{input}{desiredGrade} ), + $case->{expected}, $case->{description}; +} + +__DATA__ +[ + { + "description": "Roster is empty when no student is added", + "expected": [], + "input": { + "students": [] + }, + "property": "roster" + }, + { + "description": "Student is added to the roster", + "expected": [ + "Aimee" + ], + "input": { + "students": [ + [ + "Aimee", + 2 + ] + ] + }, + "property": "roster" + }, + { + "description": "Multiple students in the same grade are added to the roster", + "expected": [ + "Blair", + "James", + "Paul" + ], + "input": { + "students": [ + [ + "Blair", + 2 + ], + [ + "James", + 2 + ], + [ + "Paul", + 2 + ] + ] + }, + "property": "roster" + }, + { + "description": "Students in multiple grades are added to the roster", + "expected": [ + "Chelsea", + "Logan" + ], + "input": { + "students": [ + [ + "Chelsea", + 3 + ], + [ + "Logan", + 7 + ] + ] + }, + "property": "roster" + }, + { + "description": "Students are sorted by grades and then by name in the roster", + "expected": [ + "Anna", + "Barb", + "Charlie", + "Alex", + "Peter", + "Zoe", + "Jim" + ], + "input": { + "students": [ + [ + "Peter", + 2 + ], + [ + "Anna", + 1 + ], + [ + "Barb", + 1 + ], + [ + "Zoe", + 2 + ], + [ + "Alex", + 2 + ], + [ + "Jim", + 3 + ], + [ + "Charlie", + 1 + ] + ] + }, + "property": "roster" + }, + { + "description": "Grade is empty if no students in the roster", + "expected": [], + "input": { + "desiredGrade": 1, + "students": [] + }, + "property": "grade" + }, + { + "description": "Students are sorted by name in a grade", + "expected": [ + "Bradley", + "Franklin" + ], + "input": { + "desiredGrade": 5, + "students": [ + [ + "Franklin", + 5 + ], + [ + "Bradley", + 5 + ], + [ + "Jeff", + 1 + ] + ] + }, + "property": "grade" + } +]