IndividualUtils { public static Individual[] makeCopy(Individual[] sourceIndividuals, int birthday){ if (sourceIndividuals == null){ return null; } Individual[] copies = new Individual[sourceIndividuals.length]; for (int i = 0; i < sourceIndividuals.length; i++){ if (sourceIndividuals[i] != null){ copies[i] = sourceIndividuals[i].copy(birthday); } } return copies; }  static Individual[] makeCopy(Individual[] sourceIndividuals, int birthday); static Individual getBestIndividual(Population[] populations); static Individual[] getAllIndividuals(Population[] populations); static Individual[] getIndividuals(Population[] populations, int maxIndexExclusive);  }
@Test public void testMakeCopy1() throws Exception { Individual[] copies = IndividualUtils.makeCopy(null, 1); assertTrue(copies == null); }
@Test public void testMakeCopy2() throws Exception { Individual[] source = new Individual[0]; Individual[] copies = IndividualUtils.makeCopy(source, 1); assertNotSame(copies, source); }
@Test public void testMakeCopy3() throws Exception { Individual[] source = new Individual[5]; Individual[] copies = IndividualUtils.makeCopy(source, 1); assertNotSame(copies, source); }
@Test public void testMakeCopy4() throws Exception { int size = 5; Individual[] source = new Individual[size]; for (int i = 0; i < size; i++){ if (i == 2 || i == 4){ source[i] = null; } else { source[i] = new SimpleIndividual(i, i, new SimplePhenotypeRepresentation(new double[]{1.0, 2.0, 3.0})); } } int birthday = 1; Individual[] copies = IndividualUtils.makeCopy(source, birthday); for (int i = 0; i < size; i++){ if (i == 2 || i == 4){ assertTrue(copies[i] == null); } else { assertNotSame(copies[i], source[i]); assertEquals(birthday, copies[i].getBirthday()); assertNotSame(copies[i].getRepresentation(), source[i].getRepresentation()); } } assertNotSame(copies, source); }