public void SinglePointCrossoverApplyTest() { TestRandom random = new TestRandom(); IntegerVector parent1, parent2, expected, actual; bool exceptionFired; // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 3 }; parent1 = new IntegerVector(new int[] { 2, 2, 3, 5, 1 }); parent2 = new IntegerVector(new int[] { 4, 1, 3, 2, 8 }); expected = new IntegerVector(new int[] { 2, 2, 3, 2, 8 }); actual = SinglePointCrossover.Apply(random, parent1, parent2); Assert.IsTrue(Auxiliary.IntegerVectorIsEqualByPosition(actual, expected)); // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 2 }; parent1 = new IntegerVector(new int[] { 2, 2, 3, 5, 1, 9 }); // this parent is longer parent2 = new IntegerVector(new int[] { 4, 1, 3, 2, 8 }); exceptionFired = false; try { actual = SinglePointCrossover.Apply(random, parent1, parent2); } catch (System.ArgumentException) { exceptionFired = true; } Assert.IsTrue(exceptionFired); }
public void UniformOnePositionManipulatorApplyTest() { TestRandom random = new TestRandom(); IntegerVector parent, expected; IntMatrix bounds = new IntMatrix(1, 2); // The following test is not based on published examples random.Reset(); random.IntNumbers = new int[] { 3, 3 }; parent = new IntegerVector(new int[] { 2, 2, 3, 5, 1 }); expected = new IntegerVector(new int[] { 2, 2, 3, 3, 1 }); bounds[0, 0] = 2; bounds[0, 1] = 7; UniformOnePositionManipulator.Apply(random, parent, bounds); Assert.IsTrue(Auxiliary.IntegerVectorIsEqualByPosition(expected, parent)); }