Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Dec 11, 2024
1 parent ea2aab0 commit 1ee211c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion stats/stats/src/charts/types/timespans/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod tests {
}

#[test]
fn month_saturating_arithmetics_works() {
fn month_arithmetics_works() {
assert_eq!(
Month::from_date(d("2015-06-01"))
.saturating_add(TimespanDuration::from_timespan_repeats(3)),
Expand All @@ -231,6 +231,16 @@ mod tests {
.saturating_sub(TimespanDuration::from_timespan_repeats(3)),
Month::from_date(d("2015-03-01"))
);
assert_eq!(
Month::from_date(d("2015-06-01"))
.checked_add(TimespanDuration::from_timespan_repeats(3)),
Some(Month::from_date(d("2015-09-01")))
);
assert_eq!(
Month::from_date(d("2015-06-01"))
.checked_sub(TimespanDuration::from_timespan_repeats(3)),
Some(Month::from_date(d("2015-03-01")))
);

assert_eq!(
Month::from_date(d("2015-06-01"))
Expand All @@ -243,6 +253,17 @@ mod tests {
Month::from_date(NaiveDate::MIN)
);

assert_eq!(
Month::from_date(d("2015-06-01"))
.checked_add(TimespanDuration::from_timespan_repeats(u64::MAX)),
None
);
assert_eq!(
Month::from_date(d("2015-06-01"))
.checked_sub(TimespanDuration::from_timespan_repeats(u64::MAX)),
None
);

assert_eq!(
Month::from_date(NaiveDate::MAX)
.saturating_add(TimespanDuration::from_timespan_repeats(1)),
Expand All @@ -253,6 +274,17 @@ mod tests {
.saturating_sub(TimespanDuration::from_timespan_repeats(1)),
Month::from_date(NaiveDate::MIN)
);

assert_eq!(
Month::from_date(NaiveDate::MAX)
.checked_add(TimespanDuration::from_timespan_repeats(1)),
None
);
assert_eq!(
Month::from_date(NaiveDate::MIN)
.checked_sub(TimespanDuration::from_timespan_repeats(1)),
None
);
}

#[test]
Expand Down

0 comments on commit 1ee211c

Please sign in to comment.