use crate::aberration::*;
use crate::error::AstroError;
use chrono::{TimeZone, Utc};
#[test]
fn test_aberration_at_j2000() {
let dt = Utc.with_ymd_and_hms(2000, 1, 1, 12, 0, 0).unwrap();
let (_ra_app, dec_app) = apply_aberration(0.0, 90.0, dt).unwrap();
assert!((dec_app - 90.0).abs() < 0.01, "Pole star should have minimal aberration");
assert!(dec_app > 89.99, "Should stay very close to pole");
}
#[test]
fn test_aberration_magnitude_range() {
let dt = Utc.with_ymd_and_hms(2024, 6, 21, 0, 0, 0).unwrap();
let test_positions = [
(0.0, 0.0), (90.0, 23.5), (180.0, 0.0), (270.0, -23.5), ];
for (ra, dec) in test_positions {
let mag = aberration_magnitude(ra, dec, dt).unwrap();
assert!((0.0..=1500.0).contains(&mag),
"Total correction at RA={}, Dec={} is {}\" (includes precession)", ra, dec, mag);
}
}
#[test]
fn test_aberration_maximum() {
let dt = Utc.with_ymd_and_hms(2024, 6, 21, 0, 0, 0).unwrap();
let mag = aberration_magnitude(180.0, 0.0, dt).unwrap();
assert!(mag > 0.0 && mag < 1500.0,
"Total apparent correction is {}\" (includes precession)", mag);
}
#[test]
fn test_aberration_seasonal_variation() {
let ra = 100.0;
let dec = 25.0;
let summer = Utc.with_ymd_and_hms(2024, 6, 21, 0, 0, 0).unwrap();
let winter = Utc.with_ymd_and_hms(2024, 12, 21, 0, 0, 0).unwrap();
let (ra_summer, dec_summer) = apply_aberration(ra, dec, summer).unwrap();
let (ra_winter, dec_winter) = apply_aberration(ra, dec, winter).unwrap();
assert!((ra_summer - ra_winter).abs() > 0.001 || (dec_summer - dec_winter).abs() > 0.001,
"Aberration should vary with season");
}
#[test]
fn test_remove_aberration() {
let ra_mean = 150.0;
let dec_mean = 30.0;
let dt = Utc.with_ymd_and_hms(2024, 8, 15, 0, 0, 0).unwrap();
let (ra_app, dec_app) = apply_aberration(ra_mean, dec_mean, dt).unwrap();
let (ra_recovered, dec_recovered) = remove_aberration(ra_app, dec_app, dt).unwrap();
assert!((ra_recovered - ra_mean).abs() < 0.00001,
"RA recovery failed: {} vs {}", ra_recovered, ra_mean);
assert!((dec_recovered - dec_mean).abs() < 0.00001,
"Dec recovery failed: {} vs {}", dec_recovered, dec_mean);
}
#[test]
fn test_aberration_coordinate_validation() {
let dt = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
let result = apply_aberration(400.0, 0.0, dt);
assert!(matches!(result, Err(AstroError::InvalidCoordinate { .. })));
let result = apply_aberration(0.0, 100.0, dt);
assert!(matches!(result, Err(AstroError::InvalidCoordinate { .. })));
}
#[test]
fn test_aberration_ra_wraparound() {
let dt = Utc.with_ymd_and_hms(2024, 3, 20, 0, 0, 0).unwrap();
let (ra_app, _) = apply_aberration(0.1, 45.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_app), "RA should stay normalized");
let (ra_app, _) = apply_aberration(359.9, 45.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_app), "RA should stay normalized");
}
#[test]
fn test_aberration_at_ecliptic_pole() {
let dt = Utc.with_ymd_and_hms(2024, 6, 21, 0, 0, 0).unwrap();
let mag = aberration_magnitude(270.0, 66.56, dt).unwrap();
assert!(mag > 0.0 && mag < 2000.0,
"Ecliptic pole total correction is {}\" (includes precession)", mag);
}
#[test]
fn test_aberration_consistency() {
let ra = 200.0;
let dec = -15.0;
for month in 1..=12 {
let dt = Utc.with_ymd_and_hms(2024, month, 15, 0, 0, 0).unwrap();
let (ra_app, dec_app) = apply_aberration(ra, dec, dt).unwrap();
let (ra_mean, dec_mean) = remove_aberration(ra_app, dec_app, dt).unwrap();
assert!((ra_mean - ra).abs() < 0.00001,
"Month {}: RA inconsistent", month);
assert!((dec_mean - dec).abs() < 0.00001,
"Month {}: Dec inconsistent", month);
}
}
#[test]
fn test_aberration_ra_normalization_apply() {
let dt = Utc.with_ymd_and_hms(2024, 12, 21, 0, 0, 0).unwrap();
let (ra_app, _) = apply_aberration(359.995, 0.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_app), "RA should be normalized");
let (ra_app2, _) = apply_aberration(359.99, 85.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_app2), "RA should be normalized at high dec");
}
#[test]
fn test_aberration_ra_normalization_remove() {
let dt = Utc.with_ymd_and_hms(2024, 6, 21, 0, 0, 0).unwrap();
let (ra_mean, _) = remove_aberration(0.01, 45.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_mean), "RA should be normalized from negative");
let (ra_mean2, _) = remove_aberration(359.99, 45.0, dt).unwrap();
assert!((0.0..360.0).contains(&ra_mean2), "RA should be normalized from >= 360");
}