public void Mutate_NoArgs_BitMutated()
        {
            RandomizationProvider.Current = Substitute.For <IRandomization>();
            RandomizationProvider.Current.GetInt(0, 3).Returns(1);

            var target     = new FlipBitMutation();
            var chromosome = new BinaryChromosomeStub(3);

            chromosome.ReplaceGenes(0, new Gene[]
            {
                new Gene(0),
                new Gene(0),
                new Gene(0)
            });

            target.Mutate(chromosome, 1);
            Assert.AreEqual(0, chromosome.GetGene(0).Value);
            Assert.AreEqual(1, chromosome.GetGene(1).Value);
            Assert.AreEqual(0, chromosome.GetGene(2).Value);
        }
Esempio n. 2
0
        public void Mutate_NoArgs_BitMutated()
        {
            RandomizationProvider.Current = MockRepository.GenerateMock <IRandomization>();
            RandomizationProvider.Current.Expect(r => r.GetInt(0, 3)).Return(1);

            var target     = new FlipBitMutation();
            var chromosome = new BinaryChromosomeStub(3);

            chromosome.ReplaceGenes(0, new Gene[]
            {
                new Gene(0),
                new Gene(0),
                new Gene(0)
            });

            target.Mutate(chromosome, 1);
            Assert.AreEqual(0, chromosome.GetGene(0).Value);
            Assert.AreEqual(1, chromosome.GetGene(1).Value);
            Assert.AreEqual(0, chromosome.GetGene(2).Value);

            RandomizationProvider.Current.VerifyAllExpectations();
        }