Skip to content

Commit 1bb3739

Browse files
committed
exact size tests
1 parent 14f004d commit 1bb3739

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/array_chunks.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,34 @@ impl<I: Iterator, const N: usize> Iterator for ArrayChunks<I, N> {
8585
}
8686

8787
impl<I: ExactSizeIterator, const N: usize> ExactSizeIterator for ArrayChunks<I, N> {}
88+
89+
#[cfg(test)]
90+
mod tests {
91+
use crate::Itertools;
92+
93+
fn exact_size_helper(it: impl Iterator) {
94+
let (lo, hi) = it.size_hint();
95+
let count = it.count();
96+
assert_eq!(lo, count);
97+
assert_eq!(hi, Some(count));
98+
}
99+
100+
#[test]
101+
fn exact_size_not_divisible() {
102+
let it = (0..10).array_chunks::<3>();
103+
exact_size_helper(it);
104+
}
105+
106+
#[test]
107+
fn exact_size_after_next() {
108+
let mut it = (0..10).array_chunks::<3>();
109+
_ = it.next();
110+
exact_size_helper(it);
111+
}
112+
113+
#[test]
114+
fn exact_size_divisible() {
115+
let it = (0..10).array_chunks::<5>();
116+
exact_size_helper(it);
117+
}
118+
}

0 commit comments

Comments
 (0)