I'm implementing genetic algorithm in Java and I want to learn TDD with this project.
Currently I have this code:
package geneticAlgoritm;
import geneticAlgoritm.randomNumbers.IRandomGenerator;
import geneticAlgoritm.randomNumbers.RandomGenerator;
import lombok.Getter;
import lombok.NonNull;
import java.util.List;
public class Population {
@NonNull private IRandomGenerator generator = new RandomGenerator();
@Getter
@NonNull
private List<Chromosome> population;
@NonNull final IFitnessCalculator calculator;
public Population(int n, IFitnessCalculator calculator) {
this.calculator = calculator;
this.population = generatePopulation(n);
}
int nextGeneration() {
}
private List<Chromosome> generatePopulation(int n) {
return null;
}
private Chromosome mutate(Chromosome chromosome, double probability) {
return null;
}
private Chromosome crossover(Chromosome first, Chromosome second, double probability) {
return null;
}
private List<Chromosome> pickBestOfPopulation(int n) {
return null;
}
}
Basically, I have Chromosome class, which is wrapper for byte[] array and fitness of that array.
nextGeneration
generates new population with better traits. How I can change design to allow testing crossover, mutate etc functions?
nextGeneration
is really inconvenient to test for all functionalities, especially with some randomness in each (I'm using custom interface to remove it).