Skip to content

Commit

Permalink
Docs (xgi-org#90)
Browse files Browse the repository at this point in the history
* docs: general cleanup
* fix: function name change
* new tests

Co-authored-by: leotrs <[email protected]>
Co-authored-by: nwlandry <[email protected]>
Co-authored-by: Giovanni Petri <[email protected]>
  • Loading branch information
4 people authored Apr 20, 2022
1 parent 8eb74e6 commit 90f711d
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 308 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_css_files = ['custom.css']
html_css_files = ["custom.css"]

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = "1.3"
Expand Down
3 changes: 2 additions & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ numpy>=1.19,<1.22
scipy>=1.5,<1.8.0
pandas>=1.0,<=1.3.5
networkx>=2.0
requests>=2.0
requests>=2.0
matplotlib>=3.3
3 changes: 2 additions & 1 deletion requirements/documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ sphinx~=4.0
sphinx_copybutton
sphinx-rtd-theme>=0.4.2
numpydoc>=1.1
pillow>=8.2
pillow>=8.2
matplotlib>=3.3
23 changes: 13 additions & 10 deletions tests/classes/test_hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,31 @@ def test_add_edge():

def test_add_edge_with_id():
H = xgi.Hypergraph()
H.add_edge([1, 2, 3], id='myedge')
H.add_edge([1, 2, 3], id="myedge")
assert (1 in H) and (2 in H) and (3 in H)
assert 'myedge' in H.edges
assert "myedge" in H.edges
assert [1, 2, 3] in H.edges.members()
assert [1, 2, 3] == H.edges.members('myedge')
assert H.edges.members(dtype=dict) == {'myedge': [1, 2, 3]}
assert [1, 2, 3] == H.edges.members("myedge")
assert H.edges.members(dtype=dict) == {"myedge": [1, 2, 3]}


def test_add_edge_with_attr():
H = xgi.Hypergraph()
H.add_edge([1, 2, 3], color='red', place='peru')
H.add_edge([1, 2, 3], color="red", place="peru")
assert (1 in H) and (2 in H) and (3 in H)
assert 0 in H.edges
assert [1, 2, 3] in H.edges.members()
assert [1, 2, 3] == H.edges.members(0)
assert H.edges.members(dtype=dict) == {0: [1, 2, 3]}
assert H.edges[0] == {'color': 'red', 'place': 'peru'}
assert H.edges[0] == {"color": "red", "place": "peru"}


def test_add_node_to_edge():
H = xgi.Hypergraph()
H.add_edge(['apple', 'banana'], 'fruits')
H.add_node_to_edge('fruits', 'pear')
H.add_node_to_edge('veggies', 'lettuce')
assert H.edges.members(dtype=dict) == {'fruits': ['apple', 'banana', 'pear'], 'veggies': ['lettuce']}
H.add_edge(["apple", "banana"], "fruits")
H.add_node_to_edge("fruits", "pear")
H.add_node_to_edge("veggies", "lettuce")
assert H.edges.members(dtype=dict) == {
"fruits": ["apple", "banana", "pear"],
"veggies": ["lettuce"],
}
31 changes: 30 additions & 1 deletion tests/classes/test_simplicialcomplex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import pytest

import xgi
from xgi.exception import XGIError


def test_constructor(edgelist5, dict5, incidence5, dataframe5):
S_list = xgi.SimplicialComplex(edgelist5)
S_df = xgi.SimplicialComplex(dataframe5)

with pytest.raises(XGIError):
S_dict = xgi.SimplicialComplex(dict5)
with pytest.raises(XGIError):
S_mat = xgi.SimplicialComplex(incidence5)

assert list(S_list.nodes) == list(S_df.nodes)
assert list(S_list.edges) == list(S_df.edges)
assert list(S_list.edges.members(0)) == list(S_df.edges.members(0))


def test_add_simplex():
S = xgi.SimplicialComplex()
S.add_simplex([1, 2, 3])
Expand All @@ -28,6 +41,22 @@ def test_add_edge():
S.add_edge([1, 2, 3])


def test_add_simplices_from(edgelist5):
S1 = xgi.SimplicialComplex()
S1.add_simplices_from(edgelist5, max_order=None)

S2 = xgi.SimplicialComplex()
S2.add_simplices_from(edgelist5, max_order=2)

assert S1.nodes == S2.nodes

assert S1.max_edge_order() == 3
assert S2.max_edge_order() == 2

assert set(S1.edges(order=1).members()) == set(S2.edges(order=1).members())
assert set(S1.edges(order=2).members()) == set(S2.edges(order=2).members())


def test_remove_simplex_id(edgelist6):
S = xgi.SimplicialComplex()
S.add_simplices_from(edgelist6)
Expand Down
19 changes: 18 additions & 1 deletion tests/generators/test_classic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import networkx as nx
import pytest

import xgi


Expand All @@ -23,3 +23,20 @@ def test_star_clique():
assert H.num_nodes == 13
assert H.num_edges == 97
assert H.max_edge_order() == 3


def test_flag_complex():
edges = [[0, 1], [1, 2], [2, 0], [0, 3]]
G = nx.Graph(edges)

S = xgi.flag_complex(G)

simplices = [
frozenset({0, 1, 2}),
frozenset({0, 1}),
frozenset({0, 2}),
frozenset({1, 2}),
frozenset({0, 3}),
]

assert S.edges.members() == simplices
Loading

0 comments on commit 90f711d

Please sign in to comment.