Add integer overflow tests to Clock in Rust

One of the key reasons people learn Rust is because they want to write code that doesn’t fail at runtime. Exercism problems should reflect this desire by teaching students how to write Rust that can’t panic at runtime. The Clock in Rust exercise, in this case, has a weakness – you can pass all the tests and still have code that panics at runtim if too large of an integer is passed into the clock. I propose adding a set of integer overflow tests to make sure the exercise can’t be passed without accounting for this possibility.

The following are my proposed additions:

//
// Test Overflow
//

#[test]
fn positive_overflow_hours() {
    Clock::new(i32::MAX, 0);
}

#[test]
fn negative_overflow_hours() {
    Clock::new(i32::MIN, 0);
}

#[test]
fn positive_overflow_minutes() {
    Clock::new(23, i32::MAX);
}

#[test]
fn negative_overflow_minutes() {
    Clock::new(23, i32::MIN);
}

#[test]
fn positive_overflow_minutes_hours() {
    Clock::new(i32::MAX, i32::MAX);
}

#[test]
fn negative_overflow_minutes_hours() {
    Clock::new(i32::MIN, i32::MIN);
}

#[test]
fn positive_overflow_add_minutes() {
    let clock = Clock::new(i32::MAX, i32::MAX);
    clock.add_minutes(i32::MAX);
}

#[test]
fn negative_overflow_add_minutes() {
    let clock = Clock::new(i32::MIN, i32::MIN);
    clock.add_minutes(i32::MIN);
}

Thanks for your suggestion. This exercise and its tests are derived from problem-specifications. It might be considered to add them there. It is possible to add tests just for the Rust track, but only with good reason.

My personal opinion is that this may not match up with what the exercise is trying to teach. Adding all kinds of error handling and edge cases to every exercise can dilute them. I would prefer having a separate exercise about overflow which just focuses on that - maybe it already exists, I’m not sure.

If you think these tests should be added to all languages, consider posting this in the general exercism category.