Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 8
0
def test_space_agents_setter():
    new_space = space.Space()

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

    assert new_space.agents == []
Esempio n. 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)
Esempio n. 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
Esempio n. 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, )
Esempio n. 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
Esempio n. 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
Esempio n. 14
0
def test_space_best_agent():
    new_space = space.Space()

    assert new_space.best_agent == None
Esempio n. 15
0
def test_space_agents():
    new_space = space.Space()

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

    assert new_space.n_agents == 1
Esempio n. 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'
Esempio n. 18
0
def test_space_n_dimensions():
    new_space = space.Space(n_dimensions=1)

    assert new_space.n_dimensions == 1
Esempio n. 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, )
Esempio n. 20
0
def test_space_ub():
    new_space = space.Space(n_variables=1)

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

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

    new_space.build()

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

    new_space._initialize_agents()
Esempio n. 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
Esempio n. 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()
Esempio n. 26
0
def test_space_agents_setter():
    new_space = space.Space()

    new_space.agents = []

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

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

    assert new_space.n_variables == 1
Esempio n. 29
0
def test_space_built():
    new_space = space.Space()

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

    assert new_space.n_iterations == 10