/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 */
package org.jenetics;

import java.util.Random;

import org.testng.SkipException;
import org.testng.annotations.Test;

import org.jenetics.stat.Distribution;
import org.jenetics.stat.UniformDistribution;
import org.jenetics.util.Factory;
import org.jenetics.util.RandomRegistry;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version <em>$Date: 2014-08-12 $</em>
 */
public class TournamentSelectorTest
	extends SelectorTester<TournamentSelector<DoubleGene, Double>>
{

	final Factory<TournamentSelector<DoubleGene, Double>>
	_factory = new Factory<TournamentSelector<DoubleGene,Double>>()
	{
		@Override
		public TournamentSelector<DoubleGene, Double> newInstance() {
			final Random random = RandomRegistry.getRandom();
			return new TournamentSelector<>(random.nextInt(10) + 2);
		}
	};
	@Override
	protected Factory<TournamentSelector<DoubleGene, Double>> factory() {
		return _factory;
	}

	@Override
	protected Distribution<Double> getDistribution() {
		return new UniformDistribution<>(getDomain());
	}

	// TODO: implement select-distribution test.
	@Override
	@Test
	public void selectDistribution() {
		throw new SkipException("TODO: implement this test.");
	}

}

@@ -774,21 +774,67 @@
 va.util.
-Rando
+function.Function;%0Aimport java.util.stream.IntStrea
 m;%0A%0Aimpo
@@ -930,32 +930,68 @@
 t.Distribution;%0A
+import org.jenetics.stat.Histogram;%0A
 import org.jenet
@@ -1082,27 +1082,18 @@
 util.Ran
-domRegistry
+ge
 ;%0A%0A/**%0A 
@@ -1205,17 +1205,17 @@
 014-08-1
-2
+5
  $%3C/em%3E%0A
@@ -1325,328 +1325,8 @@
 %0A%7B%0A%0A
-%09final Factory%3CTournamentSelector%3CDoubleGene, Double%3E%3E%0A%09_factory = new Factory%3CTournamentSelector%3CDoubleGene,Double%3E%3E()%0A%09%7B%0A%09%09@Override%0A%09%09public TournamentSelector%3CDoubleGene, Double%3E newInstance() %7B%0A%09%09%09final Random random = RandomRegistry.getRandom();%0A%09%09%09return new TournamentSelector%3C%3E(random.nextInt(10) + 2);%0A%09%09%7D%0A%09%7D;%0A
 %09@Ov
@@ -1416,16 +1416,41 @@
 urn 
-_factory
+() -%3E new TournamentSelector%3C%3E(3)
 ;%0A%09%7D
@@ -1571,54 +1571,8 @@
 %09%7D%0A%0A
-%09// TODO: implement select-distribution test.%0A
 %09@Ov
@@ -1621,16 +1621,16 @@
 ion() %7B%0A
-
 %09%09throw 
@@ -1682,10 +1682,1004 @@
 %22);%0A%09%7D%0A%0A
+%09public static void main(final String%5B%5D args) %7B%0A%09%09final Range%3CDouble%3E domain = new Range%3C%3E(0.0, 100.0);%0A%09%09final int npopulation = 101;%0A%09%09final int loops = 100_000;%0A%0A%09%09final Double min = domain.getMin();%0A%09%09final Double max = domain.getMax();%0A%09%09final Histogram%3CDouble%3E histogram = Histogram.of(min, max, 37);%0A%0A%09%09final Function%3CGenotype%3CDoubleGene%3E, Double%3E ff = gt -%3E gt.getGene().getAllele();%0A%09%09final Factory%3CPhenotype%3CDoubleGene, Double%3E%3E ptf = () -%3E%0A%09%09%09Phenotype.of(Genotype.of(DoubleChromosome.of(min, max)), ff, 12);%0A%0A%09%09final Selector%3CDoubleGene, Double%3E selector = new TournamentSelector%3C%3E();%0A%0A%09%09for (int j = 0; j %3C loops; ++j) %7B%0A%09%09%09final Population%3CDoubleGene, Double%3E population = IntStream.range(0, npopulation)%0A%09%09%09%09.mapToObj(i -%3E ptf.newInstance())%0A%09%09%09%09.collect(Population.toPopulation());%0A%0A%09%09%09selector.select(population, npopulation/2, Optimize.MINIMUM).stream()%0A%09%09%09%09.map(pt -%3E pt.getGenotype().getGene().getAllele())%0A%09%09%09%09.forEach(histogram);%0A%09%09%7D%0A%0A%09%09System.out.println(histogram);%0A%09%7D%0A%0A
 %7D%0A

Add test.