Пример #1
0
  @Test
  public void GIVEN_individual_WHEN_score_THEN_returnScore() {
    // GIVEN
    int expectedScore = 10;
    int[] individual = new int[10];
    for (int i = 0; i < individual.length; i++) {
      individual[i] = i;
    }

    // WHEN
    int actualScore = geneticSolver.score(individual);

    // THEN
    assertEquals(expectedScore, actualScore);
  }
Пример #2
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.");
      }
    }
  }