private void TestMutation(int firstRandomValue, int secondRandomValue, int[] expectedValues) { ListShiftMutationOperator op = new ListShiftMutationOperator { MutationRate = 1 }; RandomNumberService.Instance = new FakeRandomNumberService(firstRandomValue, secondRandomValue); IntegerListEntity entity = new IntegerListEntity { MinimumStartingLength = 5, MaximumStartingLength = 5, }; entity.Initialize(new MockGeneticAlgorithm()); for (int i = 0; i < 5; i++) { entity[i] = i; } IntegerListEntity result = (IntegerListEntity)op.Mutate(entity); Assert.Equal(expectedValues, result); }
public void ListShiftMutationOperator_GenerateMutation_NullEntity() { ListShiftMutationOperator op = new ListShiftMutationOperator(); PrivateObject accessor = new PrivateObject(op); Assert.Throws <ArgumentNullException>(() => accessor.Invoke("GenerateMutation", (GeneticEntity)null)); }
public void ListShiftMutationOperator_GenerateMutation_NoMutation() { ListShiftMutationOperator op = new ListShiftMutationOperator { MutationRate = 0 }; PrivateObject accessor = new PrivateObject(op); bool result = (bool)accessor.Invoke("GenerateMutation", new IntegerListEntity()); Assert.False(result); }