Packages/MoonriseKit/Tests/SkyRendererTests/HistoricalSkyTests.swift
32 lines · 1398 bytes
1import Foundation
2import Testing
3@testable import SkyEngine
4@testable import SkyRenderer
5
6/// The date `years` Julian years from J2000.
7private func epoch(_ years: Double) -> Date { SkyEngine.j2000.addingTimeInterval(years * 365.25 * 86_400) }
8
9private func poleDistance(hr: Int, at date: Date) throws -> Double {
10 let star = try #require(Catalog.stars.first { $0.hr == hr })
11 return 90 - SkyEngine.equatorOfDate(j2000: star.position(at: date), at: date).dec
12}
13
14@Test func polarisClosestAround2100() throws {
15 #expect(try poleDistance(hr: 424, at: epoch(0)) < 0.8)
16 #expect(try poleDistance(hr: 424, at: epoch(100)) < 0.55)
17 #expect(try poleDistance(hr: 424, at: epoch(-2000)) > 10) // year 1
18}
19
20@Test func thubanWasThePoleStar() throws {
21 // Thuban (α Dra, HR 5291) was within about a tenth of a degree of the pole around 2800 BCE.
22 #expect(try poleDistance(hr: 5291, at: epoch(-4800)) < 1)
23 #expect(try poleDistance(hr: 5291, at: epoch(0)) > 20)
24}
25
26@Test func arcturusProperMotion() throws {
27 let arcturus = try #require(Catalog.stars.first { $0.hr == 5340 })
28 let now = arcturus.position(at: epoch(0)), later = arcturus.position(at: epoch(2000))
29 let dRA = (later.ra - now.ra) * cos(now.dec * .pi / 180), dDec = later.dec - now.dec
30 // 2.28″/yr total, so about 1.27° in 2000 years.
31 #expect(abs((dRA * dRA + dDec * dDec).squareRoot() - 1.27) < 0.02)
32}