Esempio n. 1
0
 def test_returns_valid_genomes(self):
     """
     Checks the genomes returned by the create_population function are
     of the correct type.
     """
     result = create_population(1, CANTUS_FIRMUS)
     self.assertEqual(Genome, type(result[0]))
Esempio n. 2
0
 def test_returns_valid_genomes(self):
     """
     Checks the genomes returned by the create_population function are
     of the correct type.
     """
     result = create_population(1, CANTUS_FIRMUS)
     self.assertEqual(Genome, type(result[0]))
Esempio n. 3
0
 def test_solutions_have_correct_number_of_notes(self):
     """
     Ensures that all solutions have the expected number of notes.
     """
     result = create_population(20, CANTUS_FIRMUS)
     expected_length = (len(CANTUS_FIRMUS) * 2) - 1
     for genome in result:
         self.assertEqual(expected_length, len(genome.chromosome))
Esempio n. 4
0
 def test_solutions_have_correct_number_of_notes(self):
     """
     Ensures that all solutions have the expected number of notes.
     """
     result = create_population(20, CANTUS_FIRMUS)
     expected_length = (len(CANTUS_FIRMUS) * 2) - 1
     for genome in result:
         self.assertEqual(expected_length, len(genome.chromosome))
Esempio n. 5
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_first_beat_intervals = [2, 4, 5, 7, 9, 11]
     valid_third_beat_intervals = valid_first_beat_intervals + [3, 6, 8, 10]
     result = create_population(20, CANTUS_FIRMUS)
     for genome in result:
         for i in range(len(genome.chromosome)):
             contrapunctus_note = genome.chromosome[i]
             cantus_firmus_note = CANTUS_FIRMUS[i / 2]
             interval = contrapunctus_note - cantus_firmus_note
             if i % 2:
                 self.assertIn(interval, valid_third_beat_intervals)
             else:
                 self.assertIn(interval, valid_first_beat_intervals)
Esempio n. 6
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_first_beat_intervals = [2, 4, 5, 7, 9, 11]
     valid_third_beat_intervals = valid_first_beat_intervals + [3, 6, 8, 10]
     result = create_population(20, CANTUS_FIRMUS)
     for genome in result:
         for i in range(len(genome.chromosome)):
             contrapunctus_note = genome.chromosome[i]
             cantus_firmus_note = CANTUS_FIRMUS[i / 2]
             interval = contrapunctus_note - cantus_firmus_note
             if i % 2:
                 self.assertIn(interval, valid_third_beat_intervals)
             else:
                 self.assertIn(interval, valid_first_beat_intervals)
Esempio n. 7
0
 def test_returns_correct_number_of_genomes(self):
     """
     Ensures the correct number of genomes are returned by the function.
     """
     result = create_population(100, CANTUS_FIRMUS)
     self.assertEqual(100, len(result))
Esempio n. 8
0
 mutation_range = 7
 mutation_rate = 0.4
 if species == 1:
     population_size = first.DEFAULT_POPULATION_SIZE
     mutation_range = first.DEFAULT_MUTATION_RANGE
     mutation_rate = first.DEFAULT_MUTATION_RATE
     start_population = first.create_population(population_size, cf)
     fitness_function = first.make_fitness_function(cf)
     generate_function = first.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = first.halt
 elif species == 2:
     population_size = second.DEFAULT_POPULATION_SIZE
     mutation_range = second.DEFAULT_MUTATION_RANGE
     mutation_rate = second.DEFAULT_MUTATION_RATE
     start_population = second.create_population(population_size, cf)
     fitness_function = second.make_fitness_function(cf)
     generate_function = first.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = second.make_halt_function(cf)
 elif species == 3:
     population_size = third.DEFAULT_POPULATION_SIZE
     mutation_range = third.DEFAULT_MUTATION_RANGE
     mutation_rate = third.DEFAULT_MUTATION_RATE
     start_population = third.create_population(population_size, cf)
     fitness_function = third.make_fitness_function(cf)
     generate_function = third.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = third.make_halt_function(cf)
 elif species == 4:
     population_size = fourth.DEFAULT_POPULATION_SIZE
Esempio n. 9
0
 def test_returns_correct_number_of_genomes(self):
     """
     Ensures the correct number of genomes are returned by the function.
     """
     result = create_population(100, CANTUS_FIRMUS)
     self.assertEqual(100, len(result))