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
61 changes: 61 additions & 0 deletions core/src/test/java/fj/control/parallel/StrategyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fj.control.parallel;

import fj.Ord;
import fj.P;
import fj.P1;
import fj.data.Enumerator;
import fj.data.List;
import fj.data.Stream;
import org.junit.Test;

import java.util.concurrent.*;

import static fj.control.parallel.Callables.callable;
import static fj.control.parallel.Strategy.*;
import static fj.data.Stream.range;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class StrategyTest {

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

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

@Test
public void testStrategyExecutor() {
final Stream<Integer> s = range(Enumerator.intEnumerator, 99, -99, -1);
final ExecutorService es = Executors.newFixedThreadPool(10);
assertThat(s.sort(Ord.intOrd, executorStrategy(es)), is(s.sort(Ord.intOrd)));
}

@Test
public void testStrategyCompletion() {
final Stream<Integer> s = range(Enumerator.intEnumerator, 99, -99, -1);
final ExecutorService es = Executors.newFixedThreadPool(10);
final CompletionService cs = new ExecutorCompletionService(es);
assertThat(s.sort(Ord.intOrd, completionStrategy(cs)), is(s.sort(Ord.intOrd)));
}

@Test
public void testStrategyMergeAll() {
final List<Integer> l = List.range(0, 100);
final List<P1<Integer>> p1s = mergeAll(l.map(x -> CompletableFuture.supplyAsync(() -> x)));
assertThat(P1.sequence(p1s)._1(), is(l));
}

@Test
public void testStrategyCallables() throws Exception {
final Strategy<Callable<Integer>> s = strategy(c -> c);
final Strategy<Callable<Integer>> cs = callableStrategy(s);
assertThat(callableStrategy(s).par(P.p(callable(1)))._1().call(), is(1));
}
}
16 changes: 0 additions & 16 deletions core/src/test/java/fj/data/StreamTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fj.data;

import fj.Equal;
import fj.Ord;
import fj.P2;
import fj.control.parallel.Strategy;
import org.junit.Test;

import java.util.ConcurrentModificationException;
Expand Down Expand Up @@ -105,18 +103,4 @@ public void testMinus() {
assertThat(s1.minus(Equal.charEqual, s2),
is(stream(new Character[]{'a', 'c', 'd'})));
}

@Test
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)));
}
}