1
Fork 0

Step::replace_one should put a one, not a zero (Issue #41492)

Turns out all six of these impls are incorrect.
This commit is contained in:
Scott McMurray 2017-04-23 21:47:09 -07:00
parent 252d3da8a6
commit f8c6436173
3 changed files with 46 additions and 6 deletions

View file

@ -1082,3 +1082,41 @@ fn test_chain_fold() {
assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
}
#[test]
fn test_step_replace_unsigned() {
let mut x = 4u32;
let y = x.replace_zero();
assert_eq!(x, 0);
assert_eq!(y, 4);
x = 5;
let y = x.replace_one();
assert_eq!(x, 1);
assert_eq!(y, 5);
}
#[test]
fn test_step_replace_signed() {
let mut x = 4i32;
let y = x.replace_zero();
assert_eq!(x, 0);
assert_eq!(y, 4);
x = 5;
let y = x.replace_one();
assert_eq!(x, 1);
assert_eq!(y, 5);
}
#[test]
fn test_step_replace_no_between() {
let mut x = 4u128;
let y = x.replace_zero();
assert_eq!(x, 0);
assert_eq!(y, 4);
x = 5;
let y = x.replace_one();
assert_eq!(x, 1);
assert_eq!(y, 5);
}