BitChromosomeSwapMutationHandler.java

1
package net.bmahe.genetics4j.core.mutation.chromosome.swapmutation;
2
3
import java.util.BitSet;
4
import java.util.Objects;
5
import java.util.random.RandomGenerator;
6
7
import org.apache.commons.lang3.Validate;
8
9
import net.bmahe.genetics4j.core.chromosomes.BitChromosome;
10
import net.bmahe.genetics4j.core.chromosomes.Chromosome;
11
import net.bmahe.genetics4j.core.mutation.chromosome.ChromosomeMutationHandler;
12
import net.bmahe.genetics4j.core.spec.chromosome.BitChromosomeSpec;
13
import net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec;
14
import net.bmahe.genetics4j.core.spec.mutation.MutationPolicy;
15
import net.bmahe.genetics4j.core.spec.mutation.SwapMutation;
16
17
public class BitChromosomeSwapMutationHandler implements ChromosomeMutationHandler<BitChromosome> {
18
19
	private final RandomGenerator randomGenerator;
20
21
	public BitChromosomeSwapMutationHandler(final RandomGenerator _randomGenerator) {
22
		Objects.requireNonNull(_randomGenerator);
23
24 1 1. <init> : Removed assignment to member variable randomGenerator → SURVIVED
		this.randomGenerator = _randomGenerator;
25
	}
26
27
	@Override
28
	public boolean canHandle(final MutationPolicy mutationPolicy, final ChromosomeSpec chromosome) {
29
		Objects.requireNonNull(mutationPolicy);
30
		Objects.requireNonNull(chromosome);
31
32 9 1. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/swapmutation/BitChromosomeSwapMutationHandler::canHandle → SURVIVED
2. canHandle : removed conditional - replaced equality check with true → SURVIVED
3. canHandle : Substituted 0 with 1 → SURVIVED
4. canHandle : removed conditional - replaced equality check with true → SURVIVED
5. canHandle : negated conditional → KILLED
6. canHandle : removed conditional - replaced equality check with false → KILLED
7. canHandle : Substituted 1 with 0 → KILLED
8. canHandle : negated conditional → KILLED
9. canHandle : removed conditional - replaced equality check with false → KILLED
		return mutationPolicy instanceof SwapMutation && chromosome instanceof BitChromosomeSpec;
33
	}
34
35
	@Override
36
	public BitChromosome mutate(final MutationPolicy mutationPolicy, final Chromosome chromosome) {
37
		Objects.requireNonNull(mutationPolicy);
38
		Objects.requireNonNull(chromosome);
39
		Validate.isInstanceOf(SwapMutation.class, mutationPolicy);
40
		Validate.isInstanceOf(BitChromosome.class, chromosome);
41
42
		final SwapMutation swapMutation = (SwapMutation) mutationPolicy;
43 5 1. mutate : removed conditional - replaced equality check with false → NO_COVERAGE
2. mutate : removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::isNumSwapFixed → NO_COVERAGE
3. mutate : removed conditional - replaced equality check with true → NO_COVERAGE
4. mutate : negated conditional → NO_COVERAGE
5. mutate : removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::numSwap → NO_COVERAGE
		final int numSwap = swapMutation.isNumSwapFixed() ? swapMutation.numSwap()
44 5 1. mutate : removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::numSwap → NO_COVERAGE
2. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE
3. mutate : Substituted 1 with 0 → NO_COVERAGE
4. mutate : Replaced integer addition with subtraction → NO_COVERAGE
5. mutate : removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE
				: 1 + randomGenerator.nextInt(swapMutation.numSwap());
45
46
		final BitChromosome bitChromosome = (BitChromosome) chromosome;
47
48 2 1. mutate : removed call to java/util/BitSet::<init> → NO_COVERAGE
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE
		final BitSet newBitSet = new BitSet(bitChromosome.getNumAlleles());
49 6 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE
2. mutate : Substituted 0 with 1 → NO_COVERAGE
3. mutate : changed conditional boundary → NO_COVERAGE
4. mutate : negated conditional → NO_COVERAGE
5. mutate : removed conditional - replaced comparison check with true → NO_COVERAGE
6. mutate : removed conditional - replaced comparison check with false → NO_COVERAGE
		for (int i = 0; i < bitChromosome.getNumAlleles(); i++) {
50 2 1. mutate : removed call to java/util/BitSet::or → NO_COVERAGE
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getBitSet → NO_COVERAGE
			newBitSet.or(bitChromosome.getBitSet());
51
		}
52
53 5 1. mutate : negated conditional → NO_COVERAGE
2. mutate : changed conditional boundary → NO_COVERAGE
3. mutate : removed conditional - replaced comparison check with false → NO_COVERAGE
4. mutate : removed conditional - replaced comparison check with true → NO_COVERAGE
5. mutate : Substituted 0 with 1 → NO_COVERAGE
		for (int i = 0; i < numSwap; i++) {
54 3 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE
2. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE
3. mutate : removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE
			final int value1Index = randomGenerator.nextInt(bitChromosome.getNumAlleles());
55 3 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE
2. mutate : removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE
3. mutate : replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE
			final int value2Index = randomGenerator.nextInt(bitChromosome.getNumAlleles());
56
57 1 1. mutate : removed call to java/util/BitSet::get → NO_COVERAGE
			final boolean value1 = newBitSet.get(value1Index);
58 1 1. mutate : removed call to java/util/BitSet::get → NO_COVERAGE
			final boolean value2 = newBitSet.get(value2Index);
59
60 1 1. mutate : removed call to java/util/BitSet::set → NO_COVERAGE
			newBitSet.set(value1Index, value2);
61 1 1. mutate : removed call to java/util/BitSet::set → NO_COVERAGE
			newBitSet.set(value2Index, value1);
62
		}
63 2 1. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE
2. mutate : removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::<init> → NO_COVERAGE
		final BitChromosome newBitChromosome = new BitChromosome(bitChromosome.getNumAlleles(), newBitSet);
64
65 1 1. mutate : replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/swapmutation/BitChromosomeSwapMutationHandler::mutate → NO_COVERAGE
		return newBitChromosome;
66
	}
67
}

