public override void MutateGeneValueThrowsExceptionForWrongType()
        {
            IDomain domain = new CategoricalDomain <int>(new List <int> {
                1
            });

            Assert.Throws <ArgumentOutOfRangeException>(() => domain.MutateGeneValue(new Allele <double>(1.0), CategoricalDomainTest.dummyVariancePercentage));
        }
Exemplo n.º 2
0
        public void MutateDoesNotDepartFromUniformDistribution()
        {
            // Set up categorical domain with integer values 0 - 3.
            var possibleValues = new List <int> {
                0, 1, 2, 3
            };
            CategoricalDomain <int> domain = new CategoricalDomain <int>(possibleValues);

            // Remember which values were generated for a lot of iterations.
            double[]     observations = new double[CategoricalDomainTest.triesForRandomTests];
            Allele <int> geneValue    = new Allele <int>(1);

            for (int i = 0; i < CategoricalDomainTest.triesForRandomTests; i++)
            {
                observations[i] = (int)domain.MutateGeneValue(geneValue, CategoricalDomainTest.dummyVariancePercentage).GetValue();
            }

            // Apply the Chi-Squared test.
            ChiSquareTest uniformTest = new ChiSquareTest(observations, new UniformDiscreteDistribution(0, 3));

            Assert.False(
                uniformTest.Significant,
                $"Mutation was found to not produce a uniform distribution by the Chi-Squared test with significance level {uniformTest.Size}.");
        }