IntChromosomeRandomMutationHandler.java

1
package net.bmahe.genetics4j.core.mutation.chromosome.randommutation;
2
3
import java.util.Arrays;
4
import java.util.random.RandomGenerator;
5
6
import org.apache.commons.lang3.Validate;
7
8
import net.bmahe.genetics4j.core.chromosomes.Chromosome;
9
import net.bmahe.genetics4j.core.chromosomes.IntChromosome;
10
import net.bmahe.genetics4j.core.mutation.chromosome.ChromosomeMutationHandler;
11
import net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec;
12
import net.bmahe.genetics4j.core.spec.chromosome.IntChromosomeSpec;
13
import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy;
14
import net.bmahe.genetics4j.core.spec.mutation.RandomMutation;
15
16
public class IntChromosomeRandomMutationHandler implements ChromosomeMutationHandler<IntChromosome> {
17
18
	private final RandomGenerator randomGenerator;
19
20
	public IntChromosomeRandomMutationHandler(final RandomGenerator _randomGenerator) {
21
		Validate.notNull(_randomGenerator);
22
23 1 1. <init> : Removed assignment to member variable randomGenerator → KILLED
		this.randomGenerator = _randomGenerator;
24
	}
25
26
	@Override
27
	public boolean canHandle(final MutationPolicy mutationPolicy, final ChromosomeSpec chromosome) {
28
		Validate.notNull(mutationPolicy);
29
		Validate.notNull(chromosome);
30
31 9 1. canHandle : removed conditional - replaced equality check with true → SURVIVED
2. canHandle : negated conditional → KILLED
3. canHandle : Substituted 1 with 0 → KILLED
4. canHandle : removed conditional - replaced equality check with false → KILLED
5. canHandle : Substituted 0 with 1 → KILLED
6. canHandle : removed conditional - replaced equality check with false → KILLED
7. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/IntChromosomeRandomMutationHandler::canHandle → KILLED
8. canHandle : negated conditional → KILLED
9. canHandle : removed conditional - replaced equality check with true → KILLED
		return mutationPolicy instanceof RandomMutation && chromosome instanceof IntChromosomeSpec;
32
	}
33
34
	@Override
35
	public IntChromosome mutate(final MutationPolicy mutationPolicy, final Chromosome chromosome) {
36
		Validate.notNull(mutationPolicy);
37
		Validate.notNull(chromosome);
38
		Validate.isInstanceOf(RandomMutation.class, mutationPolicy);
39
		Validate.isInstanceOf(IntChromosome.class, chromosome);
40
41
		final IntChromosome intChromosome = (IntChromosome) chromosome;
42
43 4 1. mutate : replaced call to java/util/Arrays::copyOf with argument → SURVIVED
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getNumAlleles → KILLED
3. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getValues → KILLED
4. mutate : removed call to java/util/Arrays::copyOf → KILLED
		final int[] newValues = Arrays.copyOf(intChromosome.getValues(), intChromosome.getNumAlleles());
44
45 3 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getNumAlleles → KILLED
2. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
3. mutate : removed call to java/util/random/RandomGenerator::nextInt → KILLED
		final int alleleFlipIndex = randomGenerator.nextInt(intChromosome.getNumAlleles());
46 5 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED
2. mutate : Replaced integer subtraction with addition → SURVIVED
3. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
4. mutate : removed call to java/util/random/RandomGenerator::nextInt → KILLED
5. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMaxValue → KILLED
		newValues[alleleFlipIndex] = randomGenerator.nextInt(intChromosome.getMaxValue() - intChromosome.getMinValue())
47 2 1. mutate : Replaced integer addition with subtraction → SURVIVED
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED
				+ intChromosome.getMinValue();
48
49 5 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMaxValue → SURVIVED
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED
3. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::<init> → KILLED
4. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getSize → KILLED
5. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/IntChromosomeRandomMutationHandler::mutate → KILLED
		return new IntChromosome(intChromosome.getSize(), intChromosome.getMinValue(), intChromosome.getMaxValue(),
50
				newValues);
51
	}
52
}

Mutations

23

1.1
Location : <init>
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
Removed assignment to member variable randomGenerator → KILLED

31

1.1
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
negated conditional → KILLED

2.2
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
Substituted 1 with 0 → KILLED

3.3
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
removed conditional - replaced equality check with false → KILLED

4.4
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
Substituted 0 with 1 → KILLED

5.5
Location : canHandle
Killed by : none
removed conditional - replaced equality check with true → SURVIVED
Covering tests

6.6
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
removed conditional - replaced equality check with false → KILLED

7.7
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/IntChromosomeRandomMutationHandler::canHandle → KILLED

8.8
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
negated conditional → KILLED

9.9
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:canHandle()]
removed conditional - replaced equality check with true → KILLED

43

1.1
Location : mutate
Killed by : none
replaced call to java/util/Arrays::copyOf with argument → SURVIVED
Covering tests

2.2
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getNumAlleles → KILLED

3.3
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getValues → KILLED

4.4
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to java/util/Arrays::copyOf → KILLED

45

1.1
Location : mutate
Killed by : net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithIntChromosome()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getNumAlleles → KILLED

2.2
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED

3.3
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to java/util/random/RandomGenerator::nextInt → KILLED

46

1.1
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED

2.2
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to java/util/random/RandomGenerator::nextInt → KILLED

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED
Covering tests

4.4
Location : mutate
Killed by : net.bmahe.genetics4j.core.EASystemTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.EASystemTest]/[method:testEvolveWithIntChromosome()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMaxValue → KILLED

5.5
Location : mutate
Killed by : none
Replaced integer subtraction with addition → SURVIVED Covering tests

47

1.1
Location : mutate
Killed by : none
Replaced integer addition with subtraction → SURVIVED
Covering tests

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED Covering tests

49

1.1
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::<init> → KILLED

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMaxValue → SURVIVED
Covering tests

3.3
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getMinValue → SURVIVED Covering tests

4.4
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
removed call to net/bmahe/genetics4j/core/chromosomes/IntChromosome::getSize → KILLED

5.5
Location : mutate
Killed by : net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.chromosome.randommutation.IntChromosomeRandomMutationHandlerTest]/[method:mutateValidate()]
replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/randommutation/IntChromosomeRandomMutationHandler::mutate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.19.6