/*
 * 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 static org.jenetics.stat.StatisticsAssert.assertDistribution;

import java.util.Random;

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

import org.jenetics.stat.Histogram;
import org.jenetics.stat.UniformDistribution;
import org.jenetics.util.CharSeq;
import org.jenetics.util.Factory;
import org.jenetics.util.RandomRegistry;
import org.jenetics.util.Scoped;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version <em>$Date: 2014-02-18 $</em>
 */
@SuppressWarnings("deprecation")
public class CharacterChromosomeTest extends ChromosomeTester<CharacterGene> {

	private final Factory<Chromosome<CharacterGene>>
	_factory = new CharacterChromosome(500);
	@Override protected Factory<Chromosome<CharacterGene>> getFactory() {
		return _factory;
	}


	@Test(invocationCount = 20, successPercentage = 95)
    public void newInstanceDistribution() {
		try (Scoped<Random> s = RandomRegistry.scope(new Random(12345))) {
			final CharSeq characters = new CharSeq("0123456789");
			final CharacterChromosome chromosome = new CharacterChromosome(characters, 5000);

			final Histogram<Long> histogram = Histogram.of(0L, 10L, 10);

			for (CharacterGene gene : chromosome) {
				histogram.accumulate(Long.valueOf(gene.getAllele().toString()));
			}

			assertDistribution(histogram, new UniformDistribution<>(0L, 10L));
		}
    }

	@Test(dataProvider = "genes")
	public void newCharacterChromosome(final String genes) {
		final CharSeq characters = new CharSeq("0123456789");
		CharacterChromosome chromosome = new CharacterChromosome(genes, characters);

		Assert.assertEquals(new String(new StringBuilder(chromosome)), genes);
	}

	@Test(dataProvider = "genes", expectedExceptions = IllegalArgumentException.class)
	public void newIllegalCharacterChromosome(final String genes) {
		final CharSeq characters = new CharSeq("012356789");
		CharacterChromosome chromosome = new CharacterChromosome(genes, characters);

		Assert.assertEquals(new String(new StringBuilder(chromosome)), genes);
	}

	@DataProvider(name = "genes")
	public Object[][] genes() {
		return new Object[][] {
				{"54374"},
				{"543794578"},
				{"54374546"},
				{"543345647"},
				{"54304897"},
				{"5433457245"}
		};
	}

}

@@ -1320,41 +1320,8 @@
  */%0A
-@SuppressWarnings(%22deprecation%22)%0A
 publ
@@ -1457,20 +1457,16 @@
 actory =
- new
  Charact
@@ -1477,16 +1477,19 @@
 romosome
+.of
 (500);%0A%09
@@ -1838,36 +1838,32 @@
 ome chromosome =
- new
  CharacterChromo
@@ -1866,16 +1866,19 @@
 romosome
+.of
 (charact
@@ -2325,36 +2325,32 @@
 ome chromosome =
- new
  CharacterChromo
@@ -2345,32 +2345,35 @@
 racterChromosome
+.of
 (genes, characte
@@ -2488,61 +2488,8 @@
 nes%22
-, expectedExceptions = IllegalArgumentException.class
 )%0A%09p
@@ -2640,20 +2640,16 @@
 mosome =
- new
  Charact
@@ -2660,16 +2660,19 @@
 romosome
+.of
 (genes, 
@@ -2677,32 +2677,108 @@
 , characters);%0A%0A
+%09%09Assert.assertFalse(chromosome.isValid(), %22Chromosome must not be valid%22);%0A
 %09%09Assert.assertE

Remove deprecated methods.