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

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

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

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

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

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

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

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

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

    new_space.build()

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

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

    new_space.agents = []

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

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

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

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

    assert new_space.n_iterations == 10