Back to index

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

List of all members.

Public Member Functions

def setUp
def test_organism_basic
def test_organism_fitness
def test_organism_copy
def test_provide_fitness

Public Attributes

 alphabet
 genome
 organism

Detailed Description

Tests for an organism in a GA population.

Definition at line 105 of file test_GAOrganism.py.


Member Function Documentation

Definition at line 108 of file test_GAOrganism.py.

00108 
00109     def setUp(self):
00110         self.alphabet = TestAlphabet()
00111         self.genome = MutableSeq("1234", self.alphabet)
00112         self.organism = Organism.Organism(self.genome, fitness_calculator)

Exercise basic organism functionality.

Definition at line 113 of file test_GAOrganism.py.

00113 
00114     def test_organism_basic(self):
00115         """Exercise basic organism functionality.
00116         """
00117         same_genome = MutableSeq("1234", self.alphabet)
00118         same_organism = Organism.Organism(same_genome, fitness_calculator)
00119 
00120         dif_genome = MutableSeq("1111", self.alphabet)
00121         dif_organism = Organism.Organism(dif_genome, fitness_calculator)
00122 
00123         assert str(self.organism) == str(same_organism), \
00124                "Comparison doesn't work for identical organisms."
00125 
00126         assert str(self.organism) != str(dif_organism), \
00127                "Comparison doesn't work for different organism."

Test copying of organisms.

Definition at line 141 of file test_GAOrganism.py.

00141 
00142     def test_organism_copy(self):
00143         """Test copying of organisms.
00144         """
00145         new_organism = self.organism.copy()
00146 
00147         new_organism.genome.append("1")
00148 
00149         assert str(new_organism.genome) != str(self.organism.genome), \
00150                "Did not provide a copy of the organism."

Test the ability to deal with the fitness of the genome.

Definition at line 128 of file test_GAOrganism.py.

00128 
00129     def test_organism_fitness(self):
00130         """Test the ability to deal with the fitness of the genome.
00131         """
00132         assert self.organism.fitness == 1234, \
00133                "Unexpected fitness %s" % self.organism.fitness
00134         
00135         new_genome = MutableSeq("1111", self.alphabet)
00136         self.organism.genome = new_genome
00137         self.organism.recalculate_fitness()
00138 
00139         assert self.organism.fitness == 1111, \
00140                "Unexpected fitness %s" % self.organism.fitness

Test that providing a pre-calculated fitness works.

Definition at line 151 of file test_GAOrganism.py.

00151 
00152     def test_provide_fitness(self):
00153         """Test that providing a pre-calculated fitness works.
00154         """
00155         def fitness_calc(genome):
00156             raise ValueError("Should not have been executed.")
00157 
00158         genome = self.organism.genome
00159 
00160         # make sure not supplying fitness works
00161         try:
00162             new_org = Organism.Organism(genome, fitness_calc)
00163             raise AssertionError("Did not calculate fitness when expected.")
00164         except ValueError:
00165             pass
00166 
00167         # make sure supplying fitness works
00168         new_org = Organism.Organism(genome, fitness_calc, 50)


Member Data Documentation

Definition at line 109 of file test_GAOrganism.py.

Definition at line 110 of file test_GAOrganism.py.

Definition at line 111 of file test_GAOrganism.py.


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