Back to index

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

List of all members.

Public Member Functions

def setUp
def test_basic_crossover
def test_prop_sym_crossover
def test_basic_asym_crossover

Public Attributes

 alphabet
 org_1
 org_2
 sym_crossover
 asym_crossover

Detailed Description

Test 'simple' 4-point crossovers.

Definition at line 214 of file test_GACrossover.py.


Member Function Documentation

Definition at line 217 of file test_GACrossover.py.

00217 
00218     def setUp(self):
00219         self.alphabet = TestAlphabet()
00220         genome_1 = MutableSeq("11111", self.alphabet)
00221         self.org_1 = Organism(genome_1, test_fitness)
00222 
00223         genome_2 = MutableSeq("22222", self.alphabet)
00224         self.org_2 = Organism(genome_2, test_fitness)
00225         
00226         self.sym_crossover = GeneralPointCrossover(3,1.0)
00227         self.asym_crossover = GeneralPointCrossover(4,1.0)

Test basic asymmetric 2-point crossover functionality.

Definition at line 263 of file test_GACrossover.py.

00263 
00264     def test_basic_asym_crossover(self):
00265         """Test basic asymmetric 2-point crossover functionality.
00266         """
00267         start_genome_1 = self.org_1.genome[:]
00268         start_genome_2 = self.org_2.genome[:]
00269         
00270         new_org_1, new_org_2 = self.asym_crossover.do_crossover(self.org_1,
00271                                                                 self.org_2)
00272 
00273         self.assertNotEqual(str(new_org_1.genome), str(start_genome_1),
00274                             "Did not perform a crossover when expected.")
00275         self.assertNotEqual(str(new_org_2.genome), str(start_genome_2),
00276                             "Did not perform a crossover when expected.")
00277 
00278         self.assertNotEqual(str(new_org_1), str(self.org_1),
00279                             "Returned an exact copy of the original organism.")
00280         self.assertNotEqual(str(new_org_2), str(self.org_2),
00281                             "Returned an exact copy of the original organism.")
    
Test basic 4-point crossover functionality.

Definition at line 228 of file test_GACrossover.py.

00228 
00229     def test_basic_crossover(self):
00230         """Test basic 4-point crossover functionality.
00231         """
00232         start_genome_1 = self.org_1.genome[:]
00233         start_genome_2 = self.org_2.genome[:]
00234         
00235         new_org_1, new_org_2 = self.sym_crossover.do_crossover(self.org_1,
00236                                                                self.org_2)
00237 
00238         self.assertNotEqual(str(new_org_1.genome), str(start_genome_1),
00239                             "Did not perform a crossover when expected.")
00240         self.assertNotEqual(str(new_org_2.genome), str(start_genome_2),
00241                             "Did not perform a crossover when expected.")
00242 
00243         self.assertNotEqual(str(new_org_1), str(self.org_1),
00244                             "Returned an exact copy of the original organism.")
00245         self.assertNotEqual(str(new_org_2), str(self.org_2),
00246                             "Returned an exact copy of the original organism.")
               
Test properties of symmetric 4-point crossover.

Definition at line 247 of file test_GACrossover.py.

00247 
00248     def test_prop_sym_crossover(self):
00249         """Test properties of symmetric 4-point crossover.
00250         """
00251         new_org_1, new_org_2 = self.sym_crossover.do_crossover(self.org_1,
00252                                                                self.org_2)
00253 
00254         self.assertEqual(len(new_org_1.genome), len(new_org_2.genome),
00255                          "Strings are of different sizes after symmetric crossover.")
00256 
00257         self.assertEqual(new_org_1.genome.tostring().count("1"),
00258                          new_org_2.genome.tostring().count("2"),
00259                          "There should be equal, inverse distributions")
00260         self.assertEqual(new_org_1.genome.tostring().count("2") ,
00261                          new_org_2.genome.tostring().count("1"),
00262                          "There should be equal, inverse distributions")
    

Member Data Documentation

Definition at line 218 of file test_GACrossover.py.

Definition at line 226 of file test_GACrossover.py.

Definition at line 220 of file test_GACrossover.py.

Definition at line 223 of file test_GACrossover.py.

Definition at line 225 of file test_GACrossover.py.


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