blob: a47f906f9f2821a9a1010d6a95c9a0e0b5888f28 [file] [log] [blame]
Jakub Kotura425e552020-12-21 17:28:15 +01001use 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 if self.curr == self.max {
15 panic!(
16 "Input iterator reached maximum of {} suggesting collection by adaptor",
17 self.max
18 );
19 }
20
21 Some(())
22 }
23}
24
25fn no_collect_test<A, T>(to_adaptor: T)
26 where A: Iterator, T: Fn(PanickingCounter) -> A
27{
28 let counter = PanickingCounter { curr: 0, max: 10_000 };
29 let adaptor = to_adaptor(counter);
30
31 for _ in adaptor.take(5) {}
32}
33
34#[test]
35fn permutations_no_collect() {
36 no_collect_test(|iter| iter.permutations(5))
37}
38
39#[test]
40fn combinations_no_collect() {
41 no_collect_test(|iter| iter.combinations(5))
42}
43
44#[test]
45fn combinations_with_replacement_no_collect() {
46 no_collect_test(|iter| iter.combinations_with_replacement(5))
47}