Search in sources :

Example 1 with QuicksortSolution

use of teetime.stage.quicksort.QuicksortSolution in project TeeTime by teetime-framework.

the class QuicksortTest method executeTestWithDefaultConfiguration.

@Test
public void executeTestWithDefaultConfiguration() {
    int[] numbers = new int[] { 3, 1, 4, 5, 2 };
    QuicksortProblem problemOne = new QuicksortProblem(0, numbers.length - 1, numbers);
    List<QuicksortProblem> inputs = new ArrayList<QuicksortProblem>();
    inputs.add(problemOne);
    List<QuicksortSolution> outputs = new ArrayList<QuicksortSolution>();
    final QuicksortConfiguration configuration = new QuicksortConfiguration(inputs, outputs);
    final Execution<QuicksortConfiguration> execution = new Execution<>(configuration);
    execution.executeBlocking();
    int[] sortedNumbers = new int[] { 1, 2, 3, 4, 5 };
    assertArrayEquals(outputs.get(0).getNumbers(), sortedNumbers);
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Example 2 with QuicksortSolution

use of teetime.stage.quicksort.QuicksortSolution 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 3 with QuicksortSolution

use of teetime.stage.quicksort.QuicksortSolution in project TeeTime by teetime-framework.

the class QuicksortTest method executeTestWithConfigurationCreatedByBuilder.

@Test
public void executeTestWithConfigurationCreatedByBuilder() {
    int[] numbers = new int[] { 3, 1, 4, 5, 2 };
    QuicksortProblem problemOne = new QuicksortProblem(0, numbers.length - 1, numbers);
    ArrayList<QuicksortProblem> inputs = new ArrayList<QuicksortProblem>();
    inputs.add(problemOne);
    ArrayList<QuicksortSolution> outputs = new ArrayList<QuicksortSolution>();
    // set up quicksort stage since it should be declared active
    DivideAndConquerStage<QuicksortProblem, QuicksortSolution> quicksortStage = new DivideAndConquerStage<QuicksortProblem, QuicksortSolution>(2);
    quicksortStage.declareActive();
    final Configuration configuration = ConfigurationBuilder.from(new InitialElementProducer<QuicksortProblem>(inputs)).to(quicksortStage).end(new CollectorSink<QuicksortSolution>(outputs));
    final Execution<Configuration> execution = new Execution<>(configuration);
    execution.executeBlocking();
    int[] sortedNumbers = new int[] { 1, 2, 3, 4, 5 };
    assertArrayEquals(outputs.get(0).getNumbers(), sortedNumbers);
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Example 4 with QuicksortSolution

use of teetime.stage.quicksort.QuicksortSolution in project TeeTime by teetime-framework.

the class QuicksortTest method executeTestWithBuilderBasedConfiguration.

@Test
public void executeTestWithBuilderBasedConfiguration() {
    int[] numbers = new int[] { 3, 1, 4, 5, 2 };
    QuicksortProblem problemOne = new QuicksortProblem(0, numbers.length - 1, numbers);
    ArrayList<QuicksortProblem> inputs = new ArrayList<QuicksortProblem>();
    inputs.add(problemOne);
    ArrayList<QuicksortSolution> outputs = new ArrayList<QuicksortSolution>();
    final QuicksortConfigurationFromBuilder configuration = new QuicksortConfigurationFromBuilder(inputs, outputs);
    final Execution<QuicksortConfigurationFromBuilder> execution = new Execution<>(configuration);
    execution.executeBlocking();
    int[] sortedNumbers = new int[] { 1, 2, 3, 4, 5 };
    assertArrayEquals(outputs.get(0).getNumbers(), sortedNumbers);
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Example 5 with QuicksortSolution

use of teetime.stage.quicksort.QuicksortSolution in project TeeTime by teetime-framework.

the class DivideAndConquerStageTest method shouldSortEmptyArray.

@Test
public void shouldSortEmptyArray() {
    int[] noInputValues = {};
    QuicksortProblem problem = new QuicksortProblem(noInputValues);
    List<QuicksortSolution> solutions = new ArrayList<QuicksortSolution>();
    test(this.quicksortStage).and().send(problem).to(quicksortStage.getInputPort()).and().receive(solutions).from(quicksortStage.getOutputPort()).start();
    assertThat(solutions.get(0).getNumbers(), is(noInputValues));
    assertThat(solutions.size(), is(1));
}
Also used : QuicksortSolution(teetime.stage.quicksort.QuicksortSolution) ArrayList(java.util.ArrayList) QuicksortProblem(teetime.stage.quicksort.QuicksortProblem) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 QuicksortProblem (teetime.stage.quicksort.QuicksortProblem)8 QuicksortSolution (teetime.stage.quicksort.QuicksortSolution)8 ArrayCreator (teetime.testutil.ArrayCreator)2