import os
from neat.population import Population
from neat.config import Config


def test_minimal():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    # creates the population
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    pop = Population(config)
    # runs the simulation for 250 epochs
    pop.epoch(eval_fitness, 250)


def test_config_options():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    for hn in (0, 1, 2):
        config.hidden_nodes = hn
        for fc in (0, 1):
            config.fully_connected = fc
            for act in ('exp', 'tanh'):
                config.nn_activation = act
                for ff in (0, 1):
                    config.feedforward = ff

                    pop = Population(config)
                    pop.epoch(eval_fitness, 250)

import os
from neat.population import Population
from neat.config import Config
from neat.statistics import get_average_fitness


def test_minimal():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    # creates the population
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    pop = Population(config)
    # runs the simulation for up to 20 epochs
    pop.epoch(eval_fitness, 20)

    # get statistics
    avg_fitness = get_average_fitness(pop)
    assert len(avg_fitness) == 1
    assert all(f == 1 for f in avg_fitness)

    # Change fitness threshold and do another run.
    config.max_fitness_threshold = 1.1
    pop = Population(config)
    # runs the simulation for 20 epochs
    pop.epoch(eval_fitness, 20)

    # get statistics
    avg_fitness = get_average_fitness(pop)
    assert len(avg_fitness) == 20
    assert all(f == 1 for f in avg_fitness)



def test_config_options():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    for hn in (0, 1, 2):
        config.hidden_nodes = hn
        for fc in (0, 1):
            config.fully_connected = fc
            for act in ('exp', 'tanh'):
                config.nn_activation = act
                for ff in (0, 1):
                    config.feedforward = ff

                    pop = Population(config)
                    pop.epoch(eval_fitness, 250)

Include statistics usage in existing tests.
Include statistics usage in existing tests.

  import os
  from neat.population import Population
  from neat.config import Config
+ from neat.statistics import get_average_fitness
  
  
  def test_minimal():
      # sample fitness function
      def eval_fitness(population):
          for individual in population:
              individual.fitness = 1.0
  
      # creates the population
      local_dir = os.path.dirname(__file__)
      config = Config(os.path.join(local_dir, 'test_configuration'))
  
      pop = Population(config)
+     # runs the simulation for up to 20 epochs
+     pop.epoch(eval_fitness, 20)
+ 
+     # get statistics
+     avg_fitness = get_average_fitness(pop)
+     assert len(avg_fitness) == 1
+     assert all(f == 1 for f in avg_fitness)
+ 
+     # Change fitness threshold and do another run.
+     config.max_fitness_threshold = 1.1
+     pop = Population(config)
-     # runs the simulation for 250 epochs
+     # runs the simulation for 20 epochs
-     pop.epoch(eval_fitness, 250)
+     pop.epoch(eval_fitness, 20)
+ 
+     # get statistics
+     avg_fitness = get_average_fitness(pop)
+     assert len(avg_fitness) == 20
+     assert all(f == 1 for f in avg_fitness)
+ 
  
  
  def test_config_options():
      # sample fitness function
      def eval_fitness(population):
          for individual in population:
              individual.fitness = 1.0
  
      local_dir = os.path.dirname(__file__)
      config = Config(os.path.join(local_dir, 'test_configuration'))
  
      for hn in (0, 1, 2):
          config.hidden_nodes = hn
          for fc in (0, 1):
              config.fully_connected = fc
              for act in ('exp', 'tanh'):
                  config.nn_activation = act
                  for ff in (0, 1):
                      config.feedforward = ff
  
                      pop = Population(config)
                      pop.epoch(eval_fitness, 250)
  
Include statistics usage in existing tests.
## Code Before:
import os
from neat.population import Population
from neat.config import Config


def test_minimal():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    # creates the population
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    pop = Population(config)
    # runs the simulation for 250 epochs
    pop.epoch(eval_fitness, 250)


def test_config_options():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    for hn in (0, 1, 2):
        config.hidden_nodes = hn
        for fc in (0, 1):
            config.fully_connected = fc
            for act in ('exp', 'tanh'):
                config.nn_activation = act
                for ff in (0, 1):
                    config.feedforward = ff

                    pop = Population(config)
                    pop.epoch(eval_fitness, 250)

## Instruction:
Include statistics usage in existing tests.
## Code After:
import os
from neat.population import Population
from neat.config import Config
from neat.statistics import get_average_fitness


def test_minimal():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    # creates the population
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    pop = Population(config)
    # runs the simulation for up to 20 epochs
    pop.epoch(eval_fitness, 20)

    # get statistics
    avg_fitness = get_average_fitness(pop)
    assert len(avg_fitness) == 1
    assert all(f == 1 for f in avg_fitness)

    # Change fitness threshold and do another run.
    config.max_fitness_threshold = 1.1
    pop = Population(config)
    # runs the simulation for 20 epochs
    pop.epoch(eval_fitness, 20)

    # get statistics
    avg_fitness = get_average_fitness(pop)
    assert len(avg_fitness) == 20
    assert all(f == 1 for f in avg_fitness)



def test_config_options():
    # sample fitness function
    def eval_fitness(population):
        for individual in population:
            individual.fitness = 1.0

    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))

    for hn in (0, 1, 2):
        config.hidden_nodes = hn
        for fc in (0, 1):
            config.fully_connected = fc
            for act in ('exp', 'tanh'):
                config.nn_activation = act
                for ff in (0, 1):
                    config.feedforward = ff

                    pop = Population(config)
                    pop.epoch(eval_fitness, 250)
