public void WhenInitialiserIsOverloaded_RequestReturnsOverloadedInitialiser() { NewByteBasedGenomeInitialiser newByteInitialiser = new NewByteBasedGenomeInitialiser(); InitialiserProvider.AddInitialiser(newByteInitialiser); var initialiser = InitialiserProvider.GetInitialiser <byte> (); Assert.AreEqual(newByteInitialiser.Name, initialiser.Name); }
public void WhenMutationIsSetToVariance_Double_CheckedOverflow_MutationLessThanMinFloorAtMin() { var population = new Population <double> (); (InitialiserContextProvider.GetContext <double> () as DoubleBasedGenomeInitialiserContext).Min = 10d; (InitialiserContextProvider.GetContext <double> () as DoubleBasedGenomeInitialiserContext).Max = 110d; DoubleBasedSingleInitialiser initialiser = new DoubleBasedSingleInitialiser( (InitialiserContextProvider.GetContext <double> () as DoubleBasedGenomeInitialiserContext).Min); InitialiserProvider.AddInitialiser(initialiser); var genomeLength = 100000; population.Initialise(1, genomeLength); ConfigurationProvider.Mutation.AllowUncheckedVariance = false; ConfigurationProvider.Mutation.ChanceOfMutation = 1; ConfigurationProvider.Mutation.ContextMutationVariance = .1; ConfigurationProvider.Mutation.MutationMethod = MutationConfiguration.MutationStyle.Variance; Mutator <double> mutator = MutationProvider.GetMutator <double> (); mutator.Mutate(population); int underflowCount = 0; population [0].Code.ForEach(i => { underflowCount += i == (InitialiserContextProvider.GetContext <double> () as DoubleBasedGenomeInitialiserContext).Min ? 1 : 0; }); double acceptableMin = (double)genomeLength * ((double)4.5d / 10); double acceptableMax = (double)genomeLength * ((double)5.5d / 10); Assert.LessOrEqual(underflowCount, acceptableMax); Assert.GreaterOrEqual(underflowCount, acceptableMin); }
public void WhenMutationIsSetToVariance_Byte_UncheckedOverflow_MutationLessThanMinUnderflowToMax() { Population <byte> population = new Population <byte> (); (InitialiserContextProvider.GetContext <byte> () as ByteBasedGenomeInitialiserContext).Min = 0; (InitialiserContextProvider.GetContext <byte> () as ByteBasedGenomeInitialiserContext).Max = 100; ByteBasedSingleInitialiser initialiser = new ByteBasedSingleInitialiser( (InitialiserContextProvider.GetContext <byte> () as ByteBasedGenomeInitialiserContext).Min); InitialiserProvider.AddInitialiser(initialiser); var genomeLength = 1000; population.Initialise(1, genomeLength); ConfigurationProvider.Mutation.AllowUncheckedVariance = true; ConfigurationProvider.Mutation.ChanceOfMutation = 1; ConfigurationProvider.Mutation.ContextMutationVariance = .1; ConfigurationProvider.Mutation.MutationMethod = MutationConfiguration.MutationStyle.Variance; Mutator <byte> mutator = MutationProvider.GetMutator <byte> (); mutator.Mutate(population); int overflowCount = 0; population [0].Code.ForEach(i => { overflowCount += i >= 90 ? 1 : 0; }); double acceptableMin = (double)genomeLength * ((double)4.5d / 10); double acceptableMax = (double)genomeLength * ((double)5.5d / 10); Assert.LessOrEqual(overflowCount, acceptableMax); Assert.GreaterOrEqual(overflowCount, acceptableMin); }