/*
 * 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@gmail.com)
 */
package io.jenetics;

import static io.jenetics.stat.StatisticsAssert.assertUniformDistribution;
import static io.jenetics.util.RandomRegistry.using;

import java.util.Random;

import org.testng.Assert;
import org.testng.annotations.Test;

import io.jenetics.stat.Histogram;
import io.jenetics.stat.MinMax;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 */
public class DoubleChromosomeTest
	extends NumericChromosomeTester<Double, DoubleGene>
{

	private final DoubleChromosome _factory = new DoubleChromosome(
		0.0, Double.MAX_VALUE, 500
	);

	@Override
	protected DoubleChromosome factory() {
		return _factory;
	}

	@Test(invocationCount = 20, successPercentage = 95)
	public void newInstanceDistribution() {
		using(new Random(12345), r -> {
			final double min = 0;
			final double max = 100;


			final MinMax<Double> mm = MinMax.of();
			final Histogram<Double> histogram = Histogram.ofDouble(min, max, 10);

			for (int i = 0; i < 1000; ++i) {
				final DoubleChromosome chromosome = new DoubleChromosome(min, max, 500);
				for (DoubleGene gene : chromosome) {
					mm.accept(gene.getAllele());
					histogram.accept(gene.getAllele());
				}
			}

			Assert.assertTrue(mm.getMin().compareTo(0.0) >= 0);
			Assert.assertTrue(mm.getMax().compareTo(100.0) <= 100);
			assertUniformDistribution(histogram);
		});
	}

}

@@ -759,16 +759,55 @@
 etics;%0A%0A
+import static java.lang.String.format;%0A
 import s
@@ -873,16 +873,16 @@
 bution;%0A
-
 import s
@@ -979,16 +979,60 @@
 Assert;%0A
+import org.testng.annotations.DataProvider;%0A
 import o
@@ -1126,16 +1126,87 @@
 .MinMax;
+%0Aimport io.jenetics.util.DoubleRange;%0Aimport io.jenetics.util.IntRange;
 %0A%0A/**%0A *
@@ -2249,16 +2249,16 @@
 ogram);%0A
-
 %09%09%7D);%0A%09%7D
@@ -2259,10 +2259,839 @@
 %7D);%0A%09%7D%0A%0A
+%09@Test(dataProvider = %22chromosomes%22)%0A%09public void chromosomeLength(%0A%09%09final DoubleChromosome dc,%0A%09%09final IntRange length%0A%09) %7B%0A%09%09Assert.assertTrue(%0A%09%09%09dc.length() %3E= length.getMin() && dc.length() %3C length.getMax(),%0A%09%09%09format(%22Chromosome length %25s not in range %25s.%22, dc.length(), length)%0A%09%09);%0A%09%7D%0A%0A%09@DataProvider(name = %22chromosomes%22)%0A%09public Object%5B%5D%5B%5D chromosomes() %7B%0A%09%09return new Object%5B%5D%5B%5D %7B%0A%09%09%09%7BDoubleChromosome.of(0, 1), IntRange.of(1)%7D,%0A%09%09%09%7BDoubleChromosome.of(DoubleRange.of(0, 1)), IntRange.of(1)%7D,%0A%09%09%09%7BDoubleChromosome.of(0, 1, 1), IntRange.of(1)%7D,%0A%09%09%09%7BDoubleChromosome.of(0, 1, 2), IntRange.of(2)%7D,%0A%09%09%09%7BDoubleChromosome.of(0, 1, 20), IntRange.of(20)%7D,%0A%09%09%09%7BDoubleChromosome.of(0, 1, IntRange.of(2, 10)), IntRange.of(2, 10)%7D,%0A%09%09%09%7BDoubleChromosome.of(DoubleRange.of(0, 1), IntRange.of(2, 10)), IntRange.of(2, 10)%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D%0A

Add unit tests.