• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use itertools::Itertools;
2 
3 struct PanickingCounter {
4     curr: usize,
5     max: usize,
6 }
7 
8 impl Iterator for PanickingCounter {
9     type Item = ();
10 
next(&mut self) -> Option<Self::Item>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 
no_collect_test<A, T>(to_adaptor: T) where A: Iterator, T: Fn(PanickingCounter) -> A,24 fn no_collect_test<A, T>(to_adaptor: T)
25 where
26     A: Iterator,
27     T: Fn(PanickingCounter) -> A,
28 {
29     let counter = PanickingCounter {
30         curr: 0,
31         max: 10_000,
32     };
33     let adaptor = to_adaptor(counter);
34 
35     for _ in adaptor.take(5) {}
36 }
37 
38 #[test]
permutations_no_collect()39 fn permutations_no_collect() {
40     no_collect_test(|iter| iter.permutations(5))
41 }
42 
43 #[test]
combinations_no_collect()44 fn combinations_no_collect() {
45     no_collect_test(|iter| iter.combinations(5))
46 }
47 
48 #[test]
combinations_with_replacement_no_collect()49 fn combinations_with_replacement_no_collect() {
50     no_collect_test(|iter| iter.combinations_with_replacement(5))
51 }
52