コード例 #1
0
ファイル: MutationTest.cs プロジェクト: bjutlgr/ga1
 public void PointMutationTest()
 {
     IChromosome<bool> a = new BinaryChromosome().GenerateFromArray(new bool[] { false, true, false, true, false });
     PointMutation mutation = new PointMutation(1);
     IChromosome<bool> res = mutation.Mutate(a);
     IChromosome<bool> exp = new BinaryChromosome().GenerateFromArray(new bool[] { true, false, true, false, true });
     Assert.AreEqual(exp, res);
 }
コード例 #2
0
ファイル: MutationTests.cs プロジェクト: pedrodbs/Genetica
        public void PointMutationTest()
        {
            var converter = new MathExpressionConverter(MathPrimitiveSets.Default);
            var prog1     = converter.FromNormalNotation("1");
            var prog2     = converter.FromNormalNotation("4");

            Console.WriteLine($"{prog1}, {prog2}");
            var op       = new PointMutation <MathProgram, double>(ExtraPrimitiveSet);
            var allProgs = new HashSet <MathProgram>(op.GetAllMutations(prog1));

            Assert.IsTrue(allProgs.Contains(prog2), $"{prog2} should be a valid mutation of {prog1}.");
            Assert.AreEqual(allProgs.Count, 2, double.Epsilon, $"Mutation of {prog1} should only have 2 elements.");
        }