I built an iterator that generates an infinite list of primes. The types look like this:
pub struct Primes { … }
impl Iterator for Primes {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> { … }
}
Now I want to test if my iterator returns the correct values by comparing the first 100 values against the correct ones:
#[test]
fn first_thousand() {
assert_eq!(
Primes::new().take(100),
first_100_primes
);
}
const first_100_primes: [u32; 100] = [2, 3, …, 541];
I do not know how to compare these values. I tried creating a slice (first_100_primes[..]
), collecting the iterator values, but I don't seem to be able to compare them.