public void IntegerListEntity_Indexer()
        {
            GeneticAlgorithm  algorithm = GetAlgorithm(3);
            IntegerListEntity entity    = new TestIntegerListEntity {
                MinimumStartingLength = 3, MaximumStartingLength = 3
            };

            entity.Initialize(algorithm);
            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(ListEntity <int>)));
            List <int>    genes    = (List <int>)accessor.GetField("genes");

            for (int i = 0; i < genes.Count; i++)
            {
                genes[i] = 0;
            }

            entity[0] = 1;
            Assert.Equal(1, genes[0]);
            Assert.Equal(0, genes[1]);
            Assert.Equal(0, genes[2]);
            Assert.Equal(1, entity[0]);
            entity[1] = 2;
            Assert.Equal(1, genes[0]);
            Assert.Equal(2, genes[1]);
            Assert.Equal(0, genes[2]);
            Assert.Equal(2, entity[1]);
            entity[2] = 3;
            Assert.Equal(1, genes[0]);
            Assert.Equal(2, genes[1]);
            Assert.Equal(3, genes[2]);
            Assert.Equal(3, entity[2]);
        }
        public void IntegerListEntity_CopyTo()
        {
            IntegerListEntity entity  = GetEntity();
            IntegerListEntity entity2 = new TestIntegerListEntity();

            entity2.Initialize(GetAlgorithm(4));

            entity.CopyTo(entity2);

            CompareGeneticEntities(entity, entity2);
        }
        public void IntegerListEntity_Initialize()
        {
            RandomNumberService.Instance = new TestRandomUtil();

            GeneticAlgorithm  algorithm = GetAlgorithm(4);
            IntegerListEntity entity    = new TestIntegerListEntity {
                MinimumStartingLength = 4, MaximumStartingLength = 4
            };

            entity.Initialize(algorithm);

            Assert.Equal("1, 2, 3, 4", entity.Representation);
        }
        public void IntegerListEntity_Ctor()
        {
            int size = 3;
            GeneticAlgorithm  algorithm = GetAlgorithm(size);
            IntegerListEntity entity    = new TestIntegerListEntity {
                MinimumStartingLength = size, MaximumStartingLength = size
            };

            entity.Initialize(algorithm);
            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(ListEntity <int>)));

            Assert.Equal(size, entity.Length);
            Assert.Equal(size, ((List <int>)accessor.GetField("genes")).Count);
        }
        public void IntegerListEntity_Length()
        {
            int length = 50;
            GeneticAlgorithm algorithm = GetAlgorithm(length);

            IntegerListEntity entity = new TestIntegerListEntity {
                MinimumStartingLength = length, MaximumStartingLength = length
            };

            entity.Initialize(algorithm);
            Assert.Equal(length, entity.Length);

            entity.Length = length;
            Assert.Equal(length, entity.Length);
        }
        private static IntegerListEntity GetEntity()
        {
            GeneticAlgorithm algorithm = GetAlgorithm(4);

            TestIntegerListEntity entity = new TestIntegerListEntity {
                MinimumStartingLength = 4, MaximumStartingLength = 4
            };

            entity.Initialize(algorithm);
            entity[0] = 5;
            entity[1] = 3;
            entity[2] = 10;
            entity[3] = 127;

            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(GeneticEntity)));

            entity.Age = 3;
            accessor.SetField("rawFitnessValue", 1);
            entity.ScaledFitnessValue = 2;

            return(entity);
        }