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);
}
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()));
}
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);
}
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);
}
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));
}
Aggregations