Skip to content

Commit

Permalink
Test combinations_with_replacement counts
Browse files Browse the repository at this point in the history
For a fast test: `n` and `k` are only up to 7.
  • Loading branch information
Philippe-Cholet committed Aug 26, 2023
1 parent b9bc9e5 commit a163451
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,28 @@ fn combinations_with_replacement() {
);
}

#[test]
fn combinations_with_replacement_range_count() {
for n in 0..=7 {
for k in 0..=7 {
let len = binomial(usize::saturating_sub(n + k, 1), k);
let mut it = (0..n).combinations_with_replacement(k);
assert_eq!(len, it.clone().count());
assert_eq!(len, it.size_hint().0);
assert_eq!(Some(len), it.size_hint().1);
for count in (0..len).rev() {
let elem = it.next();
assert!(elem.is_some());
assert_eq!(count, it.clone().count());
assert_eq!(count, it.size_hint().0);
assert_eq!(Some(count), it.size_hint().1);
}
let should_be_none = it.next();
assert!(should_be_none.is_none());
}
}
}

#[test]
fn powerset() {
it::assert_equal((0..0).powerset(), vec![vec![]]);
Expand Down

0 comments on commit a163451

Please sign in to comment.