commit bef1eb2c5de699bff52eaa3f2f5e4b21e34a505b
parent db7a0fc31bc421b402bcc3eb622a85b8a114c48e
Author: Samir Parikh <noreply@samirparikh.com>
Date: Sat, 5 Mar 2022 13:22:50 +0000
initial commit for leap
Diffstat:
A | leap/HELP.md | | | 36 | ++++++++++++++++++++++++++++++++++++ |
A | leap/Leap.pm | | | 13 | +++++++++++++ |
A | leap/README.md | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
A | leap/leap.t | | | 98 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 196 insertions(+), 0 deletions(-)
diff --git a/leap/HELP.md b/leap/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 Leap.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/leap/Leap.pm b/leap/Leap.pm
@@ -0,0 +1,13 @@
+# Declare package 'Leap'
+package Leap;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<is_leap_year>;
+
+sub is_leap_year {
+ my ($year) = @_;
+ return undef; # Replace this with your own code to pass the tests.
+}
+
+1;
diff --git a/leap/README.md b/leap/README.md
@@ -0,0 +1,48 @@
+# Leap
+
+Welcome to Leap on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a year, report if it is a leap year.
+
+The tricky thing here is that a leap year in the Gregorian calendar occurs:
+
+```text
+on every year that is evenly divisible by 4
+ except every year that is evenly divisible by 100
+ unless the year is also evenly divisible by 400
+```
+
+For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
+year, but 2000 is.
+
+## Notes
+
+Though our exercise adopts some very simple rules, there is more to
+learn!
+
+For a delightful, four minute explanation of the whole leap year
+phenomenon, go watch [this youtube video][video].
+
+[video]: http://www.youtube.com/watch?v=xX96xng7sAE
+
+## Source
+
+### Created by
+
+- @dnmfarrell
+
+### Contributed to by
+
+- @bistik
+- @darksuji
+- @kotp
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp
+\ No newline at end of file
diff --git a/leap/leap.t b/leap/leap.t
@@ -0,0 +1,98 @@
+#!/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"; # Find modules in the same dir as this file.
+
+use Leap qw<is_leap_year>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+plan 10; # This is how many tests we expect to run.
+
+imported_ok qw<is_leap_year> or bail_out;
+
+for my $case (@test_cases) {
+ is(
+ is_leap_year( $case->{input}{year} ),
+ $case->{expected} ? T : DF, # Check if True, or Defined but False
+ $case->{description}
+ );
+}
+
+__DATA__
+[
+ {
+ "description": "year not divisible by 4 in common year",
+ "expected": false,
+ "input": {
+ "year": 2015
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 2, not divisible by 4 in common year",
+ "expected": false,
+ "input": {
+ "year": 1970
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 4, not divisible by 100 in leap year",
+ "expected": true,
+ "input": {
+ "year": 1996
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 4 and 5 is still a leap year",
+ "expected": true,
+ "input": {
+ "year": 1960
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 100, not divisible by 400 in common year",
+ "expected": false,
+ "input": {
+ "year": 2100
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 100 but not by 3 is still not a leap year",
+ "expected": false,
+ "input": {
+ "year": 1900
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 400 is leap year",
+ "expected": true,
+ "input": {
+ "year": 2000
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 400 but not by 125 is still a leap year",
+ "expected": true,
+ "input": {
+ "year": 2400
+ },
+ "property": "leapYear"
+ },
+ {
+ "description": "year divisible by 200, not divisible by 400 in common year",
+ "expected": false,
+ "input": {
+ "year": 1800
+ },
+ "property": "leapYear"
+ }
+]