Example #1
0
  @Test
  public void GIVEN_mutationRateIsZero_WHEN_procreate_THEN_returnProperChild() {
    // GIVEN
    int[] parentOne = new int[10];
    int[] parentTwo = new int[10];
    for (int i = 0; i < parentOne.length; i++) {
      parentOne[i] = i;
      parentTwo[i] = 10 - i;
    }

    // WHEN
    geneticSolver = new GeneticSolver(0, defaultGenerationLimit);
    int[] child = geneticSolver.procreate(parentOne, parentTwo, -5, 10);

    // THEN
    assertEquals(parentOne.length, child.length);
    for (int i = 0; i < child.length; i++) {
      // This isn't a very good way to do this test, but I'm not sure of a better one atm
      if (child[i] != parentOne[i] || child[i] != parentTwo[i]) {
        fail("The child should not have mutated.");
      }
    }
  }