Skip to content

Commit

Permalink
Add quickcheck tests for PeekNth.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Jul 26, 2023
1 parent 9c62bf0 commit dea774b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,32 @@ quickcheck! {
}
}

quickcheck! {
fn correct_peek_nth(mut a: Vec<u16>) -> () {
let mut it = peek_nth(a.clone());
for start_pos in 0..a.len() + 2 {
for real_idx in start_pos..a.len() + 2 {
let peek_idx = real_idx - start_pos;
assert_eq!(it.peek_nth(peek_idx), a.get(real_idx));
assert_eq!(it.peek_nth_mut(peek_idx), a.get_mut(real_idx));
}
assert_eq!(it.next(), a.get(start_pos).copied());
}
}

fn peek_nth_mut_replace(a: Vec<u16>, b: Vec<u16>) -> () {
let mut it = peek_nth(a.iter());
for i in 0..a.len().min(b.len()) {
*it.peek_nth_mut(i).unwrap() = &b[i];
}
for i in 0..a.len() {
assert_eq!(it.next().unwrap(), b.get(i).unwrap_or(&a[i]));
}
assert_eq!(it.next(), None);
assert_eq!(it.next(), None);
}
}

quickcheck! {
fn dedup_via_coalesce(a: Vec<i32>) -> bool {
let mut b = a.clone();
Expand Down

0 comments on commit dea774b

Please sign in to comment.