RandomSelectionPolicyHandler.java

1
package net.bmahe.genetics4j.core.selection;
2
3
import java.util.List;
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.Genotype;
10
import net.bmahe.genetics4j.core.Population;
11
import net.bmahe.genetics4j.core.spec.AbstractEAConfiguration;
12
import net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext;
13
import net.bmahe.genetics4j.core.spec.selection.RandomSelection;
14
import net.bmahe.genetics4j.core.spec.selection.SelectionPolicy;
15
16
public class RandomSelectionPolicyHandler<T extends Comparable<T>> implements SelectionPolicyHandler<T> {
17
18
	private final RandomGenerator randomGenerator;
19
20
	public RandomSelectionPolicyHandler(final RandomGenerator _randomGenerator) {
21
		Objects.requireNonNull(_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 SelectionPolicy selectionPolicy) {
28
		Objects.requireNonNull(selectionPolicy);
29 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;
30
	}
31
32
	@Override
33
	public Selector<T> resolve(final AbstractEAExecutionContext<T> eaExecutionContext,
34
			final AbstractEAConfiguration<T> eaConfiguration,
35
			final SelectionPolicyHandlerResolver<T> selectionPolicyHandlerResolver,
36
			final SelectionPolicy selectionPolicy) {
37
		Objects.requireNonNull(selectionPolicy);
38
		Validate.isInstanceOf(RandomSelection.class, selectionPolicy);
39
40 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>() {
41
42
			@Override
43
			public Population<T> select(final AbstractEAConfiguration<T> eaConfiguration, final long generation,
44
					final int numIndividuals, final List<Genotype> population, final List<T> fitnessScore) {
45
				Objects.requireNonNull(eaConfiguration);
46
				Objects.requireNonNull(population);
47
				Objects.requireNonNull(fitnessScore);
48
				Validate.isTrue(generation >= 0);
49
				Validate.isTrue(numIndividuals > 0);
50
				Validate.isTrue(population.size() > 0);
51
				Validate.isTrue(fitnessScore.size() > 0);
52
				Validate.isTrue(fitnessScore.size() == population.size());
53
54 1 1. select : removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED
				final Population<T> selected = new Population<>();
55
56 5 1. select : removed conditional - replaced comparison check with true → TIMED_OUT
2. select : changed conditional boundary → KILLED
3. select : negated conditional → KILLED
4. select : removed conditional - replaced comparison check with false → KILLED
5. select : Substituted 0 with 1 → KILLED
				for (int i = 0; i < numIndividuals; i++) {
57 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());
58 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));
59
				}
60 1 1. select : replaced return value with null for net/bmahe/genetics4j/core/selection/RandomSelectionPolicyHandler$1::select → KILLED
				return selected;
61
			}
62
		};
63
	}
64
}

Mutations

23

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

29

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

40

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

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()]
removed call to net/bmahe/genetics4j/core/Population::<init> → KILLED

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()]
changed conditional boundary → KILLED

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

3.3
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

4.4
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

5.5
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

57

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 : none
removed call to java/util/List::size → SURVIVED
Covering tests

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/random/RandomGenerator::nextInt → 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()]
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

60

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.20.3