Exemple #1
0
        public void TestSerialization_ShouldContinueWhereLeftOff()
        {
            var filename = "testsnap.bin";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            _config.SnapshotFilename           = filename;
            _config.SnapshotGenerationInterval = 1;
            _config.MaximumGenerations         = 5;

            _ea = new TestEA(_config, new DefaultRandomNumberGenerator());
            _ea.Evolve();
            File.Exists(filename).Should().BeTrue();

            _config.MaximumGenerations = 10;
            _ea = new TestEA(_config, new DefaultRandomNumberGenerator());
            _ea.NewGenerationEvent += (g) =>
            {
                g.Should().BeGreaterOrEqualTo(5);
            };
            _ea.Evolve();

            File.Delete(filename);
        }
Exemple #2
0
        public void TestSerialization_FileShouldNotExist_WhenDeactivated()
        {
            var filename = "testsnap.bin";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            _config.SnapshotFilename           = filename;
            _config.SnapshotGenerationInterval = 0;
            _config.MaximumGenerations         = 2;

            _ea = new TestEA(_config, new DefaultRandomNumberGenerator());
            _ea.Evolve();
            File.Exists(filename).Should().BeFalse();
        }
Exemple #3
0
        public void TestDurationTermination_ShouldTerminateWhenMaxDurationHasPassed()
        {
            var ok = false;

            _config.MaximumGenerations = 500000;
            _config.MaxDuration        = new TimeSpan(0, 0, 1);
            _ea = new TestEA(_config, new DefaultRandomNumberGenerator());
            _ea.TerminationEvent += (r) =>
            {
                if (r == TerminationReason.DurationLimitReached)
                {
                    ok = true;
                }
            };
            _ea.Evolve();

            Assert.IsTrue(ok);
            Assert.IsTrue(_ea.GetDuration < new TimeSpan(0, 0, 2));
        }
Exemple #4
0
        public void TestCalculateStatisticsConfig()
        {
            var statscounter1 = 0;

            _config.CalculateStatistics = true;
            var _ea = new TestEASeeded(_config, new DefaultRandomNumberGenerator());

            _ea.PopulationStatisticsCalculated += (s) => statscounter1++;
            _ea.Evolve();
            _ea.CalculateStatisticsCount.Should().Be(2);
            statscounter1.Should().Be(2);

            var statscounter2 = 0;

            _config.CalculateStatistics = false;
            _ea = new TestEASeeded(_config, new DefaultRandomNumberGenerator());
            _ea.PopulationStatisticsCalculated += (s) => statscounter2++;
            _ea.Evolve();
            _ea.CalculateStatisticsCount.Should().Be(2);
            statscounter2.Should().Be(0);
        }
Exemple #5
0
 public void EvolveShouldCallCreateMethodsCorrectNumberOfTimes()
 {
     _ea.Evolve();
     _ea.CreateRandomPhenotypeCount.Should().Be(10);
     _ea.CreatePhenotypeCount.Should().Be(10);
 }