Skip to content

Commit

Permalink
value stability: test seq::IteratorRandom::choose_multiple / fill
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 14, 2020
1 parent dd4ee1a commit a7a8cdc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/seq/mod.rs
Expand Up @@ -893,4 +893,30 @@ mod test {
Some(90)
);
}

#[test]
fn value_stability_choose_multiple() {
fn do_test<I: Iterator<Item = u32>>(iter: I, v: &[u32]) {
let mut rng = crate::test::rng(412);
let mut buf = [0u32; 8];
assert_eq!(iter.choose_multiple_fill(&mut rng, &mut buf), v.len());
assert_eq!(&buf[0..v.len()], v);
}

do_test(0..4, &[0, 1, 2, 3]);
do_test(0..8, &[0, 1, 2, 3, 4, 5, 6, 7]);
do_test(0..100, &[58, 78, 80, 92, 43, 8, 96, 7]);

#[cfg(feature = "alloc")]
{
fn do_test<I: Iterator<Item = u32>>(iter: I, v: &[u32]) {
let mut rng = crate::test::rng(412);
assert_eq!(iter.choose_multiple(&mut rng, v.len()), v);
}

do_test(0..4, &[0, 1, 2, 3]);
do_test(0..8, &[0, 1, 2, 3, 4, 5, 6, 7]);
do_test(0..100, &[58, 78, 80, 92, 43, 8, 96, 7]);
}
}
}

0 comments on commit a7a8cdc

Please sign in to comment.