def test_grid_space_terminals_setter(): try: new_grid_space = grid.GridSpace() new_grid_space.grid = 'a' except: new_grid_space = grid.GridSpace() new_grid_space.grid = np.array((1, 1)) assert len(new_grid_space.grid) == 2
def test_grid_space_step_setter(): new_grid_space = grid.GridSpace(1, 0.1, 0, 1) try: new_grid_space.step = "a" except: new_grid_space.step = np.array([0.1]) assert new_grid_space.step == 0.1 try: new_grid_space.step = np.array([0.1, 0.1]) except: new_grid_space.step = np.array([0.1]) assert new_grid_space.step == 0.1
def test_grid_space_step_setter(): new_grid_space = grid.GridSpace() try: new_grid_space.step = 'a' except: new_grid_space.step = 0.1 assert new_grid_space.step == 0.1 try: new_grid_space.step = 0 except: new_grid_space.step = 0.1 assert new_grid_space.step == 0.1
def test_gs_run(): def square(x): return np.sum(x) def hook(optimizer, space, function): return new_function = function.Function(pointer=square) new_gs = gs.GS() grid_space = grid.GridSpace(n_variables=2, step=0.1, lower_bound=[0, 0], upper_bound=[5, 5]) history = new_gs.run(grid_space, new_function, pre_evaluation=hook) assert len(history.agents) > 0 assert len(history.best_agent) > 0 best_fitness = history.best_agent[-1][1] assert best_fitness <= constants.TEST_EPSILON, 'The algorithm gs failed to converge.'
def test_grid_initialize_agents(): new_grid_space = grid.GridSpace(1, 0.1, 0, 1) assert new_grid_space.agents[0].position[0] != 1
def test_grid_space_step(): new_grid_space = grid.GridSpace(1, 0.1, 0, 1) assert new_grid_space.step == 0.1
def test_grid_create_grid(): new_grid_space = grid.GridSpace(1, 0.1, 0, 1) new_grid_space._create_grid() assert len(new_grid_space.grid) == 11
def test_grid_create_grid(): new_grid_space = grid.GridSpace() new_grid_space._create_grid(0.1, [1, 1], [2, 2]) assert len(new_grid_space.grid) == 100
def test_grid_space_grid(): new_grid_space = grid.GridSpace() assert len(new_grid_space.grid) == 10