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

import static org.assertj.core.api.Assertions.assertThat;

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

import io.jenetics.BitChromosome;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 */
public class CodonsTest {

	@Test(dataProvider = "chromosomeSizes")
	public void toByteArray(final int size) {
		final var ch = BitChromosome.of(size);

		assertThat(Codons.toByteArray(ch)).isEqualTo(ch.toByteArray());
	}

	@DataProvider
	public Object[][] chromosomeSizes() {
		return new Object[][] {
			{1}, {2}, {3}, {7}, {8}, {9}, {10}, {15}, {16}, {17}, {31},
			{32}, {33}, {100}, {1_000}, {10_000}, {100_000}
		};
	}

}

@@ -832,24 +832,60 @@
 ssertThat;%0A%0A
+import java.util.stream.IntStream;%0A%0A
 import org.t
@@ -1507,10 +1507,584 @@
 %09%7D;%0A%09%7D%0A%0A
+%09@Test(dataProvider = %22codonsSizes%22)%0A%09public void nextIndex(final int size, final int bound) %7B%0A%09%09final int%5B%5D values = IntStream.range(0, size).toArray();%0A%09%09final SymbolIndex index = Codons.ofIntArray(values);%0A%0A%09%09for (int i = 0, n = size*3; i %3C n; ++i) %7B%0A%09%09%09final int expectedIndex = values%5Bi%25values.length%5D%25bound;%0A%09%09%09assertThat(index.next(bound)).isEqualTo(expectedIndex);%0A%09%09%7D%0A%09%7D%0A%0A%09@DataProvider%0A%09public Object%5B%5D%5B%5D codonsSizes() %7B%0A%09%09return new Object%5B%5D%5B%5D %7B%0A%09%09%09%7B1, 1%7D,%0A%09%09%09%7B2, 10%7D,%0A%09%09%09%7B3, 2%7D,%0A%09%09%09%7B8, 8%7D,%0A%09%09%09%7B10, 5%7D,%0A%09%09%09%7B16, 10%7D,%0A%09%09%09%7B31, 15%7D,%0A%09%09%09%7B33, 20%7D,%0A%09%09%09%7B100, 5%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D%0A

Add unit tests for 'Codons' class.