Example #1
0
        public void HasReached_GenerationNumberLowerThanCondition_False()
        {
            var repository = new MockRepository();
            var ga         = repository.StrictMock <IGeneticAlgorithm>();

            using (repository.Ordered())
            {
                ga.Expect(g => g.GenerationsNumber).Return(1);
                ga.Expect(g => g.GenerationsNumber).Return(2);
                ga.Expect(g => g.GenerationsNumber).Return(3);
                ga.Expect(g => g.GenerationsNumber).Return(4);
                ga.Expect(g => g.GenerationsNumber).Return(5);
                ga.Expect(g => g.GenerationsNumber).Return(6);
                ga.Expect(g => g.GenerationsNumber).Return(7);
                ga.Expect(g => g.GenerationsNumber).Return(8);
                ga.Expect(g => g.GenerationsNumber).Return(0);
            }
            repository.ReplayAll();

            var target = new GenerationNumberTermination(10);

            Assert.IsFalse(target.HasReached(ga));

            for (int i = 0; i < 8; i++)
            {
                Assert.IsFalse(target.HasReached(ga));
            }
        }
        public void HasReached_GenerationNumberGreaterOrEqualThanCondition_True()
        {
            var ga = Substitute.For <IGeneticAlgorithm>();

            ga.GenerationsNumber.Returns(10, 11);

            var target = new GenerationNumberTermination(10);

            Assert.IsTrue(target.HasReached(ga));
            Assert.IsTrue(target.HasReached(ga));
        }
        public void HasReached_Returns_True_WhenGenerationCountIsLargerThanMaximalNumberOfGenerations()
        {
            var sot   = new GenerationNumberTermination(10);
            var state = new GenerationCountState();

            for (var i = 0; i < 10; i++)
            {
                Assert.False(sot.HasReached(null, state));
                state.UpdateOnGenerationRan(null);
            }
            Assert.True(sot.HasReached(null, state));
        }
        public void HasReached_GenerationNumberLowerThanCondition_False()
        {
            var ga = Substitute.For <IGeneticAlgorithm>();

            ga.GenerationsNumber.Returns(1, 2, 3, 4, 5, 6, 7, 8, 0);

            var target = new GenerationNumberTermination(10);

            Assert.IsFalse(target.HasReached(ga));

            for (int i = 0; i < 8; i++)
            {
                Assert.IsFalse(target.HasReached(ga));
            }
        }
Example #5
0
        public void HasReached_GenerationNumberGreaterOrEqualThanCondition_True()
        {
            var repository = new MockRepository();
            var ga         = repository.StrictMock <IGeneticAlgorithm> ();

            using (repository.Ordered()) {
                ga.Expect(g => g.GenerationsNumber).Return(10);
                ga.Expect(g => g.GenerationsNumber).Return(11);
            }
            repository.ReplayAll();

            var target = new GenerationNumberTermination(10);

            Assert.IsTrue(target.HasReached(ga));
            Assert.IsTrue(target.HasReached(ga));
        }
        public ITermination GenerationNumber()
        {
            var target = new GenerationNumberTermination(1);
            var ga     = Substitute.For <IGeneticAlgorithm>();

            ga.GenerationsNumber.Returns(1);
            target.HasReached(ga);

            return(target);
        }