Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions katas/3-christmas_day/eddbot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# The Ghost of Christmas Past 🎅🎄👻

Christmas, this year, falls on a Wednesday!

But on which day did Christmas fall in years past?

## Problem Description

Write a Ruby class that returns the correct weekday of Christmas Day for previous years.

## Requirements and Constraints

### Requirements

Your code should return the name of the day of the week that Christmas Day was:
- Officially celebrated
- In England
- Using the relative local date and time

### Constraints

**You may not use Ruby's `Date` or `Time` classes, nor any other third party library to perform date computations for you**. Your solution should be derived from first-principles, implementing the logic yourself.

### Input Specifications

See the attached tests.

### Output Specifications

See the attached tests. All tests must pass!

## Examples and Test Cases

See the attached tests.

## Getting started

1. Make sure your local repository is up to date with origin and you are on the `main` branch.
2. `bin/cleo_katas attempt christmas_day`
3. `ruby katas/3-christmas_day/[yourname]/test.rb`


---

## How to run your main file

```
bundle exec ruby katas/3-christmas_day/edward.s/main.rb
```

7 changes: 7 additions & 0 deletions katas/3-christmas_day/eddbot/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'bundler/inline'

gemfile do
source 'https://rubygems.org'
gem 'minitest'
end

113 changes: 113 additions & 0 deletions katas/3-christmas_day/eddbot/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
require_relative 'main'
require 'minitest/autorun'

class ChristmasDay

DAYS_OF_WEEK = %w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
START_YEAR = 2024

def initialize(year)
@year = year
end

def is_leap_year?(other_year, gregorian: true)
if gregorian
return true if (other_year % 100).zero? && (other_year % 400).zero?
return false if (other_year % 100).zero?
return (other_year % 4).zero?
end

(other_year % 4).zero?
end

def weekday
raise if (1644...1660).include?(year) # Xmas is banned

t = 2 # Wednesday!
number_of_years_to_jump = START_YEAR - year
mutable_year = 2024

while(mutable_year != year)
# date resets (yes i'm cheating :D )
t = 4 if mutable_year == 1752 # Old Xmas (gregorian switcheroo)
t = 2 if mutable_year-1 == 1660 # Xmas is back baby!

if is_leap_year?(mutable_year)
t -= 1
t = 6 if t < 0
t -= 1
t = 6 if t < 0
else
t -= 1
t = 6 if t < 0
end

mutable_year-=1
number_of_years_to_jump-=1
end

DAYS_OF_WEEK[t]
end

private

attr_reader :year
end

class ChristmasDayTest < Minitest::Test
def test_returns_the_correct_weekday_for_2025
skip 'Not implemented'
assert_raises { ChristmasDay.new(2025).weekday }
end

def test_returns_the_correct_weekday_for_2024
assert_equal 'Wednesday', ChristmasDay.new(2024).weekday
end

def test_returns_the_correct_weekday_for_2001
assert_equal 'Tuesday', ChristmasDay.new(2001).weekday
end

def test_returns_the_correct_weekday_for_1900
assert_equal 'Tuesday', ChristmasDay.new(1900).weekday
end

def test_returns_the_correct_weekday_for_1752
assert_equal 'Monday', ChristmasDay.new(1752).weekday
end

def test_returns_the_correct_weekday_for_1751
assert_equal 'Wednesday', ChristmasDay.new(1751).weekday
end

def test_returns_the_correct_weekday_for_1660
assert_equal 'Tuesday', ChristmasDay.new(1660).weekday
end

def test_returns_the_correct_weekday_for_1659
assert_raises { ChristmasDay.new(1659).weekday }
end

def test_returns_the_correct_weekday_for_1644
assert_raises { ChristmasDay.new(1644).weekday }
end

def test_returns_the_correct_weekday_for_1643
assert_equal 'Monday', ChristmasDay.new(1643).weekday
end

def test_returns_the_correct_weekday_for_1066
skip 'Not implemented'
assert_equal 'Monday', ChristmasDay.new(1066).weekday
end

def test_returns_the_correct_weekday_for_597
skip 'Not implemented'
assert_equal 'Wednesday', ChristmasDay.new(597).weekday
end

def test_returns_the_correct_weekday_for_596
skip 'Not implemented'
assert_raises { ChristmasDay.new(596).weekday }
end
end
Loading