def test_evaluate(self, inst_mock):
     """ Ensures the evaluation method works correctly. """
     fake_equation = Mock()
     fake_equation.get_clause_evaluation = Mock(return_value=[False, False, False])  # 0%
     bgnm = BinaryGenome(genome_size=2)
     bgnm._genes = []
     assert bgnm.evaluate(fake_equation) == 0
 def _initialise(self, no_vars):
     """ Initialises the population of directly encoded genomes. """
     self._repopulate([])  # Empty pop
     while len(self.get_population()) < 10:
         new_organism = BinaryGenome(no_vars)
         print(new_organism.get_genome_length())
         self._add_organism(new_organism)
 def test_instantiate(self, get_cnt_mock):
     """ Ensures the gene count is returned appropriately. """
     get_cnt_mock.return_value = 5
     bgnm = BinaryGenome(genome_size=5) # Should call the function automatically.
     assert len(bgnm._genes) == 5
     get_cnt_mock.return_value = 7   # Try with another set of values.
     bgnm = BinaryGenome(genome_size=7) 
     assert len(bgnm._genes) == 7
 def _reproduction(self, parents):
     """ Reproduces the organism from the parent. """
     genome_size = len(parents[0].get_genes())
     population = []  # New population
     parent_a_genes = parents[0].get_genes(
     )  # Get the parents genes for crossover
     parent_b_genes = parents[1].get_genes()
     split_point = randint(0,
                           genome_size)  # Choose a point to reproduce over
     while len(population) <= 10:
         new_gene_list = []
         new_gene_list.extend(parent_a_genes[0:split_point])
         new_gene_list.extend(parent_b_genes[split_point:genome_size])
         # Generate new child
         child = BinaryGenome(genome_size)
         child.clear_genes()
         for gene in new_gene_list:
             child.add_gene(gene)
         population.append(child)
     return population
 def test_init(self, inst_mock, set_cnt_mock):
     """ Ensures the init initialises the number of genes to be expected.  """
     bgnm = BinaryGenome(genome_size=500)
     assert inst_mock.called