From d6492ede69d5dc001ef90f94528e1bf222c52c4a Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Wed, 4 Dec 2024 23:00:05 +0000 Subject: Tests first_day_in_month() methods --- rust/schist_models/src/date_utc.rs | 173 +++++++++++++++++++++++++++++++++++-- 1 file changed, 166 insertions(+), 7 deletions(-) (limited to 'rust/schist_models') diff --git a/rust/schist_models/src/date_utc.rs b/rust/schist_models/src/date_utc.rs index d3a1d2e..2b36ec0 100644 --- a/rust/schist_models/src/date_utc.rs +++ b/rust/schist_models/src/date_utc.rs @@ -372,17 +372,176 @@ mod test { } #[test] - fn test_first_day_in_month() { - todo!(); + fn when_any_date_in_2024_then_first_day_in_month_is_correct() { + let jan_1_2024: DateUtc = "2024-01-01".parse().unwrap(); + for date in get_dates_in_jan_2024() { + assert_eq!(jan_1_2024, date.first_day_in_month()); + } + + let feb_1_2024: DateUtc = "2024-02-01".parse().unwrap(); + for date in get_dates_in_feb_2024() { + assert_eq!(feb_1_2024, date.first_day_in_month()); + } + + let mar_1_2024: DateUtc = "2024-03-01".parse().unwrap(); + for date in get_dates_in_mar_2024() { + assert_eq!(mar_1_2024, date.first_day_in_month()); + } + + let apr_1_2024: DateUtc = "2024-04-01".parse().unwrap(); + for date in get_dates_in_apr_2024() { + assert_eq!(apr_1_2024, date.first_day_in_month()); + } + + let may_1_2024: DateUtc = "2024-05-01".parse().unwrap(); + for date in get_dates_in_may_2024() { + assert_eq!(may_1_2024, date.first_day_in_month()); + } + + let jun_1_2024: DateUtc = "2024-06-01".parse().unwrap(); + for date in get_dates_in_jun_2024() { + assert_eq!(jun_1_2024, date.first_day_in_month()); + } + + let jul_1_2024: DateUtc = "2024-07-01".parse().unwrap(); + for date in get_dates_in_jul_2024() { + assert_eq!(jul_1_2024, date.first_day_in_month()); + } + + let aug_1_2024: DateUtc = "2024-08-01".parse().unwrap(); + for date in get_dates_in_aug_2024() { + assert_eq!(aug_1_2024, date.first_day_in_month()); + } + + let sep_1_2024: DateUtc = "2024-09-01".parse().unwrap(); + for date in get_dates_in_sep_2024() { + assert_eq!(sep_1_2024, date.first_day_in_month()); + } + + let oct_1_2024: DateUtc = "2024-10-01".parse().unwrap(); + for date in get_dates_in_oct_2024() { + assert_eq!(oct_1_2024, date.first_day_in_month()); + } + + let nov_1_2024: DateUtc = "2024-11-01".parse().unwrap(); + for date in get_dates_in_nov_2024() { + assert_eq!(nov_1_2024, date.first_day_in_month()); + } + + let dec_1_2024: DateUtc = "2024-12-01".parse().unwrap(); + for date in get_dates_in_dec_2024() { + assert_eq!(dec_1_2024, date.first_day_in_month()); + } } #[test] - fn test_first_day_in_next_month() { - todo!(); + fn when_any_date_in_2024_then_first_day_in_next_month_is_correct() { + let feb_1_2024: DateUtc = "2024-02-01".parse().unwrap(); + for date in get_dates_in_jan_2024() { + assert_eq!(feb_1_2024, date.first_day_in_next_month()); + } + + let mar_1_2024: DateUtc = "2024-03-01".parse().unwrap(); + for date in get_dates_in_feb_2024() { + assert_eq!(mar_1_2024, date.first_day_in_next_month()); + } + + let apr_1_2024: DateUtc = "2024-04-01".parse().unwrap(); + for date in get_dates_in_mar_2024() { + assert_eq!(apr_1_2024, date.first_day_in_next_month()); + } + + let may_1_2024: DateUtc = "2024-05-01".parse().unwrap(); + for date in get_dates_in_apr_2024() { + assert_eq!(may_1_2024, date.first_day_in_next_month()); + } + + let jun_1_2024: DateUtc = "2024-06-01".parse().unwrap(); + for date in get_dates_in_may_2024() { + assert_eq!(jun_1_2024, date.first_day_in_next_month()); + } + + let jul_1_2024: DateUtc = "2024-07-01".parse().unwrap(); + for date in get_dates_in_jun_2024() { + assert_eq!(jul_1_2024, date.first_day_in_next_month()); + } + + let aug_1_2024: DateUtc = "2024-08-01".parse().unwrap(); + for date in get_dates_in_jul_2024() { + assert_eq!(aug_1_2024, date.first_day_in_next_month()); + } + + let sep_1_2024: DateUtc = "2024-09-01".parse().unwrap(); + for date in get_dates_in_aug_2024() { + assert_eq!(sep_1_2024, date.first_day_in_next_month()); + } + + let oct_1_2024: DateUtc = "2024-10-01".parse().unwrap(); + for date in get_dates_in_sep_2024() { + assert_eq!(oct_1_2024, date.first_day_in_next_month()); + } + + let nov_1_2024: DateUtc = "2024-11-01".parse().unwrap(); + for date in get_dates_in_oct_2024() { + assert_eq!(nov_1_2024, date.first_day_in_next_month()); + } + + let dec_1_2024: DateUtc = "2024-12-01".parse().unwrap(); + for date in get_dates_in_nov_2024() { + assert_eq!(dec_1_2024, date.first_day_in_next_month()); + } + + let jan_1_2025: DateUtc = "2025-01-01".parse().unwrap(); + for date in get_dates_in_dec_2024() { + assert_eq!(jan_1_2025, date.first_day_in_next_month()); + } } - #[test] - fn test_days_in_month() { - todo!(); + fn get_dates_in_jan_2024() -> Vec { + (1..31).map(|day| format!("2024-01-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_feb_2024() -> Vec { + (1..29).map(|day| format!("2024-02-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_mar_2024() -> Vec { + (1..31).map(|day| format!("2024-03-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_apr_2024() -> Vec { + (1..30).map(|day| format!("2024-04-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_may_2024() -> Vec { + (1..31).map(|day| format!("2024-05-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_jun_2024() -> Vec { + (1..30).map(|day| format!("2024-06-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_jul_2024() -> Vec { + (1..31).map(|day| format!("2024-07-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_aug_2024() -> Vec { + (1..31).map(|day| format!("2024-08-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_sep_2024() -> Vec { + (1..30).map(|day| format!("2024-09-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_oct_2024() -> Vec { + (1..31).map(|day| format!("2024-10-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_nov_2024() -> Vec { + (1..30).map(|day| format!("2024-11-{:02}", day).parse::().unwrap()).collect::>() + } + + fn get_dates_in_dec_2024() -> Vec { + (1..31).map(|day| format!("2024-12-{:02}", day).parse::().unwrap()).collect::>() } } -- cgit v1.2.3