Skip to content

Commit

Permalink
value stability: test seq::IteratorRandom::choose
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 14, 2020
1 parent 65c3766 commit dd4ee1a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/seq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,50 @@ mod test {
Err(WeightedError::InvalidWeight)
);
}

#[test]
fn value_stability_choose() {
fn choose<I: Iterator<Item = u32>>(iter: I) -> Option<u32> {
let mut rng = crate::test::rng(411);
iter.choose(&mut rng)
}

assert_eq!(choose([].iter().cloned()), None);
assert_eq!(choose(0..100), Some(33));
assert_eq!(choose(UnhintedIterator { iter: 0..100 }), Some(76));
assert_eq!(
choose(ChunkHintedIterator {
iter: 0..100,
chunk_size: 32,
chunk_remaining: 32,
hint_total_size: false,
}),
Some(39)
);
assert_eq!(
choose(ChunkHintedIterator {
iter: 0..100,
chunk_size: 32,
chunk_remaining: 32,
hint_total_size: true,
}),
Some(39)
);
assert_eq!(
choose(WindowHintedIterator {
iter: 0..100,
window_size: 32,
hint_total_size: false,
}),
Some(90)
);
assert_eq!(
choose(WindowHintedIterator {
iter: 0..100,
window_size: 32,
hint_total_size: true,
}),
Some(90)
);
}
}

0 comments on commit dd4ee1a

Please sign in to comment.