Mutations

24

1.1
Location : <init>
Killed by : none
Removed assignment to member variable randomGenerator → SURVIVED
Covering tests

32

1.1
Location : canHandle
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/core/mutation/chromosome/swapmutation/BitChromosomeSwapMutationHandler::canHandle → SURVIVED
Covering tests

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

3.3
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
negated conditional → KILLED

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

5.5
Location : canHandle
Killed by : none
Substituted 0 with 1 → SURVIVED Covering tests

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

7.7
Location : canHandle
Killed by : net.bmahe.genetics4j.core.mutation.SupersimpleTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.mutation.SupersimpleTest]/[method:simple()]
negated conditional → KILLED

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

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

43

1.1
Location : mutate
Killed by : none
removed conditional - replaced equality check with false → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::isNumSwapFixed → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed conditional - replaced equality check with true → NO_COVERAGE

4.4
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

5.5
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::numSwap → NO_COVERAGE

44

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/spec/mutation/SwapMutation::numSwap → NO_COVERAGE

2.2
Location : mutate
Killed by : none
replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE

3.3
Location : mutate
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

4.4
Location : mutate
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : mutate
Killed by : none
removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE

48

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::<init> → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE

49

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE

2.2
Location : mutate
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

3.3
Location : mutate
Killed by : none
changed conditional boundary → NO_COVERAGE

4.4
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

5.5
Location : mutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

6.6
Location : mutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

50

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::or → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getBitSet → NO_COVERAGE

53

1.1
Location : mutate
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : mutate
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed conditional - replaced comparison check with false → NO_COVERAGE

4.4
Location : mutate
Killed by : none
removed conditional - replaced comparison check with true → NO_COVERAGE

5.5
Location : mutate
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

54

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE

2.2
Location : mutate
Killed by : none
replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE

3.3
Location : mutate
Killed by : none
removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE

55

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to java/util/random/RandomGenerator::nextInt → NO_COVERAGE

3.3
Location : mutate
Killed by : none
replaced call to java/util/random/RandomGenerator::nextInt with argument → NO_COVERAGE

57

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::get → NO_COVERAGE

58

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::get → NO_COVERAGE

60

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::set → NO_COVERAGE

61

1.1
Location : mutate
Killed by : none
removed call to java/util/BitSet::set → NO_COVERAGE

63

1.1
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::getNumAlleles → NO_COVERAGE

2.2
Location : mutate
Killed by : none
removed call to net/bmahe/genetics4j/core/chromosomes/BitChromosome::<init> → NO_COVERAGE

65

1.1
Location : mutate
Killed by : none
replaced return value with null for net/bmahe/genetics4j/core/mutation/chromosome/swapmutation/BitChromosomeSwapMutationHandler::mutate → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.3