commit 2d49fa5dc3f5979fe9f0d8e86005de0292ff24a3
parent 5c6e7d59965eef13788729ec6625809c8662f40e
Author: Samir Parikh <noreply@samirparikh.com>
Date: Wed, 18 May 2022 12:46:10 +0000
get all tests to pass
Diffstat:
4 files changed, 197 insertions(+), 0 deletions(-)
diff --git a/space-age/HELP.md b/space-age/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 SpaceAge.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/space-age/README.md b/space-age/README.md
@@ -0,0 +1,39 @@
+# Space Age
+
+Welcome to Space Age on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given an age in seconds, calculate how old someone would be on:
+
+- Mercury: orbital period 0.2408467 Earth years
+- Venus: orbital period 0.61519726 Earth years
+- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
+- Mars: orbital period 1.8808158 Earth years
+- Jupiter: orbital period 11.862615 Earth years
+- Saturn: orbital period 29.447498 Earth years
+- Uranus: orbital period 84.016846 Earth years
+- Neptune: orbital period 164.79132 Earth years
+
+So if you were told someone were 1,000,000,000 seconds old, you should
+be able to say that they're 31.69 Earth-years old.
+
+If you're wondering why Pluto didn't make the cut, go watch [this
+YouTube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs).
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=01
+\ No newline at end of file
diff --git a/space-age/SpaceAge.pm b/space-age/SpaceAge.pm
@@ -0,0 +1,25 @@
+package SpaceAge;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<age_on_planet>;
+
+sub age_on_planet {
+ my ($args) = @_;
+ my $EARTH_ORBIT_PER_SECONDS = 31557600;
+ my %ORBITAL_PERIOD = (
+ Mercury => 0.2408467,
+ Venus => 0.61519726,
+ Earth => 1,
+ Mars => 1.8808158,
+ Jupiter => 11.862615,
+ Saturn => 29.447498,
+ Uranus => 84.016846,
+ Neptune => 164.79132,
+ );
+
+return sprintf("%.2f", $args->{seconds} / $EARTH_ORBIT_PER_SECONDS / $ORBITAL_PERIOD{ $args->{planet} });
+
+}
+
+1;
diff --git a/space-age/space-age.t b/space-age/space-age.t
@@ -0,0 +1,96 @@
+#!/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 SpaceAge qw<age_on_planet>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+
+imported_ok qw<age_on_planet> or bail_out;
+
+for my $case (@test_cases) {
+ is( age_on_planet( $case->{input} ),
+ $case->{expected}, $case->{description}, );
+}
+
+done_testing;
+
+__DATA__
+[
+ {
+ "description": "age on Earth",
+ "expected": 31.69,
+ "input": {
+ "planet": "Earth",
+ "seconds": 1000000000
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Mercury",
+ "expected": 280.88,
+ "input": {
+ "planet": "Mercury",
+ "seconds": 2134835688
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Venus",
+ "expected": 9.78,
+ "input": {
+ "planet": "Venus",
+ "seconds": 189839836
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Mars",
+ "expected": 35.88,
+ "input": {
+ "planet": "Mars",
+ "seconds": 2129871239
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Jupiter",
+ "expected": 2.41,
+ "input": {
+ "planet": "Jupiter",
+ "seconds": 901876382
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Saturn",
+ "expected": 2.15,
+ "input": {
+ "planet": "Saturn",
+ "seconds": 2000000000
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Uranus",
+ "expected": 0.46,
+ "input": {
+ "planet": "Uranus",
+ "seconds": 1210123456
+ },
+ "property": "age"
+ },
+ {
+ "description": "age on Neptune",
+ "expected": 0.35,
+ "input": {
+ "planet": "Neptune",
+ "seconds": 1821023456
+ },
+ "property": "age"
+ }
+]