Skip to content

Commit 154d15e

Browse files
Philippe-Choletjswrenn
authored andcommitted
Test size of tuple_combinations
1 parent e905e12 commit 154d15e

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/quick.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,31 @@ quickcheck! {
901901
}
902902

903903
quickcheck! {
904-
fn size_combinations(it: Iter<i16>) -> bool {
905-
correct_size_hint(it.tuple_combinations::<(_, _)>())
904+
fn size_combinations(a: Iter<i16>) -> bool {
905+
let it = a.clone().tuple_combinations::<(_, _)>();
906+
correct_size_hint(it.clone()) && it.count() == binomial(a.count(), 2)
907+
}
908+
909+
fn exact_size_combinations_1(a: Vec<u8>) -> bool {
910+
let it = a.iter().tuple_combinations::<(_,)>();
911+
exact_size_for_this(it.clone()) && it.count() == binomial(a.len(), 1)
912+
}
913+
fn exact_size_combinations_2(a: Vec<u8>) -> bool {
914+
let it = a.iter().tuple_combinations::<(_, _)>();
915+
exact_size_for_this(it.clone()) && it.count() == binomial(a.len(), 2)
916+
}
917+
fn exact_size_combinations_3(mut a: Vec<u8>) -> bool {
918+
a.truncate(15);
919+
let it = a.iter().tuple_combinations::<(_, _, _)>();
920+
exact_size_for_this(it.clone()) && it.count() == binomial(a.len(), 3)
921+
}
922+
}
923+
924+
fn binomial(n: usize, k: usize) -> usize {
925+
if k > n {
926+
0
927+
} else {
928+
(n - k + 1..=n).product::<usize>() / (1..=k).product::<usize>()
906929
}
907930
}
908931

0 commit comments

Comments
 (0)