Skip to content

Commit

Permalink
Switch to parametrized tests with test_case
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-LAURENT39 committed Feb 12, 2024
1 parent a074c0c commit e288e5a
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,33 @@ mod tests {
);
}

#[test]
fn test_find_prev_next_occurences() {
// Test case 1: Birthday is same day as date
let date1 = NaiveDate::from_ymd_opt(2024, 2, 6).unwrap();
assert_eq!(find_prev_next_occurences(6, 2, date1), None);

// Test case 2: Birthday already happened this year
let date2 = NaiveDate::from_ymd_opt(2024, 2, 2).unwrap();
let expected2 = (
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
);
assert_eq!(find_prev_next_occurences(1, 1, date2), Some(expected2));

// Test case 3: Birthday hasn't happened yet this year
let date3 = NaiveDate::from_ymd_opt(2024, 5, 5).unwrap();
let expected3 = (
#[test_case(6, 2,
NaiveDate::from_ymd_opt(2024, 2, 6).unwrap(),
None ;
"Birthday is same day as date")]
#[test_case(1, 1,
NaiveDate::from_ymd_opt(2024, 2, 2).unwrap(),
Some((
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
)) ;
"Birthday already happened this year")]
#[test_case(6, 6,
NaiveDate::from_ymd_opt(2024, 5, 5).unwrap(),
Some((
NaiveDate::from_ymd_opt(2023, 6, 6).unwrap(),
NaiveDate::from_ymd_opt(2024, 6, 6).unwrap(),
)) ;
"Birthday hasn't happened yet this year")]
fn test_find_prev_next_occurences(
birthday_day: u32,
birthday_month: u32,
date: NaiveDate,
expected: Option<(NaiveDate, NaiveDate)>,
) {
assert_eq!(
find_prev_next_occurences(birthday_day, birthday_month, date),
expected
);
assert_eq!(find_prev_next_occurences(6, 6, date3), Some(expected3));
}
}

0 comments on commit e288e5a

Please sign in to comment.