package org.oakgp.mutate;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import org.junit.Test;
import org.oakgp.node.Node;
import org.oakgp.selector.DummyNodeSelector;
import org.oakgp.util.Random;

public class CrossoverTest {
	@Test
	public void test() {
		Random mockRandom = mock(Random.class);
		given(mockRandom.nextInt(3)).willReturn(1);
		given(mockRandom.nextInt(5)).willReturn(3);

		DummyNodeSelector dummySelector = new DummyNodeSelector("(+ 9 5)", "(* 7 (- 8 p5))");

		SubtreeCrossover c = new SubtreeCrossover(mockRandom);

		Node result = c.evolve(dummySelector);
		assertEquals("(org.oakgp.operator.Add 9 (org.oakgp.operator.Subtract 8 p5))", result.toString());
		assertTrue(dummySelector.isEmpty());
	}
}
@@ -842,10 +842,1091 @@
 y());%0A%09%7D
+%0A%0A%09@Test%0A%09public void testMixingTypes() %7B%0A%09%09// TODO get code working as it should, then update this test to reflect the new correct behaviour%0A%09%09// NOTE: this test demonstrates the current incorrect behaviour of the code.%0A%09%09// The result breaks the signature of the Add operator.%0A%09%09// i.e. the Add operator expects both of its arguments to be of type integer - but crossover has replaced one of the existing arguments with a%0A%09%09// function node that has a LessThan operator - which has a boolean return type%0A%09%09// (this will be a problem when we stop using int primitives to represent both integer and boolean values)%0A%0A%09%09Random mockRandom = mock(Random.class);%0A%09%09given(mockRandom.nextInt(3)).willReturn(1);%0A%09%09given(mockRandom.nextInt(6)).willReturn(2);%0A%0A%09%09DummyNodeSelector dummySelector = new DummyNodeSelector(%22(+ 9 5)%22, %22(if (%3C 6 7) 8 9)%22);%0A%0A%09%09SubtreeCrossover c = new SubtreeCrossover(mockRandom);%0A%0A%09%09Node result = c.evolve(dummySelector);%0A%09%09assertEquals(%22(org.oakgp.operator.Add 9 (org.oakgp.operator.LessThan 6 7))%22, result.toString());%0A%09%09assertTrue(dummySelector.isEmpty());%0A%09%7D
 %0A%7D

Test when crossover points have different types