1+ package com .jnape .palatable .lambda .functions .builtin .fn1 ;
2+
3+ import com .jnape .palatable .lambda .adt .hlist .Tuple2 ;
4+ import com .jnape .palatable .traitor .annotations .TestTraits ;
5+ import com .jnape .palatable .traitor .runners .Traits ;
6+ import org .junit .Test ;
7+ import org .junit .runner .RunWith ;
8+ import testsupport .traits .EmptyIterableSupport ;
9+
10+ import java .util .Optional ;
11+
12+ import static com .jnape .palatable .lambda .functions .builtin .fn1 .Uncons .uncons ;
13+ import static java .util .Arrays .asList ;
14+ import static java .util .Collections .emptyList ;
15+ import static org .junit .Assert .assertEquals ;
16+ import static org .junit .Assert .assertThat ;
17+ import static testsupport .matchers .IterableMatcher .iterates ;
18+
19+ @ RunWith (Traits .class )
20+ public class UnconsTest {
21+
22+ @ TestTraits ({EmptyIterableSupport .class })
23+ public Uncons testSubject () {
24+ return uncons ();
25+ }
26+
27+ @ Test
28+ public void nonEmptyIterable () {
29+ Iterable <Integer > numbers = asList (1 , 2 , 3 );
30+ Tuple2 <Integer , Iterable <Integer >> headAndTail = uncons (numbers ).orElseThrow (AssertionError ::new );
31+
32+ assertEquals ((Integer ) 1 , headAndTail ._1 ());
33+ assertThat (headAndTail ._2 (), iterates (2 , 3 ));
34+ }
35+
36+ @ Test
37+ public void emptyIterable () {
38+ assertEquals (Optional .empty (), uncons (emptyList ()));
39+ }
40+ }
0 commit comments