Back to index

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

List of all members.

Public Member Functions

def setUp
def test_basic_crossover
def test_prop_sym_crossover
def test_prop_asym_crossover

Public Attributes

 alphabet
 org_1
 org_2
 org_3

Private Attributes

 _crossover

Detailed Description

Test 'simple' 4-point crossovers.

Definition at line 136 of file test_GACrossover.py.


Member Function Documentation

Definition at line 139 of file test_GACrossover.py.

00139 
00140     def setUp(self):
00141         self.alphabet = TestAlphabet()
00142         genome_1 = MutableSeq("11111", self.alphabet)
00143         self.org_1 = Organism(genome_1, test_fitness)
00144 
00145         genome_2 = MutableSeq("22222", self.alphabet)
00146         self.org_2 = Organism(genome_2, test_fitness)
00147         
00148         genome_3 = MutableSeq("333333333", self.alphabet)
00149         self.org_3 = Organism(genome_3, test_fitness)
00150         
00151         self._crossover  = InterleaveCrossover(1.0)

Test basic interleave crossover functionality.

Definition at line 152 of file test_GACrossover.py.

00152 
00153     def test_basic_crossover(self):
00154         """Test basic interleave crossover functionality.
00155         """
00156         start_genome_1 = self.org_1.genome[:]
00157         start_genome_2 = self.org_2.genome[:]
00158         
00159         new_org_1, new_org_2 = self._crossover.do_crossover(self.org_1,
00160                                                             self.org_2)
00161 
00162         self.assertNotEqual(str(new_org_1.genome), str(start_genome_1),
00163                             "Did not perform a crossover when expected.")
00164         self.assertNotEqual(str(new_org_2.genome), str(start_genome_2),
00165                             "Did not perform a crossover when expected.")
00166 
00167         self.assertNotEqual(str(new_org_1), str(self.org_1),
00168                             "Returned an exact copy of the original organism.")
00169         self.assertNotEqual(str(new_org_2), str(self.org_2),
00170                             "Returned an exact copy of the original organism.")
       
Test basic interleave crossover with asymmetric genomes.

Definition at line 191 of file test_GACrossover.py.

00191 
00192     def test_prop_asym_crossover(self):
00193         """Test basic interleave crossover with asymmetric genomes."""
00194         start_genome_1 = self.org_1.genome[:]
00195         start_genome_3 = self.org_3.genome[:]
00196 
00197         new_org_1, new_org_3 = self._crossover.do_crossover(self.org_1,
00198                                                             self.org_3)
00199 
00200         self.assertNotEqual(str(new_org_1.genome), str(start_genome_1),
00201                             "Did not perform a crossover when expected.")
00202         self.assertNotEqual(str(new_org_3.genome), str(start_genome_3),
00203                             "Did not perform a crossover when expected.")
00204 
00205         self.assertNotEqual(str(new_org_1), str(self.org_1),
00206                             "Returned an exact copy of the original organism.")
00207         self.assertNotEqual(str(new_org_3), str(self.org_3),
00208                             "Returned an exact copy of the original organism.")
00209 
00210         self.assertEqual(new_org_1.genome.tostring(), "13131",
00211                          "Did not interleave with growth.")
00212         self.assertEqual(new_org_3.genome.tostring(), "31313333",
                         "Did not interleave with growth.")
Test properties of interleave point crossover.

Definition at line 171 of file test_GACrossover.py.

00171 
00172     def test_prop_sym_crossover(self):
00173         """Test properties of interleave point crossover."""
00174         new_org_1, new_org_2 = self._crossover.do_crossover(self.org_1,
00175                                                             self.org_2)
00176 
00177         self.assertEqual(len(new_org_1.genome), len(new_org_2.genome),
00178             "Strings are of different sizes after interleave point crossover.")
00179 
00180         self.assertEqual(new_org_1.genome.tostring().count("1"),
00181                          new_org_2.genome.tostring().count("2"),
00182                          "There should be equal, inverse distributions")
00183         self.assertEqual(new_org_1.genome.tostring().count("2") ,
00184                          new_org_2.genome.tostring().count("1"),
00185                          "There should be equal, inverse distributions")
00186        
00187         self.assertEqual(new_org_1.genome.tostring(), "12121",
00188                          "Did not interleave.")
00189         self.assertEqual(new_org_2.genome.tostring(), "21212",
00190                          "Did not interleave.")


Member Data Documentation

Definition at line 150 of file test_GACrossover.py.

Definition at line 140 of file test_GACrossover.py.

Definition at line 142 of file test_GACrossover.py.

Definition at line 145 of file test_GACrossover.py.

Definition at line 148 of file test_GACrossover.py.


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