From dbe6b2b1bdc63e8bcd8d87ebad6568f5d2192425 Mon Sep 17 00:00:00 2001 From: James Walker Date: Sun, 16 Sep 2018 15:09:43 -0400 Subject: [PATCH] ruby - gigasecond --- ruby/gigasecond/README.md | 35 ++++++++++++++++++++++++++++++ ruby/gigasecond/gigasecond.rb | 7 ++++++ ruby/gigasecond/gigasecond_test.rb | 30 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 ruby/gigasecond/README.md create mode 100644 ruby/gigasecond/gigasecond.rb create mode 100644 ruby/gigasecond/gigasecond_test.rb diff --git a/ruby/gigasecond/README.md b/ruby/gigasecond/README.md new file mode 100644 index 0000000..5753d0e --- /dev/null +++ b/ruby/gigasecond/README.md @@ -0,0 +1,35 @@ +# Gigasecond + +Calculate the moment when someone has lived for 10^9 seconds. + +A gigasecond is 10^9 (1,000,000,000) seconds. + +* * * * + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/ruby). + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + + gem install minitest + +If you would like color output, you can `require 'minitest/pride'` in +the test file, or note the alternative instruction, below, for running +the test file. + +Run the tests from the exercise directory using the following command: + + ruby gigasecond_test.rb + +To include color from the command line: + + ruby -r minitest/pride gigasecond_test.rb + + +## Source + +Chapter 9 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=09](http://pine.fm/LearnToProgram/?Chapter=09) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/ruby/gigasecond/gigasecond.rb b/ruby/gigasecond/gigasecond.rb new file mode 100644 index 0000000..455db48 --- /dev/null +++ b/ruby/gigasecond/gigasecond.rb @@ -0,0 +1,7 @@ +class Gigasecond + GIGASECOND = 10 ** 9 + + def self.from(start) + start + GIGASECOND + end +end diff --git a/ruby/gigasecond/gigasecond_test.rb b/ruby/gigasecond/gigasecond_test.rb new file mode 100644 index 0000000..e694f17 --- /dev/null +++ b/ruby/gigasecond/gigasecond_test.rb @@ -0,0 +1,30 @@ +require 'minitest/autorun' +require_relative 'gigasecond' + +# Common test data version: 1.1.0 5506bac +class GigasecondTest < Minitest::Test + def test_date_only_specification_of_time + # skip + assert_equal Time.utc(2043, 1, 1, 1, 46, 40), Gigasecond.from(Time.utc(2011, 4, 25, 0, 0, 0)) + end + + def test_second_test_for_date_only_specification_of_time + # skip + assert_equal Time.utc(2009, 2, 19, 1, 46, 40), Gigasecond.from(Time.utc(1977, 6, 13, 0, 0, 0)) + end + + def test_third_test_for_date_only_specification_of_time + # skip + assert_equal Time.utc(1991, 3, 27, 1, 46, 40), Gigasecond.from(Time.utc(1959, 7, 19, 0, 0, 0)) + end + + def test_full_time_specified + # skip + assert_equal Time.utc(2046, 10, 2, 23, 46, 40), Gigasecond.from(Time.utc(2015, 1, 24, 22, 0, 0)) + end + + def test_full_time_with_day_roll_over + # skip + assert_equal Time.utc(2046, 10, 3, 1, 46, 39), Gigasecond.from(Time.utc(2015, 1, 24, 23, 59, 59)) + end +end