Exemplo n.º 1
0
def test_attributes_gene_impl():
    # Create the Genetic algorithm
    ga = GA()

    # Set necessary attributes
    ga.population_size = 3
    ga.chromosome_length = 5
    ga.generation_goal =  1
    # Set gene_impl
    ga.gene_impl = lambda: random.randint(1, 10)

    # Evolve the genetic algorithm
    ga.evolve()
Exemplo n.º 2
0
def test_population_size():
    """Test the population size is create correctly"""

    for i in range(4,100):
        # Create the ga to test
        ga = GA()

        ga.generation_goal = 10
        # Set the upper limit of testing
        ga.population_size = i
        # Evolve the ga
        ga.evolve()

        # If they are not equal throw an error
        assert int(len(ga.population)) == ga.population_size