Skip to content

Commit

Permalink
Add more tests for Julian Date conversion (#122)
Browse files Browse the repository at this point in the history
This adds more variety to the test of Julian Date conversion, based on
examples from Astronomical Algorithms book.
  • Loading branch information
rhannequin authored Jan 31, 2025
1 parent 35ea8e3 commit 84a3b54
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/astronoby/epoch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@

expect(described_class.from_time(time)).to eq(2457153.25)
end

# Source:
# Title: Astronomical Algorithms
# Author: Jean Meeus
# Edition: 2nd edition
# Chapter: 7 - Julian Day
[
[Time.utc(2000, 1, 1, 12), 2451545],
[Date.new(1999, 1, 1), 2451179.5],
[DateTime.new(1987, 6, 19, 12), 2446966],
[Date.new(1988, 1, 27), 2447187.5],
[Time.utc(1988, 6, 19, 12), 2447332],
[Date.new(1900, 1, 1), 2415020.5],
[Date.new(1600, 1, 1), 2305447.5],
[Date.new(1600, 12, 31), 2305812.5],
[Date.new(837, 4, 10), 2026871.5],
[Date.new(-123, 12, 31), 1676496.5],
[Date.new(-122, 1, 1), 1676497.5],
[DateTime.new(-1000, 7, 12, 12), 1356001],
[Date.new(-1000, 2, 29), 1355866.5],
[DateTime.new(-1001, 8, 17, 21, 36), 1355671.4],
[DateTime.new(-4712, 1, 1, 12), 0]
].each do |time_or_date, expected|
it "returns the Julian day number associated with the time" do
expect(described_class.from_time(time_or_date)).to eq(expected)
end
end
end

describe "::to_utc" do
Expand Down Expand Up @@ -107,5 +134,25 @@

expect(time).to eq Time.utc(2012, 4, 1, 20, 52, 48)
end

# Source:
# Title: Astronomical Algorithms
# Author: Jean Meeus
# Edition: 2nd edition
# Chapter: 7 - Julian Day
[
[Time.utc(2000, 1, 1, 12), 2451545],
[Time.utc(1999, 1, 1), 2451179.5],
[Time.utc(1987, 6, 19, 12), 2446966],
[Time.utc(1988, 1, 27), 2447187.5],
[Time.utc(1988, 6, 19, 12), 2447332],
[Time.utc(1900, 1, 1), 2415020.5],
[Time.utc(1600, 1, 1), 2305447.5],
[Time.utc(1600, 12, 31), 2305812.5]
].each do |expected_time, epoch|
it "returns the Julian day number associated with the time" do
expect(described_class.to_utc(epoch)).to eq(expected_time)
end
end
end
end

0 comments on commit 84a3b54

Please sign in to comment.