1+ package com .jnape .palatable .lambda .iterators ;
2+
3+ import org .junit .Test ;
4+
5+ import java .util .NoSuchElementException ;
6+
7+ import static java .util .Arrays .asList ;
8+ import static java .util .Collections .emptyIterator ;
9+ import static org .hamcrest .MatcherAssert .assertThat ;
10+ import static org .hamcrest .core .Is .is ;
11+
12+ public class ScanningIteratorTest {
13+
14+ public static final com .jnape .palatable .lambda .functions .DyadicFunction <Integer , Integer , Integer > ADD = (x , y ) -> x + y ;
15+
16+ @ Test
17+ public void hasNextAtLeastForB () {
18+ ScanningIterator <Integer , Integer > scanningIterator = new ScanningIterator <>(ADD , 0 , emptyIterator ());
19+ assertThat (scanningIterator .hasNext (), is (true ));
20+ }
21+
22+ @ Test
23+ public void nextIsTrueAtLeastForB () {
24+ ScanningIterator <Integer , Integer > scanningIterator = new ScanningIterator <>(ADD , 0 , emptyIterator ());
25+ assertThat (scanningIterator .next (), is (0 ));
26+ }
27+
28+ @ Test
29+ public void iteratesAsAfterB () {
30+ ScanningIterator <Integer , Integer > scanningIterator = new ScanningIterator <>(ADD , 0 , asList (1 , 2 , 3 , 4 , 5 ).iterator ());
31+
32+ scanningIterator .next ();
33+ assertThat (scanningIterator .hasNext (), is (true ));
34+ assertThat (scanningIterator .next (), is (ADD .apply (0 , 1 )));
35+ }
36+
37+ @ Test (expected = NoSuchElementException .class )
38+ public void failsOnNextIfOutOfAs () {
39+ ScanningIterator <Integer , Integer > scanningIterator = new ScanningIterator <>(ADD , 0 , emptyIterator ());
40+ scanningIterator .next ();
41+ scanningIterator .next ();
42+ }
43+ }
0 commit comments