Search in sources :

Example 1 with ArrayCreator

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()));
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) ArrayCreator(teetime.testutil.ArrayCreator) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Example 2 with ArrayCreator

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));
    }
}
Also used : Counter(teetime.stage.Counter) BlockingBusyWaitingRoundRobinMergerStrategy(teetime.stage.basic.merger.strategy.BlockingBusyWaitingRoundRobinMergerStrategy) ArrayList(java.util.ArrayList) ArrayCreator(teetime.testutil.ArrayCreator) BlockingBusyWaitingRoundRobinDistributorStrategy(teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy) Test(org.junit.Test)

Example 3 with ArrayCreator

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));
    }
}
Also used : Counter(teetime.stage.Counter) ArrayList(java.util.ArrayList) ArrayCreator(teetime.testutil.ArrayCreator) Test(org.junit.Test)

Example 4 with ArrayCreator

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));
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) ArrayCreator(teetime.testutil.ArrayCreator) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ArrayCreator (teetime.testutil.ArrayCreator)4 Counter (teetime.stage.Counter)2 QuicksortProblem (teetime.stage.quicksort.QuicksortProblem)2 QuicksortSolution (teetime.stage.quicksort.QuicksortSolution)2 BlockingBusyWaitingRoundRobinDistributorStrategy (teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy)1 BlockingBusyWaitingRoundRobinMergerStrategy (teetime.stage.basic.merger.strategy.BlockingBusyWaitingRoundRobinMergerStrategy)1