src/GenFx.Components.Tests/RouletteWheelSamplerTest.cs
/// <summary>
/// Tests that the GetEntity method works correctly.
/// </summary>
Tests that the GetEntity method works correctly.
Tests that the GetEntity method works correctly .
[Fact]
        public void RouletteWheelSampler_GetEntity()
        {
            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, 4));
            slices.Add(new WheelSlice(entity2, 2));
            slices.Add(new WheelSlice(entity3, 1));
            slices.Add(new WheelSlice(entity4, 3));
            TestRandomUtil randomUtil = new TestRandomUtil();
            RandomNumberService.Instance = randomUtil;
            randomUtil.Ratio = 0;
            GeneticEntity sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity1, sampledEntity);
            randomUtil.Ratio = .39999;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity1, sampledEntity);
            randomUtil.Ratio = .4;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity2, sampledEntity);
            randomUtil.Ratio = .59999;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity2, sampledEntity);
            randomUtil.Ratio = .6;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity3, sampledEntity);
            randomUtil.Ratio = .69999;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity3, sampledEntity);
            randomUtil.Ratio = .7;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity4, sampledEntity);
            randomUtil.Ratio = 1;
            sampledEntity = RouletteWheelSampler.GetEntity(slices);
            Assert.Same(entity4, sampledEntity);
        }
[ Fact ] public void RouletteWheelSampler_GetEntity ( ) { 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 , 4 ) ) ; slices . Add ( new WheelSlice ( entity2 , 2 ) ) ; slices . Add ( new WheelSlice ( entity3 , 1 ) ) ; slices . Add ( new WheelSlice ( entity4 , 3 ) ) ; TestRandomUtil randomUtil = new TestRandomUtil ( ) ; RandomNumberService . Instance = randomUtil ; randomUtil . Ratio = 0 ; GeneticEntity sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity1 , sampledEntity ) ; randomUtil . Ratio = .39999 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity1 , sampledEntity ) ; randomUtil . Ratio = .4 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity2 , sampledEntity ) ; randomUtil . Ratio = .59999 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity2 , sampledEntity ) ; randomUtil . Ratio = .6 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity3 , sampledEntity ) ; randomUtil . Ratio = .69999 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity3 , sampledEntity ) ; randomUtil . Ratio = .7 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity4 , sampledEntity ) ; randomUtil . Ratio = 1 ; sampledEntity = RouletteWheelSampler . GetEntity ( slices ) ; Assert . Same ( entity4 , sampledEntity ) ; }
Tests that the GetEntity method works correctly.
Tests that the GetEntity method works correctly .