Пример #1
0
 def test_render_with_created_on(self):
     """
     Ensures the title is used in the lilypond code.
     """
     created_on = datetime.datetime.today()
     result = render(1, [5, 6, 5], [10, 11, 12], created_on=created_on)
     self.assertIn(created_on.strftime('%c'), result)
Пример #2
0
 def test_render_with_created_on(self):
     """
     Ensures the title is used in the lilypond code.
     """
     created_on = datetime.datetime.today()
     result = render(1, [5, 6, 5], [10, 11, 12], created_on=created_on)
     self.assertIn(created_on.strftime('%c'), result)
Пример #3
0
 def test_render_with_problems(self):
     """
     If render encounters problems with the passed in music it should just
     return an empty string (falsey).
     """
     result = render(1, [], [])
     self.assertEqual('', result)
Пример #4
0
 def test_render_with_problems(self):
     """
     If render encounters problems with the passed in music it should just
     return an empty string (falsey).
     """
     result = render(1, [], [])
     self.assertEqual('', result)
Пример #5
0
 def test_render_with_default_args(self):
     """
     Checks the arguments appear as expected in the resulting lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12])
     self.assertIn('Untitled', result)
     self.assertIn('Anonymous', result)
     self.assertIn("b' 1 cis'' d''", result)
     self.assertIn("d' 1 e' d' \\bar \"|.\"", result)
Пример #6
0
 def test_render_with_default_args(self):
     """
     Checks the arguments appear as expected in the resulting lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12])
     self.assertIn('Untitled', result)
     self.assertIn('Anonymous', result)
     self.assertIn("b' 1 cis'' d''", result)
     self.assertIn("d' 1 e' d' \\bar \"|.\"", result)
Пример #7
0
 def test_render_with_composer(self):
     """
     Ensures the title is used in the lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12], composer='unittest')
     self.assertIn('unittest', result)
Пример #8
0
 def test_render_with_title(self):
     """
     Ensures the title is used in the lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12], title='foo')
     self.assertIn('foo', result)
Пример #9
0
 def test_render_with_composer(self):
     """
     Ensures the title is used in the lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12], composer='unittest')
     self.assertIn('unittest', result)
Пример #10
0
 def test_render_with_title(self):
     """
     Ensures the title is used in the lilypond code.
     """
     result = render(1, [5, 6, 5], [10, 11, 12], title='foo')
     self.assertIn('foo', result)
Пример #11
0
        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,
        generate_function, halt_function)
    fitness = 0.0

    counter = 0
    for generation in ga:
        counter += 1
        fitness = generation[0].fitness
        print "--- Generation %d ---" % counter
        print generation[0]
        print fitness
    with open('%s.ly' % output, 'w') as output:
        output.write(lilypond.render(species, cf, generation[0].chromosome))