Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_GASelection.TournamentSelectionTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_select_best
def test_selection

Public Attributes

 selector

Detailed Description

Test selection based on a tournament style scheme.

Definition at line 117 of file test_GASelection.py.


Member Function Documentation

Definition at line 120 of file test_GASelection.py.

00120 
00121     def setUp(self):
00122         self.selector = TournamentSelection(NoMutation(), NoCrossover(),
00123                                             NoRepair(), 2)

Ensure selection of the best organism in a population of 2.

Definition at line 124 of file test_GASelection.py.

00124 
00125     def test_select_best(self):
00126         """Ensure selection of the best organism in a population of 2.
00127         """
00128         #Create any two non equal organisms
00129         org_1 = random_organism()
00130         while True:
00131             org_2 = random_organism()
00132             if org_2.fitness != org_1.fitness:
00133                 break
00134         #Sort them so org_1 is most fit
00135         if org_2.fitness > org_1.fitness:
00136             org_1, org_2 = org_2, org_1
00137         self.assertTrue(org_1.fitness > org_2.fitness)
00138         
00139         pop = [org_1, org_2]
00140         new_pop = self.selector.select(pop)
00141         for org in new_pop:
00142             self.assertEqual(org, org_1,
00143                              "Got a worse organism selected.")
00144 
00145         #Just to make sure the selector isn't doing something
00146         #silly with the order, try this with the input reserved:
00147         pop = [org_2, org_1]
00148         new_pop = self.selector.select(pop)
00149         for org in new_pop:
00150             self.assertEqual(org, org_1,
00151                              "Got a worse organism selected.")

Here is the call graph for this function:

Test basic selection on a small population.

Definition at line 152 of file test_GASelection.py.

00152 
00153     def test_selection(self):
00154         """Test basic selection on a small population.
00155         """
00156         pop = [random_organism() for org_num in range(50)]
00157         new_pop = self.selector.select(pop)
00158 
00159         self.assertEqual(len(new_pop), len(pop),
00160                          "Did not maintain population size.")
00161 

Here is the call graph for this function:


Member Data Documentation

Definition at line 121 of file test_GASelection.py.


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