1+ package com .jnape .palatable .lambda .semigroup .builtin ;
2+
3+ import com .jnape .palatable .lambda .functions .Fn1 ;
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+ import testsupport .traits .FiniteIteration ;
10+ import testsupport .traits .InfiniteIterableSupport ;
11+ import testsupport .traits .Laziness ;
12+
13+ import static com .jnape .palatable .lambda .semigroup .builtin .Intersection .intersection ;
14+ import static java .util .Arrays .asList ;
15+ import static java .util .Collections .emptyList ;
16+ import static java .util .Collections .singletonList ;
17+ import static org .junit .Assert .assertThat ;
18+ import static testsupport .matchers .IterableMatcher .isEmpty ;
19+ import static testsupport .matchers .IterableMatcher .iterates ;
20+
21+ @ RunWith (Traits .class )
22+ public class IntersectionTest {
23+
24+ @ TestTraits ({Laziness .class , InfiniteIterableSupport .class , EmptyIterableSupport .class , FiniteIteration .class })
25+ public Fn1 <Iterable <Integer >, Iterable <Integer >> testSubject () {
26+ return intersection (asList (0 , 1 , 2 , 3 ));
27+ }
28+
29+ @ Test
30+ public void intersectionOfEmptyOnEitherSideIsEmpty () {
31+ assertThat (intersection (emptyList (), singletonList (1 )), isEmpty ());
32+ assertThat (intersection (singletonList (1 ), emptyList ()), isEmpty ());
33+ assertThat (intersection (emptyList (), emptyList ()), isEmpty ());
34+ }
35+
36+ @ Test
37+ public void intersectionIsCommonElementsAcrossIterables () {
38+ assertThat (intersection (asList (1 , 2 , 3 ), asList (1 , 2 , 3 )), iterates (1 , 2 , 3 ));
39+ assertThat (intersection (asList (1 , 2 , 3 ), asList (2 , 3 , 4 )), iterates (2 , 3 ));
40+ assertThat (intersection (singletonList (1 ), singletonList (2 )), isEmpty ());
41+ assertThat (intersection (asList (1 , 2 , 3 , 3 ), singletonList (3 )), iterates (3 ));
42+ }
43+ }
0 commit comments