Back to index

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

List of all members.

Public Member Functions

def setUp
def test_keep_higher
def test_keep_lower

Public Attributes

 alphabet
 org_1
 org_2
 test_crossover

Detailed Description

Tests for crossovers which do not reduce fitness.

Definition at line 356 of file test_GACrossover.py.


Member Function Documentation

Definition at line 359 of file test_GACrossover.py.

00359 
00360     def setUp(self):
00361         self.alphabet = TestAlphabet()
00362         genome_1 = MutableSeq("2", self.alphabet)
00363         self.org_1 = Organism(genome_1, test_fitness)
00364 
00365         genome_2 = MutableSeq("2", self.alphabet)
00366         self.org_2 = Organism(genome_2, test_fitness)
00367 
00368         self.test_crossover = TestCrossover()

Make sure we always keep higher fitness when specified.

Definition at line 369 of file test_GACrossover.py.

00369 
00370     def test_keep_higher(self):
00371         """Make sure we always keep higher fitness when specified.
00372         """
00373         crossover = SafeFitnessCrossover(self.test_crossover)
00374 
00375         self.test_crossover.type = "same"
00376         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00377 
00378         self.assertEqual(str(new_org_1), str(self.org_1),
00379                          "Did not retain organism for same fitness.")
00380         self.assertEqual(str(new_org_2), str(self.org_2),
00381                          "Did not retain organism for same fitness.")
00382 
00383         self.test_crossover.type = "lower"
00384         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00385 
00386         self.assertEqual(str(new_org_1), str(self.org_1),
00387                          "Did not retain organism when crossover had lower fitness.")
00388         self.assertEqual(str(new_org_2), str(self.org_2),
00389                          "Did not retain organism when crossover had lower fitness.")
00390 
00391         self.test_crossover.type = "higher"
00392         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00393 
00394         self.assertTrue(new_org_1.fitness > self.org_1.fitness and \
00395                      new_org_2.fitness > self.org_2.fitness,
00396                      "Did not get new organism when it had higher fitness.")

Make sure we do normal crossover functionality when specified.

Definition at line 397 of file test_GACrossover.py.

00397 
00398     def test_keep_lower(self):
00399         """Make sure we do normal crossover functionality when specified.
00400         """
00401         crossover = SafeFitnessCrossover(self.test_crossover, 1.0)
00402 
00403         self.test_crossover.type = "same"
00404         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00405 
00406         self.assertEqual(str(new_org_1), str(self.org_1),
00407                          "Did not retain organism for same fitness.")
00408         self.assertEqual(str(new_org_2), str(self.org_2),
00409                          "Did not retain organism for same fitness.")
00410 
00411         self.test_crossover.type = "lower"
00412         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00413 
00414         self.assertNotEqual(str(new_org_1), str(self.org_1),
00415                          "Retained lower fitness organism in crossover.")
00416         self.assertNotEqual(str(new_org_2), str(self.org_2),
00417                          "Retained lower fitness organism in crossover.")
00418         
00419         self.test_crossover.type = "higher"
00420         new_org_1, new_org_2 = crossover.do_crossover(self.org_1, self.org_2)
00421 
00422         self.assertTrue(new_org_1.fitness > self.org_1.fitness and \
00423                      new_org_2.fitness > self.org_2.fitness,
00424                      "Did not get new organism under higher fitness conditions.")


Member Data Documentation

Definition at line 360 of file test_GACrossover.py.

Definition at line 362 of file test_GACrossover.py.

Definition at line 365 of file test_GACrossover.py.

Definition at line 367 of file test_GACrossover.py.


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