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