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