1use itertools::Itertools;
2
3struct PanickingCounter {
4 curr: usize,
5 max: usize,
6}
7
8impl Iterator for PanickingCounter {
9 type Item = ();
10
11 fn next(&mut self) -> Option<Self::Item> {
12 self.curr += 1;
13
14 assert_ne!(
15 self.curr, self.max,
16 "Input iterator reached maximum of {} suggesting collection by adaptor",
17 self.max
18 );
19
20 Some(())
21 }
22}
23
24fn no_collect_test<A, T>(to_adaptor: T)
25 where A: Iterator, T: Fn(PanickingCounter) -> A
26{
27 let counter = PanickingCounter { curr: 0, max: 10_000 };
28 let adaptor = to_adaptor(counter);
29
30 for _ in adaptor.take(5) {}
31}
32
33#[test]
34fn permutations_no_collect() {
35 no_collect_test(|iter| iter.permutations(5))
36}
37
38#[test]
39fn combinations_no_collect() {
40 no_collect_test(|iter| iter.combinations(5))
41}
42
43#[test]
44fn combinations_with_replacement_no_collect() {
45 no_collect_test(|iter| iter.combinations_with_replacement(5))
46}