Пример #1
0
        public void Crossover(string stringA, string stringB, ISeq <int> points, string expectedA, string expectedB)
        {
            var a = CharSeq.ToImmutableSeq(stringA);
            var b = CharSeq.ToImmutableSeq(stringB);

            var ma = a.Copy();
            var mb = b.Copy();

            var intPoints = points.Select(i => i).ToArray();

            MultiPointCrossover.Crossover(ma, mb, intPoints);
            Assert.Equal(ToString(ma), expectedA);
            Assert.Equal(ToString(mb), expectedB);
        }
Пример #2
0
        public void SinglePointCrossoverConsistency()
        {
            var a = CharSeq.ToImmutableSeq("1234567890");
            var b = CharSeq.ToImmutableSeq("ABCDEFGHIJ");

            for (var i = 0; i < a.Length + 1; ++i)
            {
                var ma1 = a.Copy();
                var mb1 = b.Copy();
                var ma2 = a.Copy();
                var mb2 = b.Copy();

                MultiPointCrossover.Crossover(ma1, mb1, new[] { i });
                SinglePointCrossover.Crossover(ma2, mb2, i);

                Assert.Equal(ma1, ma2);
                Assert.Equal(mb1, mb2);
            }
        }