Last active
August 29, 2015 14:10
-
-
Save paulghaddad/160b2b4329e2e7a4ff38 to your computer and use it in GitHub Desktop.
Exercism: Gigasecond
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gigasecond | |
Write a program that will calculate the date that someone turned or will celebrate their 1 Gs anniversary. | |
A gigasecond is one billion (10**9) seconds. | |
## Source | |
Chapter 9 in Chris Pine's online Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=09) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'time' | |
class Gigasecond | |
GIGASECONDs_IN_DAYS = 10**9 / (60 * 60 * 24) # 1 day = 86,400 seconds | |
def self.from(date) | |
date + GIGASECONDs_IN_DAYS | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require 'date' | |
require 'time' | |
require_relative 'gigasecond' | |
class GigasecondTest < MiniTest::Unit::TestCase | |
def test_1 | |
gs = Gigasecond.from(Date.new(2011, 4, 25)) | |
assert_equal Date.new(2043, 1, 1), gs | |
end | |
def test_2 | |
gs = Gigasecond.from(Date.new(1977, 6, 13)) | |
assert_equal Date.new(2009, 2, 19), gs | |
end | |
def test_3 | |
gs = Gigasecond.from(Date.new(1959, 7, 19)) | |
assert_equal Date.new(1991, 3, 27), gs | |
end | |
def test_yourself | |
your_birthday = Date.new(1982, 10, 16) | |
gs = Gigasecond.from(your_birthday) | |
assert_equal Date.new(2014, 6, 24), gs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment