src/GenFx.Components.Tests/RouletteWheelSamplerTest.cs
/// <summary>
/// Tests that the GetEntity method returns a random entity when no wheel slices sizes are set.
/// </summary>
Tests that the GetEntity method returns a random entity when no wheel slices sizes are set.
Tests that the GetEntity method returns a random entity when no wheel slices sizes are set .
[Fact]
        public void RouletteWheelSampler_GetEntity_NoSizes()
        {
            MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                GeneticEntitySeed = new MockEntity(),
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                PopulationSeed = new MockPopulation()
            };
            List<WheelSlice> slices = new List<WheelSlice>();
            MockEntity entity1 = new MockEntity();
            entity1.Initialize(algorithm);
            MockEntity entity2 = new MockEntity();
            entity2.Initialize(algorithm);
            MockEntity entity3 = new MockEntity();
            entity3.Initialize(algorithm);
            MockEntity entity4 = new MockEntity();
            entity4.Initialize(algorithm);
            slices.Add(new WheelSlice(entity1, 0));
            slices.Add(new WheelSlice(entity2, 0));
            slices.Add(new WheelSlice(entity3, 0));
            slices.Add(new WheelSlice(entity4, 0));
            TestRandomUtil randomUtil = new TestRandomUtil();
            RandomNumberService.Instance = randomUtil;
            randomUtil.RandomValue = 2;
            GeneticEntity sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Equal(4, randomUtil.MaxValuePassed);
            Assert.Same(entity3, sampledEntity);
        }
[ Fact ] public void RouletteWheelSampler_GetEntity_NoSizes ( ) { MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm { GeneticEntitySeed = new MockEntity ( ) , SelectionOperator = new MockSelectionOperator ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , PopulationSeed = new MockPopulation ( ) } ; List < WheelSlice > slices = new List < WheelSlice > ( ) ; MockEntity entity1 = new MockEntity ( ) ; entity1 . Initialize ( algorithm ) ; MockEntity entity2 = new MockEntity ( ) ; entity2 . Initialize ( algorithm ) ; MockEntity entity3 = new MockEntity ( ) ; entity3 . Initialize ( algorithm ) ; MockEntity entity4 = new MockEntity ( ) ; entity4 . Initialize ( algorithm ) ; slices . Add ( new WheelSlice ( entity1 , 0 ) ) ; slices . Add ( new WheelSlice ( entity2 , 0 ) ) ; slices . Add ( new WheelSlice ( entity3 , 0 ) ) ; slices . Add ( new WheelSlice ( entity4 , 0 ) ) ; TestRandomUtil randomUtil = new TestRandomUtil ( ) ; RandomNumberService . Instance = randomUtil ; randomUtil . RandomValue = 2 ; GeneticEntity sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Equal ( 4 , randomUtil . MaxValuePassed ) ; Assert . Same ( entity3 , sampledEntity ) ; }
Tests that the GetEntity method returns a random entity when no wheel slices sizes are set.
Tests that the GetEntity method returns a random entity when no wheel slices sizes are set .