use of teetime.testutil.ArrayCreator in project TeeTime by teetime-framework.
the class DivideAndConquerStageTest method shouldSortMultipleHugeArrays.
@Test
public void shouldSortMultipleHugeArrays() {
ArrayCreator arrayCreator = new ArrayCreator(0);
List<QuicksortProblem> problems = new ArrayList<QuicksortProblem>();
problems.add(new QuicksortProblem(arrayCreator.createFilledArray(10000000)));
problems.add(new QuicksortProblem(arrayCreator.createFilledArray(10000000)));
problems.add(new QuicksortProblem(arrayCreator.createFilledArray(10000000)));
List<QuicksortSolution> solutions = new ArrayList<QuicksortSolution>();
test(this.quicksortStage).and().send(problems).to(quicksortStage.getInputPort()).and().receive(solutions).from(quicksortStage.getOutputPort()).start();
AssertHelper.assertSorted(solutions.get(0).getNumbers());
AssertHelper.assertSorted(solutions.get(1).getNumbers());
AssertHelper.assertSorted(solutions.get(2).getNumbers());
assertThat(solutions.size(), is(problems.size()));
}
use of teetime.testutil.ArrayCreator in project TeeTime by teetime-framework.
the class StaticTaskFarmStageTest method testOrderedStaticTaskFarmStageWithMultipleStage.
@Test
public void testOrderedStaticTaskFarmStageWithMultipleStage() throws Exception {
ArrayCreator creator = new ArrayCreator(SEED);
List<Integer> randomNumbers = creator.createFilledList(1024);
TestTuple[] testInputTuples = { // expect in correct order
TestTuple.use(2, randomNumbers).expect(randomNumbers), // expect in correct order
TestTuple.use(3, randomNumbers).expect(randomNumbers) };
for (TestTuple testTuple : testInputTuples) {
StaticTaskFarmStage<Integer, Integer, Counter<Integer>> taskFarmStage = createTaskFarm(testTuple.numWorkerStages);
// ordered element passing
taskFarmStage.getDistributor().setStrategy(new BlockingBusyWaitingRoundRobinDistributorStrategy());
taskFarmStage.getMerger().setStrategy(new BlockingBusyWaitingRoundRobinMergerStrategy());
List<Integer> outputElements = new ArrayList<Integer>();
test(taskFarmStage).and().send(testTuple.inputElements).to(taskFarmStage.getInputPort()).and().receive(outputElements).from(taskFarmStage.getOutputPort()).start();
assertThat(outputElements, contains(testTuple.expectedOutputElements));
}
}
use of teetime.testutil.ArrayCreator in project TeeTime by teetime-framework.
the class StaticTaskFarmStageTest method testStaticTaskFarmStageWithSingleStage.
@Test
public void testStaticTaskFarmStageWithSingleStage() throws Exception {
ArrayCreator creator = new ArrayCreator(SEED);
List<Integer> randomNumbers = creator.createFilledList(1024);
TestTuple[] testInputTuples = { // tuple semantics: number of worker stages, input elements, and (expect) output elements
TestTuple.use(1, 1, 2).expect(1, 2), // expect in any order
TestTuple.use(1, randomNumbers).expect(randomNumbers) };
for (TestTuple testTuple : testInputTuples) {
StaticTaskFarmStage<Integer, Integer, Counter<Integer>> taskFarmStage = createTaskFarm(testTuple.numWorkerStages);
List<Integer> outputElements = new ArrayList<Integer>();
test(taskFarmStage).and().send(testTuple.inputElements).to(taskFarmStage.getInputPort()).and().receive(outputElements).from(taskFarmStage.getOutputPort()).start();
assertThat(outputElements, contains(testTuple.expectedOutputElements));
}
}
use of teetime.testutil.ArrayCreator in project TeeTime by teetime-framework.
the class DivideAndConquerStageTest method shouldSortHugeArray.
@Test
public void shouldSortHugeArray() {
int[] numbers = new ArrayCreator(0).createFilledArray(10000000);
QuicksortProblem problem = new QuicksortProblem(numbers);
List<QuicksortSolution> solutions = new ArrayList<QuicksortSolution>();
test(this.quicksortStage).and().send(problem).to(quicksortStage.getInputPort()).and().receive(solutions).from(quicksortStage.getOutputPort()).start();
AssertHelper.assertSorted(solutions.get(0).getNumbers());
assertThat(solutions.size(), is(1));
}
Aggregations