### Question:
Chromosome implements Comparable<Chromosome> { public Chromosome[] mate(Chromosome mate) { char[] arr1 = gene.toCharArray(); char[] arr2 = mate.gene.toCharArray(); int pivot = rand.nextInt(arr1.length); char[] child1 = new char[gene.length()]; char[] child2 = new char[gene.length()]; System.arraycopy(arr1, 0, child1, 0, pivot); System.arraycopy(arr2, pivot, child1, pivot, (child1.length - pivot)); System.arraycopy(arr2, 0, child2, 0, pivot); System.arraycopy(arr1, pivot, child2, pivot, (child2.length - pivot)); return new Chromosome[] { new Chromosome(String.valueOf(child1)), new Chromosome(String.valueOf(child2))}; } Chromosome(String gene); String getGene(); int getFitness(); Chromosome mutate(); Chromosome[] mate(Chromosome mate); @Override int compareTo(Chromosome c); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void testMate() { Chromosome c1 = Chromosome.generateRandom(); Chromosome c2 = Chromosome.generateRandom(); char[] arr1 = c1.getGene().toCharArray(); char[] arr2 = c2.getGene().toCharArray(); Chromosome[] children = c1.mate(c2); assertEquals(2, children.length); assertEquals(13, children[0].getGene().length()); assertEquals(13, children[1].getGene().length()); char[] tmpArr = children[0].getGene().toCharArray(); int pivot; for (pivot = 0; pivot < arr1.length; pivot++) { if (arr1[pivot] != tmpArr[pivot]) { break; } } tmpArr = children[0].getGene().toCharArray(); for (int i = 0; i < tmpArr.length; i++) { if (i < pivot) { assertEquals(arr1[i], tmpArr[i]); } else { assertEquals(arr2[i], tmpArr[i]); } } tmpArr = children[1].getGene().toCharArray(); for (int i = 0; i < tmpArr.length; i++) { if (i < pivot) { assertEquals(arr2[i], tmpArr[i]); } else { assertEquals(arr1[i], tmpArr[i]); } } }