public void DiscreteCrossoverApplyTest()
        {
            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[] { 0, 0, 1, 0, 1 };
            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, 5, 8 });
            actual            = DiscreteCrossover.Apply(random, new ItemArray <IntegerVector>(new IntegerVector[] { parent1, parent2 }));
            Assert.IsTrue(Auxiliary.IntegerVectorIsEqualByPosition(actual, expected));

            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 0, 0, 1, 0, 1 };
            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 = DiscreteCrossover.Apply(random, new ItemArray <IntegerVector>(new IntegerVector[] { parent1, parent2 }));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemple #2
0
        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));
        }