src/GenFx.Components.Tests/BinaryStringEntityTest.cs
/// <summary>
/// Tests that the indexer works correctly.
///</summary>
Tests that the indexer works correctly.
Tests that the indexer works correctly .
[Fact]
        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]);
        }
[ Fact ] 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 ( " " ) ; 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 ] ) ; }
Tests that the indexer works correctly.
Tests that the indexer works correctly .