def test_hypergraph_from_numpy_array(seven_by_six): sbs = seven_by_six H = Hypergraph.from_numpy_array(sbs.arr) assert len(H.nodes) == 6 assert len(H.edges) == 7 assert H.dim('e5') == 2 assert set(H.neighbors('v2')) == {'v0', 'v5'}
def test_from_numpy_array(): M = np.array([[0, 1, 1, 0, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) h = Hypergraph.from_numpy_array(M) assert "v1" in h.edges["e0"] assert "e1" not in h.nodes["v2"].memberships with pytest.raises(Exception) as excinfo: h = Hypergraph.from_numpy_array(M, node_names=["A"]) assert "Number of node names does not match number of rows" in str( excinfo.value) node_names = ["A", "B", "C", "D"] edge_names = ["a", "b", "c", "d", "e"] h = Hypergraph.from_numpy_array(M, node_names, edge_names) assert "a" in h.edges assert "A" in h.nodes assert "B" in h.edges["a"]
def test_from_numpy_array(): M = np.array([[0, 1, 1, 0, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) h = Hypergraph.from_numpy_array(M) assert 'v1' in h.edges['e0'] assert 'e1' not in h.nodes['v2'].memberships with pytest.raises(Exception) as excinfo: h = Hypergraph.from_numpy_array(M, node_names=['A']) assert 'Number of node names does not match number of rows' in str( excinfo.value) node_names = ['A', 'B', 'C', 'D'] edge_names = ['a', 'b', 'c', 'd', 'e'] h = Hypergraph.from_numpy_array(M, node_names, edge_names) assert 'a' in h.edges assert 'A' in h.nodes assert 'B' in h.edges['a']
def test_from_numpy_array_with_key(): M = np.array([[5, 0, 7, 2], [6, 8, 1, 1], [2, 5, 1, 9]]) h = Hypergraph.from_numpy_array(M, node_names=['A', 'B', 'C'], edge_names=['a', 'b', 'c', 'd'], key=lambda x: x > 4) assert 'A' in h.edges['a'] assert 'C' not in h.edges['a']
def test_from_numpy_array_with_key(): M = np.array([[5, 0, 7, 2], [6, 8, 1, 1], [2, 5, 1, 9]]) h = Hypergraph.from_numpy_array( M, node_names=["A", "B", "C"], edge_names=["a", "b", "c", "d"], key=lambda x: x > 4, ) assert "A" in h.edges["a"] assert "C" not in h.edges["a"]