Skip to content

leap: Updated exercise to 1.4.0 version #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/leap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[package]
name = "leap"
version = "1.0.0"
version = "1.4.0"
2 changes: 1 addition & 1 deletion exercises/leap/example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn is_leap_year(year: i32) -> bool {
pub fn is_leap_year(year: u64) -> bool {
let has_factor = |n| year % n == 0;
has_factor(4) && (!has_factor(100) || has_factor(400))
}
2 changes: 1 addition & 1 deletion exercises/leap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn is_leap_year(year: i32) -> bool {
pub fn is_leap_year(year: u64) -> bool {
unimplemented!("true if {} is a leap year", year)
}
32 changes: 30 additions & 2 deletions exercises/leap/tests/leap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
extern crate leap;

fn process_leapyear_case(year: u64, expected: bool) {
assert_eq!(leap::is_leap_year(year), expected);
}

#[test]
fn test_year_divisible_by_4_not_divisible_by_100_leap_year() {
process_leapyear_case(1996, true);
}

#[test]
#[ignore]
fn test_year_not_divisible_by_4_common_year() {
process_leapyear_case(2015, false);
}

#[test]
fn test_vanilla_leap_year() {
assert_eq!(leap::is_leap_year(1996), true);
#[ignore]
fn test_year_divisible_by_200_not_divisible_by_400_common_year() {
process_leapyear_case(1800, false);
}

#[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_400_leap_year() {
process_leapyear_case(2000, true);
}

#[test]
Expand Down