Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created October 17, 2008 16:22
Show Gist options
  • Save seven1m/17456 to your computer and use it in GitHub Desktop.
Save seven1m/17456 to your computer and use it in GitHub Desktop.
require 'test/unit'
require 'date'
class BirthdayCalculationTest < Test::Unit::TestCase
def test_calculation
bday = Birthday.new(1981, 12, 4)
today = Date.new(2008, 11, 4)
assert_equal 30, bday.days_from(today)
end
def test_lower_month_number
bday = Birthday.new(1981, 1, 4)
today = Date.new(2008, 11, 4)
assert_equal 61, bday.days_from(today)
end
def test_leap_year
bday = Birthday.new(1981, 3, 4)
today = Date.new(2008, 2, 4)
assert_equal 29, bday.days_from(today)
today = Date.new(2009, 2, 4)
assert_equal 28, bday.days_from(today)
end
end
class Birthday < Date
def days_from(from_day)
# return number of days (without taking birthday year in consideration)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment