Skip to content

Commit

Permalink
Test negative factors.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielparks committed Mar 16, 2024
1 parent cdd9494 commit f18b70f
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ mod tests {

#[test]
fn round_small_signed_integer() {
// FIXME: what if factor is negative?
check!(10 == 10i8.round_to(1));

check!(0 == 0i8.round_to(2));
Expand Down Expand Up @@ -263,9 +262,20 @@ mod tests {
check!(0 == (i32::MIN / 2 + 1).round_to(i32::MAX));
}

#[test]
#[should_panic(expected = "try_round_to() requires positive factor")]
fn round_integer_zero_factor() {
let _ = 0.round_to(0);
}

#[test]
#[should_panic(expected = "try_round_to() requires positive factor")]
fn round_integer_negative_factor() {
let _ = 0.round_to(-1);
}

#[test]
fn round_small_float() {
// FIXME: what if factor is negative?
check!(10.0 == 10.0.round_to(1.0));

check!(0.0 == 0.0.round_to(2.0));
Expand Down Expand Up @@ -317,4 +327,16 @@ mod tests {
check!(0.0 == (f32::MIN * 0.5).round_to(f32::MAX));
check!(-f32::MAX == (f32::MIN * 0.6).round_to(f32::MAX));
}

#[test]
#[should_panic(expected = "try_round_to() requires positive factor")]
fn round_float_zero_factor() {
let _ = 0.0.round_to(0.0);
}

#[test]
#[should_panic(expected = "try_round_to() requires positive factor")]
fn round_float_negative_factor() {
let _ = 0.0.round_to(-1.0);
}
}

0 comments on commit f18b70f

Please sign in to comment.