mardi 17 décembre 2019

How do I compare iterators?

I want to compare to iterators in a test case. Unfortunately, assert_eq! does not like to be passed iterators. One workaround looks like this:

    let mut a = 0..5;
    let mut b = 0..6;

    assert!(a.by_ref().zip(b.by_ref()).all(|(a, b)| a == b));
    assert_eq!(a.next(), None);
    assert_eq!(b.next(), None);

But it requires 3 (or at least) 2 lines for the test and the iterator needs to be made mutable. Is there anything better?

Aucun commentaire:

Enregistrer un commentaire