Skip to content

Commit 68828d3

Browse files
committed
create tests for set monoid fabric methods
1 parent 0083c80 commit 68828d3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

core/src/test/java/fj/MonoidTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fj;
22

3+
import fj.data.Enumerator;
34
import fj.data.Option;
5+
import fj.data.Set;
46
import fj.data.Stream;
57
import org.junit.Test;
68

@@ -16,4 +18,26 @@ public void lifted_sum_of_two_numbers() {
1618
assertThat(optionMonoid.sum(some(3), some(5)), is(some(8)));
1719
assertThat(optionMonoid.sumLeft(Stream.arrayStream(some(3), some(5))), is(some(8)));
1820
}
21+
22+
@Test
23+
public void intersection_monoid_test() {
24+
Bounded<Integer> integersBounded = Bounded.bounded(0, 10);
25+
Monoid<Set<Integer>> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd);
26+
Set<Integer> first = Set.set(Ord.intOrd, 1, 2, 3, 4);
27+
Set<Integer> second = Set.set(Ord.intOrd, 3, 4, 5, 6);
28+
Set<Integer> zero = intersectionMonoid.zero();
29+
Set<Integer> actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second);
30+
assertThat(actual, is(Set.set(Ord.intOrd, 3, 4)));
31+
}
32+
33+
@Test
34+
public void union_monoid_test() {
35+
Monoid<Set<Integer>> intersectionMonoid = Monoid.setMonoid(Ord.intOrd);
36+
Set<Integer> first = Set.set(Ord.intOrd, 1, 2, 3, 4);
37+
Set<Integer> second = Set.set(Ord.intOrd, 3, 4, 5, 6);
38+
Set<Integer> zero = intersectionMonoid.zero();
39+
Set<Integer> actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second);
40+
assertThat(actual, is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6)));
41+
}
42+
1943
}

0 commit comments

Comments
 (0)