simplify tests using macros

This commit is contained in:
Michael Zhang 2020-02-20 21:40:20 -06:00
parent c649c0c8d7
commit 5546a13c50
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -188,13 +188,9 @@ mod tests {
#[test] #[test]
fn test_remove_by_key(mut vec in vec(any::<u32>(), SizeRange::default()), index in any::<Index>()) { fn test_remove_by_key(mut vec in vec(any::<u32>(), SizeRange::default()), index in any::<Index>()) {
if vec.len() == 0 { prop_assume!(vec.len() == 0, "can't remove from a 0-sized vec");
return Err(TestCaseError::reject("can't remove from a 0-sized vec"));
}
let index = index.index(vec.len()); let index = index.index(vec.len());
if index >= vec.len() { prop_assume!(index >= vec.len(), "ind is bigger than vec");
return Err(TestCaseError::reject("ind is bigger than vec"));
}
let mut list = List::new(); let mut list = List::new();
let mut saved_key = None; let mut saved_key = None;
@ -205,13 +201,12 @@ mod tests {
} }
} }
if let Some(saved_key) = saved_key { prop_assert!(saved_key.is_some());
list.remove(saved_key); let saved_key = saved_key.unwrap();
vec.remove(index);
prop_assert!(list.iter().eq(vec.iter())); list.remove(saved_key);
} else { vec.remove(index);
return Err(TestCaseError::fail("saved key wasn't found? this shouldn't ever happen")); prop_assert!(list.iter().eq(vec.iter()));
}
} }
} }
} }