aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_eorzea_weather.rs
blob: a13b99499da556b7069f170b175cea6351cf21ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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;

mod weather_tests {
    use super::*;
    #[test]
    fn test_calculate_current_weather_interval(){
        let timestamp = 1724738458;
        let (start, end) = calculate_current_weather_interval(timestamp);
        assert_eq!(start, 1724738403);
        assert_eq!(end, 1724739802);
    }

    #[test]
    fn test_get_weather_by_time(){
        let timestamp = 1724738458;
        let weather = get_weather_by_time("Middle La Noscea", timestamp);
        println!("{:?}", weather);
    }

    #[test]
    fn test_calculate_forecast_pos_offset(){
        let timestamp = 1724738458;
        let weather = calculate_forecast("Middle La Noscea", timestamp, 8);
        assert_eq!(weather.weather, Weather::ClearSkies);
        assert_eq!(weather.start_time, 1724749443);
        assert_eq!(weather.end_time, 1724750823);
        assert_eq!(weather.zone_name, "Middle La Noscea");
    }

    #[test]
    fn test_calculate_forecast_neg_offset(){
        let timestamp = 1724738458;
        let weather = calculate_forecast("Middle La Noscea", timestamp, -1);
        assert_eq!(weather.weather, Weather::Wind);
        assert_eq!(weather.start_time, 1724737023);
        assert_eq!(weather.end_time, 1724738403);
        assert_eq!(weather.zone_name, "Middle La Noscea");
    }

    #[test]
    fn test_calculate_forecast_zero_offset(){
        let timestamp = 1724738458;
        let weather = calculate_forecast("Middle La Noscea", timestamp, 0);
        assert_eq!(weather.weather, Weather::Wind);
        assert_eq!(weather.start_time, 1724738403);
        assert_eq!(weather.end_time, 1724739802);
        assert_eq!(weather.zone_name, "Middle La Noscea");
    }

    #[test]
    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);
        assert_eq!(weather.start_time, 1724742543);
        assert_eq!(weather.end_time, 1724743923);
        assert_eq!(weather.zone_name, "Eureka Pagos");
    }

    #[test]
    fn test_convert_weather_enum_to_string(){
        let weather_variants = vec![
            (Weather::AstroMagneticStorm, "Astro-Magnetic Storms"),
            (Weather::Blizzards, "Blizzards"),
            (Weather::ClearSkies, "Clear Skies"),
            (Weather::Clouds, "Clouds"),
            (Weather::DustStorms, "Dust Storms"),
            (Weather::FairSkies, "Fair Skies"),
            (Weather::Fog, "Fog"),
            (Weather::Gales, "Gales"),
            (Weather::Gloom, "Gloom"),
            (Weather::HeatWaves, "Heat Waves"),
            (Weather::MoonDust, "Moon Dust"),
            (Weather::Rain, "Rain"),
            (Weather::Showers, "Showers"),
            (Weather::Snow, "Snow"),
            (Weather::Thunder, "Thunder"),
            (Weather::Thunderstorms, "Thunderstorms"),
            (Weather::UmbralStatic, "Umbral Static"),
            (Weather::UmbralWind, "Umbral Wind"),
            (Weather::Wind, "Wind"),
        ];

        for (weather, expected_str) in weather_variants {
            assert_eq!(weather.to_string(), expected_str);
        }
    }

    #[test]
    fn test_calculate_current_weather_interval_day_overflow(){
        let (start, end) = 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);
    }



}

send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage