Skip to content

Commit 0cf8f9d

Browse files
committed
fixing test for andAll
1 parent 75bec13 commit 0cf8f9d

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package fj.data;
2+
3+
import fj.F;
4+
import fj.function.Booleans;
5+
import fj.test.Property;
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
import static fj.P1.curry;
10+
import static fj.data.List.list;
11+
import static fj.function.Booleans.isnot;
12+
import static org.hamcrest.core.Is.is;
13+
14+
/**
15+
* Created by amar on 28/01/15.
16+
*/
17+
public class BooleansTest {
18+
19+
@Test
20+
public void testAnd(){
21+
F<String, Boolean> f1 = a -> a.startsWith("fj");
22+
F<String, Boolean> f2 = a -> a.contains("data");
23+
24+
F<String, Boolean> f3 = Booleans.and(f1, f2);
25+
26+
Assert.assertTrue(f3.f("fj.data"));
27+
Assert.assertTrue(f3.f("fj.data.Function"));
28+
29+
}
30+
31+
@Test
32+
public void testOr(){
33+
F<String, Boolean> f1 = a -> a.startsWith("fj");
34+
F<String, Boolean> f2 = a -> a.startsWith("someOtherPackage");
35+
36+
F<String, Boolean> f3 = Booleans.or(f1, f2);
37+
38+
Assert.assertTrue(f3.f("fj.data"));
39+
Assert.assertTrue(f3.f("someOtherPackage.fj.data"));
40+
Assert.assertFalse(f3.f("something.fj.data.Function"));
41+
42+
}
43+
44+
@Test
45+
public void testComap(){
46+
F<String, Boolean> f1 = a -> a.length() > 3;
47+
F<Integer, String> f2 = a -> a.toString();
48+
49+
F<Integer, Boolean> f3 = Booleans.contramap(f2, f1);
50+
51+
Assert.assertTrue(f3.f(1000));
52+
Assert.assertFalse(f3.f(100));
53+
54+
}
55+
56+
@SuppressWarnings("unchecked")
57+
@Test
58+
public void testAndAll(){
59+
F<String, Boolean> f1 = a -> a.endsWith("fj");
60+
F<String, Boolean> f2 = a -> a.startsWith("someOtherPackage");
61+
F<String, Boolean> f3 = a -> a.length() < 20;
62+
63+
F<String, Boolean> f4 = Booleans.andAll(Stream.<F<String, Boolean>>stream(f1, f2, f3));
64+
65+
Assert.assertTrue(f4.f("someOtherPackage.fj"));
66+
Assert.assertFalse(f4.f("otther"));
67+
Assert.assertFalse(f4.f("someOtherPackage.fj.data.something.really.big"));
68+
69+
}
70+
71+
@SuppressWarnings("unchecked")
72+
@Test
73+
public void testIsNot(){
74+
F<Integer, Boolean> f1 = a -> a == 4;
75+
List<String> result = list("some", "come", "done!").filter(isnot(String::length, f1));
76+
77+
Assert.assertThat(result.length(), is(1));
78+
Assert.assertEquals(result, list("done!"));
79+
80+
}
81+
}

0 commit comments

Comments
 (0)