From 4b013b8b9af0e8db48b10882f64bff252cf7742d Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 23 Nov 2024 14:09:55 -0800 Subject: add user-defined global weather timing offset helper for adjusting final output unix time. Should only be used in single-threaded environment --- tests/test_eorzea_weather.rs | 48 ++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/test_eorzea_weather.rs b/tests/test_eorzea_weather.rs index a13b994..027097d 100644 --- a/tests/test_eorzea_weather.rs +++ b/tests/test_eorzea_weather.rs @@ -1,12 +1,15 @@ extern crate ffxiv_chronowatcher; -use ffxiv_chronowatcher::eorzean_weather::{calculate_current_weather_interval, find_next_weather_occurance, get_weather_by_time, calculate_forecast, Weather}; -use chrono::DateTime; +use ffxiv_chronowatcher::eorzean_weather::{ + calculate_current_weather_interval, calculate_forecast, find_next_weather_occurance, + get_global_weather_timing_offset, get_weather_by_time, set_global_weather_timing_offset, + Weather, +}; mod weather_tests { use super::*; #[test] - fn test_calculate_current_weather_interval(){ + fn test_calculate_current_weather_interval() { let timestamp = 1724738458; let (start, end) = calculate_current_weather_interval(timestamp); assert_eq!(start, 1724738403); @@ -14,14 +17,13 @@ mod weather_tests { } #[test] - fn test_get_weather_by_time(){ + fn test_get_weather_by_time() { let timestamp = 1724738458; - let weather = get_weather_by_time("Middle La Noscea", timestamp); - println!("{:?}", weather); + get_weather_by_time("Middle La Noscea", timestamp); } #[test] - fn test_calculate_forecast_pos_offset(){ + fn test_calculate_forecast_pos_offset() { let timestamp = 1724738458; let weather = calculate_forecast("Middle La Noscea", timestamp, 8); assert_eq!(weather.weather, Weather::ClearSkies); @@ -31,7 +33,7 @@ mod weather_tests { } #[test] - fn test_calculate_forecast_neg_offset(){ + fn test_calculate_forecast_neg_offset() { let timestamp = 1724738458; let weather = calculate_forecast("Middle La Noscea", timestamp, -1); assert_eq!(weather.weather, Weather::Wind); @@ -41,7 +43,7 @@ mod weather_tests { } #[test] - fn test_calculate_forecast_zero_offset(){ + fn test_calculate_forecast_zero_offset() { let timestamp = 1724738458; let weather = calculate_forecast("Middle La Noscea", timestamp, 0); assert_eq!(weather.weather, Weather::Wind); @@ -51,7 +53,7 @@ mod weather_tests { } #[test] - fn test_find_next_weather_occurance(){ + fn test_find_next_weather_occurance() { let timestamp = 1724738458; let weather = find_next_weather_occurance("Eureka Pagos", timestamp, Weather::Blizzards); assert_eq!(weather.weather, Weather::Blizzards); @@ -61,7 +63,7 @@ mod weather_tests { } #[test] - fn test_convert_weather_enum_to_string(){ + fn test_convert_weather_enum_to_string() { let weather_variants = vec![ (Weather::AstroMagneticStorm, "Astro-Magnetic Storms"), (Weather::Blizzards, "Blizzards"), @@ -90,19 +92,31 @@ mod weather_tests { } #[test] - fn test_calculate_current_weather_interval_day_overflow(){ - let (start, end) = calculate_current_weather_interval(1672531199); - assert_eq!(1,1); + fn test_calculate_current_weather_interval_day_overflow() { + let (_, __) = calculate_current_weather_interval(1672531199); + assert_eq!(1, 1); } #[test] #[should_panic] fn get_weather_by_time_panic_zone_not_found() { let timestamp = 1724738458; - let weather = get_weather_by_time("Somewhere Not Here", timestamp); + get_weather_by_time("Somewhere Not Here", timestamp); } + #[test] + fn test_set_global_offset() { + set_global_weather_timing_offset(1724738458); + assert_eq!(get_global_weather_timing_offset(), 1724738458); + set_global_weather_timing_offset(0); + } - + #[test] + fn test_find_weather_by_time_with_offset() { + let timestamp = 1732396696; + set_global_weather_timing_offset(40); + let weather = find_next_weather_occurance("Eureka Pagos", timestamp, Weather::Fog); + assert_eq!(weather.start_time, 1732401962); + set_global_weather_timing_offset(0); + } } - -- cgit v1.2.3