public void BinaryStringEntity_Indexer()
        {
            GeneticAlgorithm       algorithm = GetAlgorithm(3);
            TestBinaryStringEntity entity    = new TestBinaryStringEntity {
                MinimumStartingLength = 3, MaximumStartingLength = 3
            };

            entity.Initialize(algorithm);
            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(BinaryStringEntity)));

            BitArray genes = (BitArray)accessor.GetField("genes");

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

            entity[0] = true;
            Assert.True(genes[0]);
            Assert.False(genes[1]);
            Assert.False(genes[2]);
            Assert.True(entity[0]);
            entity[1] = true;
            Assert.True(genes[0]);
            Assert.True(genes[1]);
            Assert.False(genes[2]);
            Assert.True(entity[1]);
            entity[2] = true;
            Assert.True(genes[0]);
            Assert.True(genes[1]);
            Assert.True(genes[2]);
            Assert.True(entity[2]);
        }
        public void BinaryStringEntity_Initialize()
        {
            GeneticAlgorithm       algorithm = GetAlgorithm(4);
            TestBinaryStringEntity entity    = new TestBinaryStringEntity {
                MinimumStartingLength = 4, MaximumStartingLength = 4
            };

            RandomNumberService.Instance = new TestRandomUtil();
            entity.Initialize(algorithm);
            Assert.Equal("1010", entity.Representation);
        }
        public void BinaryStringEntity_CopyTo()
        {
            TestBinaryStringEntity entity  = GetEntity();
            TestBinaryStringEntity entity2 = new TestBinaryStringEntity();

            entity2.Initialize(entity.Algorithm);

            entity.CopyTo(entity2);

            CompareGeneticEntities(entity, entity2);
        }
        public void BinaryStringEntity_Ctor()
        {
            int size = 3;
            GeneticAlgorithm       algorithm = GetAlgorithm(size);
            TestBinaryStringEntity entity    = new TestBinaryStringEntity {
                MinimumStartingLength = size, MaximumStartingLength = size
            };

            entity.Initialize(algorithm);
            PrivateObject accessor = new PrivateObject(entity, new PrivateType(typeof(BinaryStringEntity)));

            Assert.Equal(size, entity.Length);
            Assert.Equal(size, ((BitArray)accessor.GetField("genes")).Length);
        }
        public void BinaryStringEntity_Length_SetToDifferentValue()
        {
            int length = 50;
            GeneticAlgorithm algorithm = GetAlgorithm(length);

            TestBinaryStringEntity entity = new TestBinaryStringEntity
            {
                MinimumStartingLength = length,
                MaximumStartingLength = length,
                IsFixedSize           = true
            };

            entity.Initialize(algorithm);
            Assert.Throws <ArgumentException>(() => entity.Length = 51);
        }
        public void BinaryStringEntity_Length()
        {
            int length = 50;
            GeneticAlgorithm algorithm = GetAlgorithm(length);

            TestBinaryStringEntity entity = new TestBinaryStringEntity {
                MinimumStartingLength = length, MaximumStartingLength = length
            };

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

            entity.Length = length;
            Assert.Equal(length, entity.Length);
        }
        public void BinaryStringEntity_Genes()
        {
            TestBinaryStringEntity entity = new TestBinaryStringEntity
            {
                MinimumStartingLength = 2,
                MaximumStartingLength = 2
            };

            entity.Initialize(new MockGeneticAlgorithm());

            BitArray bits = entity.GetGenes();

            Assert.Equal(entity.Length, bits.Length);

            for (int i = 0; i < bits.Length; i++)
            {
                Assert.Equal(entity[i], bits[i]);
            }
        }