Пример #1
0
        public void ValueOfZeroLength()
        {
            const int length  = 0;
            var       alleles = MutableSeq.OfLength <int>(length).Fill(Factories.Int()).ToImmutableSeq();

            Assert.Throws <ArgumentException>(() => EnumGene.Of(alleles));
        }
Пример #2
0
        public void InvalidChromosome()
        {
            var alleles = ImmutableSeq.Of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            var gene    = new EnumGene <int>(3, alleles);
            var genes   = MutableSeq.OfLength <EnumGene <int> >(10).Fill(() => gene).ToImmutableSeq();

            var chromosome = new PermutationChromosome <int>(genes);

            Assert.False(chromosome.IsValid);
        }
Пример #3
0
        public override void IsValid()
        {
            var alleles = Enumerable.Range(0, 100).ToImmutableSeq();

            var genes = Base.Subset(100, 10).Select(i => EnumGene.Of(i, alleles)).ToImmutableSeq();

            var ch = new PermutationChromosome <int>(genes);

            Assert.True(ch.IsValid);
            Assert.Equal(10, ch.Length);
        }
Пример #4
0
        public int CompareTo(EnumGene <TAllele> gene)
        {
            var result = 0;

            if (_alleleIndex > gene._alleleIndex)
            {
                result = 1;
            }
            else if (_alleleIndex < gene._alleleIndex)
            {
                result = -1;
            }

            return(result);
        }