Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_GACrossover.UniformTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_basic_crossover
def test_ds_prop_uniform_crossover
def test_ss_prop_uniform_crossover

Public Attributes

 alphabet
 org_1
 org_2
 org_3
 crossover

Detailed Description

Test simple point crossovers.

Definition at line 66 of file test_GACrossover.py.


Member Function Documentation

Definition at line 69 of file test_GACrossover.py.

00069 
00070     def setUp(self):
00071         self.alphabet = TestAlphabet()
00072         genome_1 = MutableSeq("11111111", self.alphabet)
00073         self.org_1 = Organism(genome_1, test_fitness)
00074 
00075         genome_2 = MutableSeq("22222222", self.alphabet)
00076         self.org_2 = Organism(genome_2, test_fitness)
00077         
00078         genome_3 = MutableSeq("333", self.alphabet)
00079         self.org_3 = Organism(genome_3, test_fitness)
00080 
00081         self.crossover = UniformCrossover(1.0, 0.8)

Test basic uniform crossover functionality.

Definition at line 82 of file test_GACrossover.py.

00082 
00083     def test_basic_crossover(self):
00084         """Test basic uniform crossover functionality.
00085         """
00086         start_genome_1 = self.org_1.genome[:]
00087         start_genome_2 = self.org_2.genome[:]
00088         
00089         new_org_1, new_org_2 = self.crossover.do_crossover(self.org_1,
00090                                                            self.org_2)
00091 
00092         self.assertNotEqual(str(new_org_1.genome), str(start_genome_1),
00093                             "Did not perform a crossover when expected.")
00094         self.assertNotEqual(str(new_org_2.genome), str(start_genome_2),
00095                             "Did not perform a crossover when expected.")
00096     
00097         self.assertNotEqual(str(new_org_1), str(self.org_1),
00098                             "Returned an exact copy of the original organism.")
00099         self.assertNotEqual(str(new_org_2), str(self.org_2),
00100                             "Returned an exact copy of the original organism.")

Test properties of differing genome length, uniform crossovers.

Definition at line 101 of file test_GACrossover.py.

00101 
00102     def test_ds_prop_uniform_crossover(self):
00103         """Test properties of differing genome length, uniform crossovers.
00104         """
00105         new_org_1, new_org_2 = self.crossover.do_crossover(self.org_1,
00106                                                            self.org_3)
00107 
00108 
00109         self.assertTrue(len(new_org_1.genome) > len(new_org_2.genome),
00110                      "Strings are of wrong sizes after uniform crossover.")
00111 
00112         self.assertEqual(new_org_2.genome.tostring().count("1"),
00113                          new_org_1.genome.tostring().count("3"),
00114                          "There should be equal distributions of the smaller string")
00115 
00116         self.assertEqual(str(self.org_1.genome[len(new_org_2.genome):]),
00117                          str(new_org_1.genome[len(new_org_2.genome):]),
00118                          "Uniform should not touch non-overlapping elements of genome")
    
Test properties of equal genome length, uniform crossovers.

Definition at line 119 of file test_GACrossover.py.

00119 
00120     def test_ss_prop_uniform_crossover(self):
00121         """Test properties of equal genome length, uniform crossovers.
00122         """
00123         new_org_1, new_org_2 = self.crossover.do_crossover(self.org_1,
00124                                                            self.org_2)
00125 
00126         self.assertEqual(len(new_org_1.genome), len(new_org_2.genome),
00127                          "Strings are of different sizes after uniform crossover.")
00128 
00129         self.assertEqual(new_org_1.genome.tostring().count("1"),
00130                          new_org_2.genome.tostring().count("2"),
00131                          "There should be equal, inverse distributions")
00132         self.assertEqual(new_org_1.genome.tostring().count("2") ,
00133                          new_org_2.genome.tostring().count("1"),
00134                          "There should be equal, inverse distributions")
00135 


Member Data Documentation

Definition at line 70 of file test_GACrossover.py.

Definition at line 80 of file test_GACrossover.py.

Definition at line 72 of file test_GACrossover.py.

Definition at line 75 of file test_GACrossover.py.

Definition at line 78 of file test_GACrossover.py.


The documentation for this class was generated from the following file: