Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_GAOrganism.CreatePopulationTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_function_population
def test_random_population
def test_random_population_types

Public Attributes

 alphabet

Detailed Description

Tests for utility functions for creating populations.

Definition at line 36 of file test_GAOrganism.py.


Member Function Documentation

Definition at line 39 of file test_GAOrganism.py.

00039 
00040     def setUp(self):
00041         self.alphabet = TestAlphabet()

Create a population using a function to generate genomes.

Definition at line 42 of file test_GAOrganism.py.

00042 
00043     def test_function_population(self):
00044         """Create a population using a function to generate genomes.
00045         """
00046         num_orgs = 10
00047         new_pop = Organism.function_population(genome_generator,
00048                                                num_orgs, fitness_calculator)
00049 
00050         assert len(new_pop) == num_orgs, "Expected %s organisms, got %s" \
00051                % (num_orgs, len(new_pops))
00052 
00053         for org in new_pop:
00054             assert isinstance(org, Organism.Organism), \
00055                    "Expected to get an organism, got %r" % org
00056 
00057             exp_fit = fitness_calculator(org.genome)
00058             assert org.fitness == exp_fit, \
00059                    "Expected fitness of %s, got %s" % (org.fitness, exp_fit)

Here is the call graph for this function:

Create a population randomly from a alphabet.

Definition at line 60 of file test_GAOrganism.py.

00060 
00061     def test_random_population(self):
00062         """Create a population randomly from a alphabet.
00063         """
00064         num_orgs = 10
00065         genome_size = 5
00066         new_pop = Organism.random_population(self.alphabet, genome_size,
00067                                              num_orgs, fitness_calculator)
00068 
00069         assert len(new_pop) == num_orgs, "Expected %s organisms, got %s" \
00070                % (num_orgs, len(new_pops))
00071 
00072         for org in new_pop:
00073             assert isinstance(org, Organism.Organism), \
00074                    "Expected to get an organism, got %r" % org
00075 
00076             exp_fit = fitness_calculator(org.genome)
00077             assert org.fitness == exp_fit, \
00078                    "Expected fitness of %s, got %s" % (org.fitness, exp_fit)
00079 
00080             assert len(org.genome) == genome_size, \
00081                    "Expected genome size of %s, got %s" % (len(org.genome),
00082                                                            genome_size)

Here is the call graph for this function:

Creating a random population with different types of alphabets.

Definition at line 83 of file test_GAOrganism.py.

00083 
00084     def test_random_population_types(self):
00085         """Creating a random population with different types of alphabets.
00086         """
00087         class DoubleAlphabet:
00088             letters = [1.0, 2.0]
00089 
00090         class CharacterAlphabet:
00091             letters = ["a", "b"]
00092 
00093         class IntegerAlphabet:
00094             letters = [1, 2]
00095 
00096         def test_fitness(genome):
00097             return 2
00098 
00099         all_alphabets = [DoubleAlphabet(), CharacterAlphabet(),
00100                          IntegerAlphabet()]
00101 
00102         for alphabet in all_alphabets:
00103             new_pop = Organism.random_population(alphabet, 5, 10,
00104                                                  test_fitness)

Here is the call graph for this function:


Member Data Documentation

Definition at line 40 of file test_GAOrganism.py.


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