src/GenFx.Components.Tests/SigmaScalingStrategyTest.cs
/// <summary>
/// Tests that the Scale method works correctly.
/// </summary>
Tests that the Scale method works correctly.
Tests that the Scale method works correctly .
[Fact]
        public void SigmaScalingStrategy_Scale_Multiplier5()
        {
            GeneticAlgorithm algorithm = GetAlgorithm(5);
            SigmaScalingStrategy strategy = new SigmaScalingStrategy { Multiplier = 5 };
            strategy.Initialize(algorithm);
            SimplePopulation population = new SimplePopulation();
            population.Initialize(algorithm);
            PrivateObject populationAccessor = new PrivateObject(population, new PrivateType(typeof(Population)));
            AddEntity(algorithm, 4, population);
            AddEntity(algorithm, 10, population);
            AddEntity(algorithm, 20, population);
            AddEntity(algorithm, 0, population);
            populationAccessor.SetField("rawMean", (double)(4 + 10 + 20) / 4);
            populationAccessor.SetField("rawStandardDeviation", MathHelper.GetStandardDeviation(population.Entities, population.RawMean.Value, FitnessType.Raw));
            strategy.Scale(population);
            Assert.Equal(33.17, Math.Round(population.Entities[0].ScaledFitnessValue, 2));
            Assert.Equal(39.17, Math.Round(population.Entities[1].ScaledFitnessValue, 2));
            Assert.Equal(49.17, Math.Round(population.Entities[2].ScaledFitnessValue, 2));
            Assert.Equal(29.17, Math.Round(population.Entities[3].ScaledFitnessValue, 2));
        }
[ Fact ] public void SigmaScalingStrategy_Scale_Multiplier5 ( ) { GeneticAlgorithm algorithm = GetAlgorithm ( 5 ) ; SigmaScalingStrategy strategy = new SigmaScalingStrategy { Multiplier = 5 } ; strategy . Initialize ( algorithm ) ; SimplePopulation population = new SimplePopulation ( ) ; population . Initialize ( algorithm ) ; PrivateObject populationAccessor = new PrivateObject ( population , new PrivateType ( typeof ( Population ) ) ) ; AddEntity ( algorithm , 4 , population ) ; AddEntity ( algorithm , 10 , population ) ; AddEntity ( algorithm , 20 , population ) ; AddEntity ( algorithm , 0 , population ) ; populationAccessor . SetField ( " " , ( double ) ( 4 + 10 + 20 ) / 4 ) ; populationAccessor . SetField ( " " , MathHelper . GetStandardDeviation ( population . Entities , population . RawMean . Value , FitnessType . Raw ) ) ; strategy . Scale ( population ) ; Assert . Equal ( 33.17 , Math . Round ( population . Entities [ 0 ] . ScaledFitnessValue , 2 ) ) ; Assert . Equal ( 39.17 , Math . Round ( population . Entities [ 1 ] . ScaledFitnessValue , 2 ) ) ; Assert . Equal ( 49.17 , Math . Round ( population . Entities [ 2 ] . ScaledFitnessValue , 2 ) ) ; Assert . Equal ( 29.17 , Math . Round ( population . Entities [ 3 ] . ScaledFitnessValue , 2 ) ) ; }
Tests that the Scale method works correctly.
Tests that the Scale method works correctly .