Beispiel #1
0
def test_getters():
    """
    Test if the assignement and return of the adjacency matrix works
    """

    A = np.random.randint(2, size=(10, 10))
    S = np.random.randint(2, size=10)
    stocks = np.random.rand(10)
    ones = np.ones(10)
    # Dummy values
    m = ExploitCore(A, S, stocks, ones, ones, ones, 0.5, 2.0)
    assert (m.get_adjacency() == A).all()
    assert (m.get_strategies() == S).all()
    assert (m.get_stocks() == stocks).all()
    assert m.get_time() == 0
Beispiel #2
0
def test_update():
    """
    Test if one update process changes either the adjacency matrix or the
    strategies.
    """
    A = nx.adj_matrix(nx.erdos_renyi_graph(10, 0.3)).toarray()
    S = np.random.randint(2, size=10)
    stocks = np.ones(10)
    ones = np.ones(10)

    # If rewire (phi=1) A has to change
    m = ExploitCore(A.copy(), S, stocks.copy(), ones, ones, ones, 1.0, 2.0)
    m.run(steps=1)
    assert np.sum(np.abs(m.get_adjacency() - A)) == 4
    # Stocks decreased
    assert (m.get_stocks() < stocks).all()

    # If no rewirte (phi=0) S has to change
    m = ExploitCore(A, S.copy(), stocks.copy(), ones, ones, ones, 0.0, 2.0)
    m.run(steps=1)
    assert np.sum(np.abs(m.get_strategies() - S)) == 1
    # Stocks decreased
    assert (m.get_stocks() < stocks).all()