/*
 * 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.jenetix;

import java.util.Random;
import java.util.stream.Collectors;

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

import org.jenetics.util.ISeq;

import org.jenetix.util.MutableTreeNode;
import org.jenetix.util.MutableTreeNodeTest;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
public class TreeChromosomeTest {

	@Test
	public void create() {
		final MutableTreeNode<Integer> tree =
			MutableTreeNodeTest.newTree(3, new Random(123));

		final TreeChromosome<Integer> chromosome = TreeChromosome.of(tree);
		System.out.println(chromosome.length());
		System.out.println(chromosome);

		final MutableTreeNode<Integer> tree2 = chromosome.toTree();

		final ISeq<Integer> seq1 = tree.stream()
			.map(MutableTreeNode::getValue)
			.collect(ISeq.toISeq());
		final ISeq<Integer> seq2 = tree2.stream()
			.map(MutableTreeNode::getValue)
			.collect(ISeq.toISeq());

		System.out.println(seq1);
		System.out.println(seq2);

		Assert.assertEquals(seq1, seq2);
	}

}

@@ -784,44 +784,8 @@
 dom;
-%0Aimport java.util.stream.Collectors;
 %0A%0Aim
@@ -869,14 +869,78 @@
 ics.
-util.I
+SwapMutator;%0Aimport org.jenetics.util.ISeq;%0Aimport org.jenetics.util.M
 Seq;
@@ -1848,10 +1848,632 @@
 2);%0A%09%7D%0A%0A
+%09@Test%0A%09public void swap() %7B%0A%09%09final MutableTreeNode%3CInteger%3E tree =%0A%09%09%09MutableTreeNodeTest.newTree(5, new Random(123));%0A%0A%09%09final SwapMutator%3CTreeGene%3CInteger%3E, Integer%3E mutator = new SwapMutator%3C%3E();%0A%09%09final TreeChromosome%3CInteger%3E chromosome = TreeChromosome.of(tree);%0A%09%09System.out.println(chromosome);%0A%0A%09%09for (int i = 0; i %3C 30; ++i) %7B%0A%09%09%09final MSeq%3CTreeGene%3CInteger%3E%3E genes = chromosome.toSeq().copy();%0A%09%09%09genes.shuffle();%0A%09%09%09final TreeChromosome%3CInteger%3E sc = chromosome.newInstance(genes.toISeq());%0A%09%09%09System.out.println(sc);%0A%09%09%09System.out.flush();%0A%09%09%09System.out.println(sc.toTree());%0A%09%09%09System.out.flush();%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

Add some mutator tests.