Exemple #1
0
        public void GenotypeGeneratorBreederWithoutIndexTest()
        {
            GenotypeGeneratorBreeder<ListGenotype<FloatGene>>.BreederDelegateWithoutIndex withoutIndex =
                () => new ListGenotype<FloatGene>(
                    Enumerable.Range(0, 10).ToList().Select(i => new FloatGene(i)));

            GenotypeGeneratorBreeder<ListGenotype<FloatGene>> breederWithoutIndex =
                new GenotypeGeneratorBreeder<ListGenotype<FloatGene>>(withoutIndex, 100);

            IList<ListGenotype<FloatGene>> genotypesWithoutIndex = breederWithoutIndex.Breed();

            Assert.AreEqual(100, genotypesWithoutIndex.Count);

            foreach (ListGenotype<FloatGene> genotype in genotypesWithoutIndex)
            {
                Assert.AreEqual(10, genotype.Count);

                for (int j = 0; j < genotype.Count; j++)
                {
                    Assert.AreEqual(j, genotype[j].Value);
                }
            }
        }
Exemple #2
0
        public void GenotypeGeneratorBreederWithIndexTest()
        {
            GenotypeGeneratorBreeder<ListGenotype<FloatGene>>.BreederDelegateWithIndex withIndex =
                index => new ListGenotype<FloatGene>(
                    Enumerable.Range(0, 200).ToList().Select(i => new FloatGene(index*i)));

            GenotypeGeneratorBreeder<ListGenotype<FloatGene>> breederWithIndex =
                new GenotypeGeneratorBreeder<ListGenotype<FloatGene>>(withIndex, 500);

            IList<ListGenotype<FloatGene>> genotypesWithIndex = breederWithIndex.Breed();

            Assert.AreEqual(500, genotypesWithIndex.Count);

            for (int i = 0; i < genotypesWithIndex.Count; i++)
            {
                Assert.AreEqual(200, genotypesWithIndex[i].Count);

                for (int j = 0; j < genotypesWithIndex[i].Count; j++)
                {
                    Assert.AreEqual(i*j, genotypesWithIndex[i][j].Value);
                }
            }
        }