Example #1
0
def test_space_n_variables_setter():
    try:
        new_space = space.Space(n_variables=0.0)
    except:
        new_space = space.Space(n_variables=1)

    try:
        new_space = space.Space(n_variables=0)
    except:
        new_space = space.Space(n_variables=1)

    assert new_space.n_variables == 1
Example #2
0
def test_space_n_agents_setter():
    try:
        new_space = space.Space(n_agents=0.0)
    except:
        new_space = space.Space(n_agents=1)

    try:
        new_space = space.Space(n_agents=0)
    except:
        new_space = space.Space(n_agents=1)

    assert new_space.n_agents == 1
Example #3
0
def test_space_n_dimensions_setter():
    try:
        new_space = space.Space(n_dimensions=0.0)
    except:
        new_space = space.Space(n_dimensions=1)

    try:
        new_space = space.Space(n_dimensions=0)
    except:
        new_space = space.Space(n_dimensions=1)

    assert new_space.n_dimensions == 1
Example #4
0
def test_space_n_iterations_setter():
    try:
        new_space = space.Space(n_iterations=0.0)
    except:
        new_space = space.Space(n_iterations=10)

    try:
        new_space = space.Space(n_iterations=0)
    except:
        new_space = space.Space(n_iterations=10)

    assert new_space.n_iterations == 10
Example #5
0
def test_space_build():
    new_space = space.Space()

    try:
        lb = None

        ub = [10]

        new_space._build(lb, ub)
    except:
        lb = [0]

        ub = [10]

        new_space._build(lb, ub)

    try:
        lb = [0]

        ub = None

        new_space._build(lb, ub)
    except:
        lb = [0]

        ub = [10]

        new_space._build(lb, ub)

    assert new_space.built == True
Example #6
0
def test_space_clip_by_bound():
    new_space = space.Space()

    new_space.build()
    new_space.clip_by_bound()

    assert new_space.agents[0].position[0] == 0
Example #7
0
def test_space_built_setter():
    new_space = space.Space()

    try:
        new_space.built = 1
    except:
        new_space.built = True

    assert new_space.built == True
Example #8
0
def test_space_agents_setter():
    new_space = space.Space()

    try:
        new_space.agents = None
    except:
        new_space.agents = []

    assert new_space.agents == []
Example #9
0
def test_space_best_agent_setter():
    new_space = space.Space()

    try:
        new_space.best_agent = None
    except:
        new_space.best_agent = agent.Agent(1, 1, 0, 1)

    assert isinstance(new_space.best_agent, agent.Agent)
Example #10
0
def test_space_check_bound_size():
    new_space = space.Space()

    lb = [0, 1, 2, 3, 4]

    size = 5

    try:
        new_space._check_bound_size(lb, size - 1)
    except:
        boolean = new_space._check_bound_size(lb, size)

    assert boolean == True
Example #11
0
def test_space_ub_setter():
    new_space = space.Space(n_variables=2)

    try:
        new_space.ub = [0, 1]
    except:
        new_space.ub = np.array([0, 1])

    try:
        new_space.ub = np.array([0])
    except:
        new_space.ub = np.array([0, 1])

    assert new_space.ub.shape == (2, )
Example #12
0
def test_space_mapping_setter():
    new_space = space.Space(n_variables=1)

    try:
        new_space.mapping = "a"
    except:
        new_space.mapping = ["x1"]

    assert len(new_space.mapping) == 1

    try:
        new_space.mapping = []
    except:
        new_space.mapping = ["x1"]

    assert len(new_space.mapping) == 1
Example #13
0
def test_space_ub_setter():
    new_space = space.Space(n_variables=1)

    try:
        new_space.ub = [1]
    except:
        new_space.ub = np.array([1])

    assert new_space.ub[0] == 1

    try:
        new_space.ub = np.array([1, 2])
    except:
        new_space.ub = np.array([1])

    assert new_space.ub[0] == 1
Example #14
0
def test_space_best_agent():
    new_space = space.Space()

    assert new_space.best_agent == None
Example #15
0
def test_space_agents():
    new_space = space.Space()

    assert new_space.agents == []
Example #16
0
def test_space_n_agents():
    new_space = space.Space(n_agents=1)

    assert new_space.n_agents == 1
Example #17
0
def test_space_best_agent_setter():
    new_space = space.Space()

    new_space.best_agent = agent.Agent()

    assert type(new_space.best_agent).__name__ == 'Agent'
Example #18
0
def test_space_n_dimensions():
    new_space = space.Space(n_dimensions=1)

    assert new_space.n_dimensions == 1
Example #19
0
def test_space_lb_setter():
    new_space = space.Space(n_variables=2)

    new_space.lb = np.array([0, 1])

    assert new_space.lb.shape == (2, )
Example #20
0
def test_space_ub():
    new_space = space.Space(n_variables=1)

    assert new_space.ub.shape == (1, )
Example #21
0
def test_space_lb():
    new_space = space.Space(n_variables=10)

    assert new_space.lb.shape == (10, )
Example #22
0
def test_space_build():
    new_space = space.Space()

    new_space.build()

    assert new_space.built == True
Example #23
0
def test_space_initialize_agents():
    new_space = space.Space(n_agents=2, n_variables=1, n_dimensions=1)

    new_space._initialize_agents()
Example #24
0
def test_space_create_agents():
    new_space = space.Space(n_agents=2, n_variables=1, n_dimensions=1)

    new_space._create_agents()

    assert len(new_space.agents) == 2
Example #25
0
def test_space_initialize_agents():
    new_space = space.Space(n_agents=2, n_variables=2, n_dimensions=1)

    with pytest.raises(NotImplementedError):
        new_space._initialize_agents()
Example #26
0
def test_space_agents_setter():
    new_space = space.Space()

    new_space.agents = []

    assert new_space.agents == []
Example #27
0
def test_space_best_agent():
    new_space = space.Space()

    assert isinstance(new_space.best_agent, agent.Agent)
Example #28
0
def test_space_n_variables():
    new_space = space.Space(n_variables=1)

    assert new_space.n_variables == 1
Example #29
0
def test_space_built():
    new_space = space.Space()

    assert new_space.built == False
Example #30
0
def test_space_n_iterations():
    new_space = space.Space(n_iterations=10)

    assert new_space.n_iterations == 10