Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/src/main/java/fj/F8Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ private F8Functions() {
/**
* Partial application.
*
* @param a The <code>A</code> to which to apply this function.
* @return The function partially applied to the given argument.
*/
public static <A, B, C, D, E, F$, G, H, I> F7<B, C, D, E, F$, G, H, I> f(final F8<A, B, C, D, E, F$, G, H, I> func, final A a) {
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/java/fj/DigitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fj;

import fj.data.Option;
import org.junit.Test;

import static fj.data.Array.range;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class DigitTest {
@Test
public void testInteger() {
for (Integer i: range(0, 10)) {
assertThat(Digit.fromLong(i).toLong(), is(i.longValue()));
}
}

@Test
public void testChar() {
for (Integer i: range(0, 10)) {
Character c = Character.forDigit(i, 10);
assertThat(Digit.fromChar(c).some().toChar(), is(c));
}
}

@Test
public void testCharNone() {
assertThat(Digit.fromChar('x'), is(Option.none()));
}
}
25 changes: 25 additions & 0 deletions core/src/test/java/fj/FFunctionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fj;

import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

public class FFunctionsTest {
@Test
public void testApply() {
F8<Integer, Integer, Integer, Integer,
Integer, Integer, Integer, Integer, Integer> f8 =
(i1, i2, i3, i4, i5, i6, i7, i8) ->
i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
F7<Integer, Integer, Integer, Integer,
Integer, Integer, Integer, Integer> f7 = F8Functions.f(f8, 8);
F6<Integer, Integer, Integer, Integer, Integer, Integer, Integer> f6 =
F7Functions.f(f7, 7);
F5<Integer, Integer, Integer, Integer, Integer, Integer> f5 = F6Functions.f(f6, 6);
F4<Integer, Integer, Integer, Integer, Integer> f4 = F5Functions.f(f5, 5);
F3<Integer, Integer, Integer, Integer> f3 = F4Functions.f(f4, 4);
F2<Integer, Integer, Integer> f2 = F3Functions.f(f3, 3);
F<Integer, Integer> f1 = F2Functions.f(f2, 2);
assertThat(F1Functions.f(f1, 1).f(), is(36));
}
}
24 changes: 24 additions & 0 deletions core/src/test/java/fj/FWFunctionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fj;

import org.junit.Test;

import fj.F1W;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class FWFunctionsTest {
@Test
public void testLift1() {
F<Integer, Integer> f = i -> i + 1;
F1W f1w = F1W.lift(f);
assertThat(f1w.f(1), is(2));
}

@Test
public void testLift2() {
F2<Integer, Integer, Integer> f2 = (i, j) -> i + j;
F2W f2w = F2W.lift(f2);
assertThat(f2w.f(1, 2), is(3));
}

}
6 changes: 0 additions & 6 deletions core/src/test/java/fj/ShowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
* Created by MarkPerry on 4/06/2015.
*/
public class ShowTest {



@Test
public void arrayShow() {
Array<Integer> a = array(3, 5, 7);
String s = Show.arrayShow(Show.intShow).showS(a);
System.out.println(s);
assertTrue(s.equals("Array(3,5,7)"));

}

}
82 changes: 82 additions & 0 deletions core/src/test/java/fj/TryEffectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package fj;

import fj.data.Validation;
import fj.function.TryEffect0;
import fj.function.TryEffect1;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

public class TryEffectTest {

@Test
public void testTryEffect0Success() {
F<TryEffect0, Validation<TryEffectException, Unit>> f =
TryEffect.f(TryEffect0<TryEffectException>::f);
Validation<TryEffectException, Unit> v = f.f(new AlwaysSucceed0());
assertThat(v.isSuccess(), is(true));
assertThat(v.success(), is(Unit.unit()));
}

@Test
public void testTryEffect0Fail() {
F<TryEffect0, Validation<TryEffectException, Unit>> f =
TryEffect.f(TryEffect0<TryEffectException>::f);
Validation<TryEffectException, Unit> v = f.f(new AlwaysFail0());
assertThat(v.isFail(), is(true));
assertThat(v.fail(), is(new TryEffectException()));
}

@Test
public void testTryEffect1Success() {
F2<TryEffect1<Integer, TryEffectException>, Integer, Validation<TryEffectException, Unit>> f =
TryEffect.f(TryEffect1<Integer, TryEffectException>::f);
Validation<TryEffectException, Unit> v = f.f(new AlwaysSucceed1(), 1);
assertThat(v.isSuccess(), is(true));
assertThat(v.success(), is(Unit.unit()));
}

@Test
public void testTryEffect1Fail() {
F2<TryEffect1<Integer, TryEffectException>, Integer, Validation<TryEffectException, Unit>> f =
TryEffect.f(TryEffect1<Integer, TryEffectException>::f);
Validation<TryEffectException, Unit> v = f.f(new AlwaysFail1(), 1);
assertThat(v.isFail(), is(true));
assertThat(v.fail(), is(new TryEffectException()));
}

class AlwaysSucceed0 implements TryEffect0<TryEffectException> {
@Override
public void f() throws TryEffectException {
// SUCCESS
}
}

class AlwaysSucceed1 implements TryEffect1<Integer, TryEffectException> {
@Override
public void f(Integer i) throws TryEffectException {
// SUCCESS;
}
}

class AlwaysFail0 implements TryEffect0<TryEffectException> {
@Override
public void f() throws TryEffectException {
throw new TryEffectException();
}
}

class AlwaysFail1 implements TryEffect1<Integer, TryEffectException> {
@Override
public void f(Integer i) throws TryEffectException {
throw new TryEffectException();
}
}

class TryEffectException extends Exception {
@Override
public boolean equals (Object obj) {
return (obj instanceof TryEffectException);
}
}
}
50 changes: 50 additions & 0 deletions core/src/test/java/fj/TryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fj;

import fj.data.Validation;
import fj.function.Try0;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class TryTest {

@Test
public void testTrySuccess() {
F<Try0<Integer, TryException>, Validation<TryException, Integer>> f =
Try.f(Try0::f);
Validation<TryException, Integer> v = f.f(new AlwaysSucceed());
assertThat(v.isSuccess(), is(true));
assertThat(v.success(), is(99));
}

@Test
public void testTryFail() {
F<Try0<Integer, TryException>, Validation<TryException, Integer>> f =
Try.f(Try0::f);
Validation<TryException, Integer> v = f.f(new AlwaysFail());
assertThat(v.isFail(), is(true));
assertThat(v.fail(), is(new TryException()));
}

class AlwaysSucceed implements Try0<Integer, TryException> {
@Override
public Integer f() throws TryException {
return 99;
}
}

class AlwaysFail implements Try0<Integer, TryException> {
@Override
public Integer f() throws TryException {
throw new TryException();
}
}

class TryException extends Exception {
@Override
public boolean equals (Object obj) {
return (obj instanceof TryException);
}
}
}
4 changes: 3 additions & 1 deletion core/src/test/java/fj/data/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.EnumSet;

import static fj.Show.listShow;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
* Created by MarkPerry on 14/07/2014.
Expand All @@ -16,7 +18,7 @@ public class JavaTest {
public void test1() {
// #33: Fixes ClassCastException
final List<Colors> colors = Java.<Colors>EnumSet_List().f(EnumSet.allOf(Colors.class));
listShow(Show.<Colors>anyShow()).print(colors);
assertThat(listShow(Show.<Colors>anyShow()).showS(colors), is("List(red,green,blue)"));
}

enum Colors {
Expand Down
1 change: 0 additions & 1 deletion core/src/test/java/fj/data/OptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void traverseList() {
int max = 3;
List<Option<Integer>> actual = some(max).traverseList(a -> List.range(1, a + 1));
List<Option<Integer>> expected = List.range(1, max + 1).map(i -> some(i));
System.out.println(String.format("actual: %s, expected: %s", actual.toString(), expected.toString()));
assertTrue(actual.equals(expected));
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/test/java/fj/data/SeqTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import fj.P2;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -40,7 +42,8 @@ public void convertToString() {
@Test
public void test() {
P2<Seq<Integer>, Seq<Integer>> p2 = Seq.single(1).split(5);
System.out.println(p2);
assertThat(p2._1(), is(Seq.single(1)));
assertThat(p2._2(), is(Seq.empty()));
}

}
9 changes: 8 additions & 1 deletion core/src/test/java/fj/data/StreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ public void testMinus() {
}

@Test
public void testSort() {
public void testSortSeq() {
Stream<Integer> s = range(Enumerator.intEnumerator, 99, -99, -1);
assertThat(s.sort(Ord.intOrd, Strategy.seqStrategy()),
is(s.sort(Ord.intOrd)));
}

@Test
public void testSortThread() {
Stream<Integer> s = range(Enumerator.intEnumerator, 99, -99, -1);
assertThat(s.sort(Ord.intOrd, Strategy.simpleThreadStrategy()),
is(s.sort(Ord.intOrd)));
}
}
11 changes: 0 additions & 11 deletions core/src/test/java/fj/data/TreeMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public void split() {
Show<Set<String>> ss = Show.setShow(Show.stringShow);
Show<Option<String>> so = Show.optionShow(Show.stringShow);
Show<P3<Set<String>, Option<String>, Set<String>>> sp3 = Show.p3Show(ss, so, ss);
if (true) {
st.println(m2);
sp3.println(p);
}

// assert equals
Equal<Set<String>> seq = Equal.setEqual(Equal.stringEqual);
Expand Down Expand Up @@ -70,13 +66,6 @@ public void splitLookup() {
List<Integer> rightList = List.range(pivot + 1, max + 1);
TreeMap<Integer, String> rightMap = iterableTreeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString())));

// debug info
if (true) {
Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
Show<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> sp3 = Show.p3Show(st, Show.optionShow(Show.stringShow), st);
sp3.println(p3);
}

// do the assert
Equal<TreeMap<Integer, String>> tme = Equal.treeMapEqual(Equal.intEqual, Equal.stringEqual);
Equal<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> eq = Equal.p3Equal(tme, Equal.optionEqual(Equal.stringEqual), tme);
Expand Down