#![allow(clippy::all, clippy::pedantic, clippy::restriction, warnings)]
use deep_time::{Dt, Scale};
mod astropy_verified_conversions_tests {
use super::*;
#[test]
fn galexsec() {
let galexsec = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::UTC)
.to_galexsec()
.to_sec_f();
assert_eq!(galexsec, 1261871963.0);
}
#[test]
fn gps() {
let gps = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::GPS)
.to_gps()
.to_sec_f();
assert_eq!(gps, 1261871981.0);
}
#[test]
fn unix_tai() {
let unix_tai = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.to_unix()
.to_sec_f();
assert_eq!(unix_tai, 1577836800.0);
}
#[test]
fn unix_utc() {
let unix = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::UTC)
.to_unix()
.to_sec_f();
assert_eq!(unix, 1577836763.0);
}
#[test]
fn cxcsec() {
let cxc = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::TT)
.to_cxcsec()
.to_sec_f();
assert_eq!(cxc, 694224032.184);
}
#[test]
fn decimal_year() {
let x = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0);
let y = Dt::from_ymd(-2000, 1, 1, Scale::TAI, 0, 0, 0, 0);
assert_eq!(x.to_jyear(), 2019.9986310746065);
assert!((x.to_byear() - 2020.000335739628).abs() < 1e-12);
assert_eq!(x.to_decimalyear(), 2020.0);
assert_eq!(y.to_decimalyear(), -2000.0);
}
#[test]
fn tai_jd() {
let jd = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0).to_jd_f();
assert_eq!(jd, 2458849.5);
}
#[test]
fn tt_jd() {
let jd = Dt::from_ymd(2020, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::TT)
.to_jd_f();
assert_eq!(jd, 2458849.500372500158846);
}
#[test]
fn tdb_jd_multi() {
let results = [
2086302.500372504815459,
2086392.500372519250959,
2268923.500372501555830,
2269013.500372519250959,
2451544.500372498761863,
2451635.500372518785298,
2451910.500372499227524,
2452000.500372518785298,
2452275.500372499227524,
2452365.500372518785298,
2452640.500372499227524,
2452730.500372518785298,
2453005.500372499227524,
2453096.500372519250959,
2453371.500372499693185,
2453461.500372519250959,
2453736.500372499227524,
2453826.500372519250959,
2454101.500372499227524,
2454191.500372519250959,
2454832.500372499227524,
2454922.500372519250959,
2455197.500372498761863,
2455287.500372519250959,
2455562.500372498761863,
2455652.500372519250959,
2455927.500372498761863,
2456018.500372519250959,
2456293.500372499227524,
2456383.500372518785298,
2456658.500372499227524,
2456748.500372518785298,
2457023.500372499227524,
2457113.500372519250959,
2457388.500372499227524,
2457479.500372519250959,
2457754.500372499227524,
2457844.500372519250959,
2458119.500372499227524,
2458209.500372519250959,
2458849.500372498761863,
2458940.500372519250959,
2459215.500372498761863,
2459305.500372519250959,
2461406.500372499227524,
2461496.500372518785298,
2462502.500372499227524,
2462592.500372519250959,
2464328.500372498761863,
2464418.500372518785298,
2487704.500372499227524,
2487794.500372519250959,
3182029.500372488982975,
3182120.500372514594346,
4642999.500372484326363,
4643090.500372495502234,
];
let mut results_idx: usize = 0;
let mut diffs: f64 = 0.0;
let mut max_diff: f64 = 0.0;
#[cfg(feature = "tdb_fairhead1990")]
const TOLERANCE: f64 = 0.0;
#[cfg(not(feature = "tdb_fairhead1990"))]
const TOLERANCE: f64 = 2.0e-9;
for yr in [
1000, 1500, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2027, 2030, 2035, 2099, 4000, 8000,
]
.iter()
{
for mo in [1, 4] {
let jd = Dt::from_ymd(*yr as i64, mo, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::TDB)
.to_jd_f();
let expected = results[results_idx];
let diff = (jd - expected).abs();
assert!(
diff <= TOLERANCE,
"{yr}-{mo:02}-01: diff = {diff:.2e} JD (expected {expected:.15}, got {jd:.15})"
);
diffs += diff;
if diff > max_diff {
max_diff = diff;
}
results_idx += 1;
}
}
let ave_diff = diffs / results_idx as f64;
}
#[test]
fn tcb_jd() {
let results = [
2268923.497671171557158,
2451544.500502743292600,
2458849.500616008881480,
3182029.511829047929496,
];
let mut result: usize = 0;
for yr in [1500, 2000, 2020, 4000] {
let expected = results[result];
let jd = Dt::from_ymd(yr as i64, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::TCB)
.to_jd_f();
if cfg!(feature = "tdb_fairhead1990") {
assert_eq!(jd, expected);
} else {
let diff = (jd - expected).abs();
assert!(
diff < 2e-9,
"TCB JD diff too large without tdb_fairhead1990 feature: {}",
diff
);
}
result += 1;
}
}
#[test]
fn tcg_jd() {
let results = [
2268923.500251080375165,
2451544.500378353986889,
2458849.500383445061743,
3182029.500887450296432,
];
let mut result: usize = 0;
for yr in [1500, 2000, 2020, 4000] {
let expected = results[result];
let jd = Dt::from_ymd(yr as i64, 1, 1, Scale::TAI, 0, 0, 0, 0)
.target(Scale::TCG)
.to_jd_f();
assert_eq!(jd, expected);
result += 1;
}
}
}