diff --git a/leap/src/lib.rs b/leap/src/lib.rs index fb1ecbc..59ed187 100644 --- a/leap/src/lib.rs +++ b/leap/src/lib.rs @@ -1,3 +1,3 @@ pub fn is_leap_year(year: u64) -> bool { - unimplemented!("true if {} is a leap year", year) + (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 } diff --git a/leap/tests/leap.rs b/leap/tests/leap.rs index a8a69a4..15451ac 100644 --- a/leap/tests/leap.rs +++ b/leap/tests/leap.rs @@ -8,61 +8,51 @@ fn test_year_not_divisible_by_4_common_year() { } #[test] -#[ignore] fn test_year_divisible_by_2_not_divisible_by_4_in_common_year() { process_leapyear_case(1970, false); } #[test] -#[ignore] fn test_year_divisible_by_4_not_divisible_by_100_leap_year() { process_leapyear_case(1996, true); } #[test] -#[ignore] fn test_year_divisible_by_4_and_5_is_still_a_leap_year() { process_leapyear_case(1960, true); } #[test] -#[ignore] fn test_year_divisible_by_100_not_divisible_by_400_common_year() { process_leapyear_case(2100, false); } #[test] -#[ignore] fn test_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year() { process_leapyear_case(1900, false); } #[test] -#[ignore] fn test_year_divisible_by_400_leap_year() { process_leapyear_case(2000, true); } #[test] -#[ignore] fn test_year_divisible_by_400_but_not_by_125_is_still_a_leap_year() { process_leapyear_case(2400, true); } #[test] -#[ignore] fn test_year_divisible_by_200_not_divisible_by_400_common_year() { process_leapyear_case(1800, false); } #[test] -#[ignore] fn test_any_old_year() { process_leapyear_case(1997, false); } #[test] -#[ignore] fn test_early_years() { process_leapyear_case(1, false); process_leapyear_case(4, true); @@ -72,7 +62,6 @@ fn test_early_years() { } #[test] -#[ignore] fn test_century() { process_leapyear_case(1700, false); process_leapyear_case(1800, false); @@ -80,7 +69,6 @@ fn test_century() { } #[test] -#[ignore] fn test_exceptional_centuries() { process_leapyear_case(1600, true); process_leapyear_case(2000, true); @@ -88,7 +76,6 @@ fn test_exceptional_centuries() { } #[test] -#[ignore] fn test_years_1600_to_1699() { let incorrect_years = (1600..1700) .filter(|&year| leap::is_leap_year(year) != (year % 4 == 0))