예제 #1
0
        public void ToInteger_NegativeValue_Integer()
        {
            RandomizationProvider.Current = Substitute.For <IRandomization>();
            RandomizationProvider.Current.GetInt(0, 3).Returns(-2);

            var target = new IntegerChromosome(0, 3);

            Assert.AreEqual("11111111111111111111111111111110", target.ToString());

            var actual = target.ToInteger();

            Assert.AreEqual(-2, actual);
        }
        public void Integer()
        {
            var target = new IntegerChromosome(0, 10);

            target.Clone();
            target.CompareTo(new IntegerChromosome(0, 10));
            target.CreateNew();
            var x = target.Fitness;

            target.FlipGene(0);
            target.GenerateGene(0);
            target.GetGene(0);
            target.GetGenes();
            target.GetHashCode();
            var y = target.Length;

            target.ReplaceGene(0, new Gene(false));
            target.ReplaceGenes(0, new Gene[] { new Gene(false), new Gene(true) });
            target.Resize(20);
            target.ToInteger();
            target.ToString();
        }
        public void FlipGene_Index_ValueFlip()
        {
            RandomizationProvider.Current = Substitute.For <IRandomization>();
            RandomizationProvider.Current.GetInt(0, 3).Returns(-2);

            var target = new IntegerChromosome(0, 3);

            Assert.AreEqual("11111111111111111111111111111110", target.ToString());

            target.FlipGene(0);
            Assert.AreEqual("01111111111111111111111111111110", target.ToString());

            target.FlipGene(1);
            Assert.AreEqual("00111111111111111111111111111110", target.ToString());

            target.FlipGene(10);
            Assert.AreEqual("00111111110111111111111111111110", target.ToString());

            target.FlipGene(31);
            Assert.AreEqual("00111111110111111111111111111111", target.ToString());

            target.FlipGene(30);
            Assert.AreEqual("00111111110111111111111111111101", target.ToString());
        }