Exemplo 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]))
Exemplo 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]))
Exemplo 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) * 4) - 3
     for genome in result:
         self.assertEqual(expected_length, len(genome.chromosome))
Exemplo 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) * 4) - 3
     for genome in result:
         self.assertEqual(expected_length, len(genome.chromosome))
Exemplo n.º 5
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_even_beat_intervals = [2, 4, 5, 7, 9, 11]
     valid_odd_beat_intervals = valid_even_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 / 4]
             interval = contrapunctus_note - cantus_firmus_note
             if i % 2:
                 self.assertIn(interval, valid_odd_beat_intervals)
             else:
                 self.assertIn(interval, valid_even_beat_intervals)
Exemplo n.º 6
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_even_beat_intervals = [2, 4, 5, 7, 9, 11]
     valid_odd_beat_intervals = valid_even_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 / 4]
             interval = contrapunctus_note - cantus_firmus_note
             if i % 2:
                 self.assertIn(interval, valid_odd_beat_intervals)
             else:
                 self.assertIn(interval, valid_even_beat_intervals)
Exemplo 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))
Exemplo n.º 8
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))
Exemplo n.º 9
0
            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
        mutation_range = fourth.DEFAULT_MUTATION_RANGE
        mutation_rate = fourth.DEFAULT_MUTATION_RATE
        start_population = fourth.create_population(population_size, cf)
        fitness_function = fourth.make_fitness_function(cf)
        generate_function = fourth.make_generate_function(mutation_range,
            mutation_rate, cf)
        halt_function = fourth.make_halt_function(cf)

    ga = ga.genetic_algorithm(start_population, fitness_function,