/*
 * 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 LongChromosomeTest
	extends NumericChromosomeTester<Long, LongGene>
{

	private final LongChromosome _factory = new LongChromosome(
		0L, Long.MAX_VALUE, 500
	);

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

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

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

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

			Assert.assertTrue(mm.getMin().compareTo(0L) >= 0);
			Assert.assertTrue(mm.getMax().compareTo(100L) <= 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,85 @@
 .MinMax;
+%0Aimport io.jenetics.util.IntRange;%0Aimport io.jenetics.util.LongRange;
 %0A%0A/**%0A *
@@ -2218,16 +2218,16 @@
 ogram);%0A
-
 %09%09%7D);%0A%09%7D
@@ -2228,10 +2228,840 @@
 %7D);%0A%09%7D%0A%0A
+%09@Test(dataProvider = %22chromosomes%22)%0A%09public void chromosomeLength(%0A%09%09final LongChromosome 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%7BLongChromosome.of(0, 1000), IntRange.of(1)%7D,%0A%09%09%09%7BLongChromosome.of(LongRange.of(0, 1000)), IntRange.of(1)%7D,%0A%09%09%09%7BLongChromosome.of(0, 1000, 1), IntRange.of(1)%7D,%0A%09%09%09%7BLongChromosome.of(0, 1000, 2), IntRange.of(2)%7D,%0A%09%09%09%7BLongChromosome.of(0, 1000, 20), IntRange.of(20)%7D,%0A%09%09%09%7BLongChromosome.of(0, 1000, IntRange.of(2, 10)), IntRange.of(2, 10)%7D,%0A%09%09%09%7BLongChromosome.of(LongRange.of(0, 1000), IntRange.of(2, 10)), IntRange.of(2, 10)%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D%0A

Add unit tests.