コード例 #1
0
 public void FitnessTrueTest()
 {
     double wantedBestResult = 19;
     ReachWantedResult target = new ReachWantedResult(wantedBestResult);
     bool actual = target.Fitness(_parents);
     Assert.IsTrue(actual);
     Assert.AreEqual(1, target.ActualCountOfReps);
 }
コード例 #2
0
        public void FitnessFalseTest()
        {
            double wantedBestResult = 20;
            ReachWantedResult target1 = new ReachWantedResult(wantedBestResult);
            bool actual = target1.Fitness(_parents);
            Assert.IsFalse(actual);
            Assert.AreEqual(wantedBestResult, target1.BestResult);

            wantedBestResult = 21;
            ReachWantedResult target2 = new ReachWantedResult(wantedBestResult);
            actual = target2.Fitness(_parents);
            Assert.IsFalse(actual);
            Assert.AreNotEqual(wantedBestResult, target2.BestResult);
        }
コード例 #3
0
        public void RunReachWantedResultTest()
        {
            _mutation = new NotRandomMutation();
            _selection = new TournamentSelection();
            _crossingover = new CyclicalCrossingover();

            int wantedResult = 6;
            IFitnessFunction fitnessFunction = new ReachWantedResult(wantedResult);
            int pCrossingover = 80;
            int pMutation = 60;
            Array.Sort(_closedTracks);
            double preBestResult = _closedTracks[0].GetTrackLength();
            GEngine target = new GEngine(_closedTracks, pCrossingover, pMutation, fitnessFunction, _mutation, _crossingover, _selection);
            target.Run();
            Assert.AreEqual(wantedResult, target.FitnessFunction.BestResult);
            Assert.IsTrue(preBestResult > target.FitnessFunction.BestResult);
        }