test_class.file: java/src/test/java/net/auxesia/ChromosomeTest.java
test_class.identifier: ChromosomeTest
test_case.body: @Test
  	public void testMate() {
  		Chromosome c1 = Chromosome.generateRandom();
  		Chromosome c2 = Chromosome.generateRandom();
  		char[] arr1   = c1.getGene().toCharArray();
  		char[] arr2   = c2.getGene().toCharArray();
  
  		// Check to ensure the right number of children are returned.
  		Chromosome[] children = c1.mate(c2);		
  		assertEquals(2, children.length);
  
  		// Check the resulting child gene lengths
  		assertEquals(13, children[0].getGene().length());
  		assertEquals(13, children[1].getGene().length());
  		
  		// Determine the pivot point for the mating
  		char[] tmpArr = children[0].getGene().toCharArray();
  		int pivot;
  		for (pivot = 0; pivot < arr1.length; pivot++) {
  			if (arr1[pivot] != tmpArr[pivot]) {
  				break;
  			}
  		}
  		
  		// Check the first child.
  		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]);
  			}
  		}
  		
  		// Check the second child.
  		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]);
  			}
  		}
  	}
test_case.class_method_signature: ChromosomeTest.testMate()
test_case.full_signature: @Test public void testMate()
test_case.identifier: testMate
test_case.invocations: generateRandom generateRandom toCharArray getGene toCharArray getGene mate assertEquals assertEquals length getGene assertEquals length getGene toCharArray getGene toCharArray getGene assertEquals assertEquals toCharArray getGene assertEquals assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMate()
focal_class.declarator: gene
focal_class.modifier: private final
focal_class.original_string: private final String gene;
focal_class.type: String
focal_class.var_name: gene
focal_class.declarator: fitness
focal_class.modifier: private final
focal_class.original_string: private final int fitness;
focal_class.type: int
focal_class.var_name: fitness
focal_class.declarator: TARGET_GENE = "Hello, world!".toCharArray()
focal_class.modifier: private static final
focal_class.original_string: private static final char[] TARGET_GENE = "Hello, world!".toCharArray();
focal_class.type: char[]
focal_class.var_name: TARGET_GENE
focal_class.declarator: rand = new Random(System.currentTimeMillis())
focal_class.modifier: private static final
focal_class.original_string: private static final Random rand = new Random(System.currentTimeMillis());
focal_class.type: Random
focal_class.var_name: rand
focal_class.file: java/src/main/java/net/auxesia/Chromosome.java
focal_class.identifier: Chromosome
focal_class.interfaces: implements Comparable<Chromosome>
focal_class.class_method_signature: Chromosome.Chromosome(String gene)
focal_class.full_signature: public  Chromosome(String gene)
focal_class.identifier: Chromosome
focal_class.modifiers: public
focal_class.parameters: (String gene)
focal_class.signature:  Chromosome(String gene)
focal_class.class_method_signature: Chromosome.getGene()
focal_class.full_signature: public String getGene()
focal_class.identifier: getGene
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getGene()
focal_class.class_method_signature: Chromosome.getFitness()
focal_class.full_signature: public int getFitness()
focal_class.identifier: getFitness
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getFitness()
focal_class.class_method_signature: Chromosome.calculateFitness(String gene)
focal_class.full_signature: private static int calculateFitness(String gene)
focal_class.identifier: calculateFitness
focal_class.modifiers: private static
focal_class.parameters: (String gene)
focal_class.return: int
focal_class.signature: int calculateFitness(String gene)
focal_class.class_method_signature: Chromosome.mutate()
focal_class.full_signature: public Chromosome mutate()
focal_class.identifier: mutate
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Chromosome
focal_class.signature: Chromosome mutate()
focal_class.class_method_signature: Chromosome.mate(Chromosome mate)
focal_class.full_signature: public Chromosome[] mate(Chromosome mate)
focal_class.identifier: mate
focal_class.modifiers: public
focal_class.parameters: (Chromosome mate)
focal_class.return: Chromosome[]
focal_class.signature: Chromosome[] mate(Chromosome mate)
focal_class.class_method_signature: Chromosome.generateRandom()
focal_class.full_signature: static Chromosome generateRandom()
focal_class.identifier: generateRandom
focal_class.modifiers: static
focal_class.parameters: ()
focal_class.return: Chromosome
focal_class.signature: Chromosome generateRandom()
focal_class.class_method_signature: Chromosome.compareTo(Chromosome c)
focal_class.full_signature: @Override public int compareTo(Chromosome c)
focal_class.identifier: compareTo
focal_class.modifiers: @Override public
focal_class.parameters: (Chromosome c)
focal_class.return: int
focal_class.signature: int compareTo(Chromosome c)
focal_class.class_method_signature: Chromosome.equals(Object o)
focal_class.full_signature: @Override public boolean equals(Object o)
focal_class.identifier: equals
focal_class.modifiers: @Override public
focal_class.parameters: (Object o)
focal_class.return: boolean
focal_class.signature: boolean equals(Object o)
focal_class.class_method_signature: Chromosome.hashCode()
focal_class.full_signature: @Override public int hashCode()
focal_class.identifier: hashCode
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int hashCode()
focal_method.body: public Chromosome[] mate(Chromosome mate) {
  		// Convert the genes to arrays to make thing easier.
  		char[] arr1  = gene.toCharArray();
  		char[] arr2  = mate.gene.toCharArray();
  		
  		// Select a random pivot point for the mating
  		int pivot    = rand.nextInt(arr1.length);
  		
  		// Provide a container for the child gene data
  		char[] child1 = new char[gene.length()];
  		char[] child2 = new char[gene.length()];
  		
  		// Copy the data from each gene to the first child.
  		System.arraycopy(arr1, 0, child1, 0, pivot);
  		System.arraycopy(arr2, pivot, child1, pivot, (child1.length - pivot));
  		
  		// Repeat for the second child, but in reverse order.
  		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))}; 
  	}
focal_method.class_method_signature: Chromosome.mate(Chromosome mate)
focal_method.full_signature: public Chromosome[] mate(Chromosome mate)
focal_method.identifier: mate
focal_method.invocations: toCharArray toCharArray nextInt length length arraycopy arraycopy arraycopy arraycopy valueOf valueOf
focal_method.modifiers: public
focal_method.parameters: (Chromosome mate)
focal_method.return: Chromosome[]
focal_method.signature: Chromosome[] mate(Chromosome mate)