Search in sources :

Example 6 with QuicksortSolution

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

the class DivideAndConquerStageTest method shouldSortSingleArray.

@Test
public void shouldSortSingleArray() {
    int[] numbers = { 5, 4, 3, 2, 1 };
    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()).and().start();
    int[] sortedNumbers = new int[] { 1, 2, 3, 4, 5 };
    assertArrayEquals(solutions.get(0).getNumbers(), sortedNumbers);
    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)

Example 7 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 8 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)

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