コード例 #1
0
        public void ToCanonicalString()
        {
            var c     = BitChromosome.Of(new BigInteger(234902));
            var value = c.ToCanonicalString();
            var sc    = BitChromosome.Of(value);

            Assert.Equal(c, sc);
        }
コード例 #2
0
        public void SeqTypes()
        {
            var c = BitChromosome.Of(100, 0.3);

            Assert.Equal(typeof(BitGeneImmutableSeq), c.ToSeq().GetType());
            Assert.Equal(typeof(BitGeneMutableSeq), c.ToSeq().Copy().GetType());
            Assert.Equal(typeof(BitGeneImmutableSeq), c.ToSeq().Copy().ToImmutableSeq().GetType());
        }
コード例 #3
0
        public void Zeros()
        {
            var c = BitChromosome.Of(1000, 0.5);

            var zeros = c.Zeros().Count();

            Assert.Equal(zeros, c.Length - c.BitCount());
            Assert.True(c.Zeros().All(i => !c.Get(i)));
        }
コード例 #4
0
        public void Ones()
        {
            var c = BitChromosome.Of(1000, 0.5);

            var ones = c.Ones().Count();

            Assert.Equal(ones, c.BitCount());
            Assert.True(c.Ones().All(i => c.Get(i)));
        }
コード例 #5
0
ファイル: GenotypeTest.cs プロジェクト: TiZott/jenetics.net
        public void TestGenotypeGenotypeOfT()
        {
            var c1 = BitChromosome.Of(12);
            var c2 = BitChromosome.Of(12);
            var g2 = Genotype.Of(c1, c2, c2);
            var g4 = g2;

            Assert.Equal(g4, g2);
            Assert.Equal(g4.GetHashCode(), g2.GetHashCode());
        }
コード例 #6
0
        public void ToBitSet()
        {
            var c1 = BitChromosome.Of(34);
            var c2 = BitChromosome.Of(c1.ToBitSet(), 34);

            for (var i = 0; i < c1.Length; ++i)
            {
                Assert.Equal(c1.GetGene(i).GetBit(), c2.GetGene(i).GetBit());
            }
        }
コード例 #7
0
        public void ToBigInteger()
        {
            var data = new byte[1056];

            RandomRegistry.GetRandom().NextBytes(data);
            var value      = new BigInteger(data);
            var chromosome = BitChromosome.Of(value);

            Assert.Equal(chromosome.ToBigInteger(), value);
        }
コード例 #8
0
        public void BitSetBitCount(double p)
        {
            const int size  = 1000;
            var       @base = BitChromosome.Of(size, p);

            for (var i = 0; i < 1000; ++i)
            {
                var other = @base.NewInstance();
                Assert.Equal(other.BitCount(), other.ToBitSet().OfType <bool>().Count(bit => bit));
            }
        }
コード例 #9
0
        public void NumValue()
        {
            var c1 = BitChromosome.Of(10);

            var value = c1.IntValue();

            Assert.Equal((short)value, c1.ShortValue());
            Assert.Equal(value, c1.LongValue());
            Assert.Equal(value, c1.FloatValue());
            Assert.Equal((double)value, c1.DoubleValue());
        }
コード例 #10
0
        public void FromByteArrayBitSet()
        {
            var random = RandomRegistry.GetRandom();
            var bytes  = new byte[234];

            random.NextBytes(bytes);

            var bits = new BitArray(bytes);
            var c    = BitChromosome.Of(bits);

            Assert.Equal(bytes, c.ToByteArray());
            Assert.Equal(bytes, bits.ToByteArray());
        }
コード例 #11
0
        public void NewInstance()
        {
            const int size  = 50000;
            var       @base = BitChromosome.Of(size, 0.5);

            for (var i = 0; i < 100; ++i)
            {
                var other = @base.NewInstance();
                Assert.NotEqual(@base, other);

                Assert.True(Math.Abs(1 - other.BitCount() / (size / 2.0)) < 0.02);
            }
        }
コード例 #12
0
        public void BitCount(double p)
        {
            const int size  = 1000;
            var       @base = BitChromosome.Of(size, p);

            for (var i = 0; i < 1000; ++i)
            {
                var other = @base.NewInstance();

                var bitCount = other.Count(gene => gene.BooleanValue());

                Assert.Equal(bitCount, other.BitCount());
            }
        }
コード例 #13
0
        public void FromBitSet()
        {
            var random = RandomRegistry.GetRandom();
            var bits   = new BitArray(2343);

            for (var i = 0; i < bits.Count; ++i)
            {
                bits[i] = random.NextBoolean();
            }

            var c = BitChromosome.Of(bits);

            Assert.Equal(bits.ToByteArray(), c.ToByteArray());
        }
コード例 #14
0
        public void Invert()
        {
            var c1 = BitChromosome.Of(100, 0.3);
            var c3 = c1.Invert();

            for (var i = 0; i < c1.Length; ++i)
            {
                Assert.True(c1.GetGene(i).GetBit() != c3.GetGene(i).GetBit());
            }

            var c4 = c3.Invert();

            Assert.Equal(c1, c4);
        }
コード例 #15
0
        public void IntProbability()
        {
            var c = BitChromosome.Of(10, 0);

            foreach (var g in c)
            {
                Assert.False(g.GetBit());
            }

            c = BitChromosome.Of(10, 1);
            foreach (var g in c)
            {
                Assert.True(g.GetBit());
            }
        }
コード例 #16
0
        public void BitChromosomeBitSet()
        {
            var bits = new BitArray(10);

            for (var i = 0; i < 10; ++i)
            {
                bits[i] = i % 2 == 0;
            }

            var c = BitChromosome.Of(bits);

            for (var i = 0; i < bits.Length; ++i)
            {
                Assert.Equal(c.GetGene(i).GetBit(), i % 2 == 0);
            }
        }
コード例 #17
0
 protected override Factory <IChromosome <BitGene> > Factory()
 {
     return(() => BitChromosome.Of(500, 0.3));
 }