RandomSelectionPolicyHandler.java

1
package net.bmahe.genetics4j.core.selection;
2
3
import java.util.List;
4
import java.util.random.RandomGenerator;
5
6
import org.apache.commons.lang3.Validate;
7
8
import net.bmahe.genetics4j.core.Genotype;
9
import net.bmahe.genetics4j.core.Population;
10
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration;
11
import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext;
12
import net.bmahe.genetics4j.core.spec.selection.RandomSelection;
13
import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy;
14
15
public class RandomSelectionPolicyHandler<T extends Comparable<T>> implements SelectionPolicyHandler<T> {
16
17
	private final RandomGenerator randomGenerator;
18
19
	public RandomSelectionPolicyHandler(final RandomGenerator _randomGenerator) {
20
		Validate.notNull(_randomGenerator);
21
22 1 1. <init> : Removed assignment to member variable randomGenerator → KILLED
		this.randomGenerator = _randomGenerator;
23
	}
24
25
	@Override
26
	public boolean canHandle(final SelectionPolicy selectionPolicy) {
27
		Validate.notNull(selectionPolicy);
28 2 1. canHandle : replaced boolean return with true for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::canHandle → KILLED
2. canHandle : replaced boolean return with false for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::canHandle → KILLED
		return selectionPolicy instanceof RandomSelection;
29
	}
30
31
	@Override
32
	public Selector<T> resolve(final AbstractEAExecutionContext<T> eaExecutionContext,
33
			final AbstractEAConfiguration<T> eaConfiguration,
34
			final SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver,
35
			final SelectionPolicy selectionPolicy) {
36
		Validate.notNull(selectionPolicy);
37
		Validate.isInstanceOf(RandomSelection.class, selectionPolicy);
38
39 3 1. resolve : removed call to net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler$1::<init> → KILLED
2. <init> : Removed assignment to member variable this$0 → KILLED
3. resolve : replaced return value with null for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::resolve → KILLED
		return new Selector<T>() {
40
41
			@Override
42
			public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final int numIndividuals,
43
					final List<Genotype> population, final List<T> fitnessScore) {
44
				Validate.notNull(eaConfiguration);
45
				Validate.notNull(population);
46
				Validate.notNull(fitnessScore);
47
				Validate.isTrue(numIndividuals > 0);
48
				Validate.isTrue(population.size() > 0);
49
				Validate.isTrue(fitnessScore.size() > 0);
50
				Validate.isTrue(fitnessScore.size() == population.size());
51
52 1 1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
				final Population<T> selected = new Population<>();
53
54 5 1. select : removed conditional - replaced comparison check with true → TIMED_OUT
2. select : changed conditional boundary → KILLED
3. select : Substituted 0 with 1 → KILLED
4. select : removed conditional - replaced comparison check with false → KILLED
5. select : negated conditional → KILLED
				for (int i = 0; i < numIndividuals; i++) {
55 3 1. select : removed call to java/util/List::size → SURVIVED
2. select : replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED
3. select : removed call to java/util/random/RandomGenerator::nextInt → KILLED
					final int selectedIndex = randomGenerator.nextInt(population.size());
56 3 1. select : removed call to net/bmahe/genetics4j/core/Population::add → KILLED
2. select : removed call to java/util/List::get → KILLED
3. select : removed call to java/util/List::get → KILLED
					selected.add(population.get(selectedIndex), fitnessScore.get(selectedIndex));
57
				}
58 1 1. select : replaced return value with null for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler$1::select → KILLED
				return selected;
59
			}
60
		};
61
	}
62
}

Mutations

22

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

28

1.1
Location : canHandle
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:canHandle()]
replaced boolean return with true for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::canHandle → KILLED

2.2
Location : canHandle
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:canHandle()]
replaced boolean return with false for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::canHandle → KILLED

39

1.1
Location : resolve
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler$1::<init> → KILLED

2.2
Location : <init>
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
Removed assignment to member variable this$0 → KILLED

3.3
Location : resolve
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
replaced return value with null for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler::resolve → KILLED

52

1.1
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED

54

1.1
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
changed conditional boundary → KILLED

2.2
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
Substituted 0 with 1 → KILLED

3.3
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed conditional - replaced comparison check with false → KILLED

4.4
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
negated conditional → KILLED

5.5
Location : select
Killed by : none
removed conditional - replaced comparison check with true → TIMED_OUT

55

1.1
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
replaced call to java/util/random/RandomGenerator::nextInt with argument → KILLED

2.2
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to java/util/random/RandomGenerator::nextInt → KILLED

3.3
Location : select
Killed by : none
removed call to java/util/List::size → SURVIVED
Covering tests

56

1.1
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to net/bmahe/genetics4j/core/Population::add → KILLED

2.2
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to java/util/List::get → KILLED

3.3
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
removed call to java/util/List::get → KILLED

58

1.1
Location : select
Killed by : net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.core.selection.RandomSelectionPolicyHandlerTest]/[method:select()]
replaced return value with null for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler$1::select → KILLED

Active mutators

Tests examined


Report generated by PIT 1.19.6