Skip to content

Commit b8889e8

Browse files
authored
Merge pull request #351 from gliptak/coverage12
Add FingerTree tests
2 parents 21a73c4 + 7e149a6 commit b8889e8

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

core/src/test/java/fj/FWFunctionsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.junit.Test;
44

5-
import fj.F1W;
65
import static org.hamcrest.core.Is.is;
76
import static org.junit.Assert.assertThat;
87

props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package fj.data.fingertrees;
22

3+
import fj.Function;
34
import fj.P;
45
import fj.P2;
5-
import fj.Show;
66
import fj.data.List;
7-
import fj.data.Stream;
7+
import fj.data.Option;
88
import org.junit.Test;
99

10-
import static fj.P.p;
11-
import static fj.Show.intShow;
12-
import static fj.test.Property.prop;
13-
import static fj.test.Property.property;
14-
import static java.lang.System.out;
10+
import static fj.Monoid.intAdditionMonoid;
11+
import static fj.Monoid.intMinMonoid;
12+
import static fj.data.fingertrees.FingerTree.measured;
1513
import static org.hamcrest.CoreMatchers.equalTo;
1614
import static org.junit.Assert.assertThat;
15+
import static org.hamcrest.core.Is.is;
16+
1717

1818
/**
1919
* Created by MarkPerry on 10/10/2015.
@@ -24,18 +24,35 @@ public class FingerTreeTest {
2424

2525
@Test
2626
public void size() {
27-
validateSize(List.list(-92, 68, 54, -77, -18, 67));
28-
validateSize(List.list(-92, 68, 54, -77, -18, 67, -60, 23, -70, 99, 66, -79, -5));
27+
validateOperations(List.list(-92, 68, 54, -77, -18, 67));
28+
validateOperations(List.list(-92, 68, 54, -77, -18, 67, -60, 23, -70, 99, 66, -79, -5));
2929
}
3030

31-
void validateSize(List<Integer> list) {
31+
void validateOperations(List<Integer> list) {
3232
FingerTree<Integer, Integer> ft = list.foldLeft(
3333
(acc, i) -> acc.snoc(i), FingerTree.<Integer>emptyIntAddition()
3434
);
3535
assertThat(ft.measure(), equalTo(list.length()));
36+
assertThat(ft.foldLeft((s, i) -> s + 1, 0), equalTo(list.length()));
37+
assertThat(ft.foldRight((i, s) -> 1 + s, 0), equalTo(list.length()));
38+
assertThat(ft.filter(e -> e.equals(-77)).head(), equalTo(-77));
3639
assertThat(ft.length(), equalTo(list.length()));
3740
}
3841

42+
@Test
43+
public void testHeadOption() {
44+
assertThat(Empty.emptyIntAddition().headOption(), is(Option.none()));
45+
FingerTree<Integer, Integer> ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1);
46+
assertThat(ft.headOption(), is(Option.some(1)));
47+
}
48+
49+
@Test
50+
public void testUncons() {
51+
assertThat(Empty.emptyIntAddition().uncons(0, (h, t) -> h), is(0));
52+
FingerTree<Integer, Integer> ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1);
53+
assertThat(ft.uncons(0, (h, t) -> h), is(1));
54+
}
55+
3956
public FingerTree<Integer, Integer> midSeq() {
4057
FingerTree<Integer, Integer> ft = FingerTree.emptyIntAddition();
4158
return List.range(1, SIZE).foldLeft(ft2 -> i -> ft2.snoc(i), ft);

0 commit comments

Comments
 (0)