Skip to content

Commit

Permalink
NXOntology.n_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Sep 30, 2021
1 parent 57e2851 commit 5bd9d6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nxontology/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,16 @@ def n_nodes(self) -> int:
"""
Total number of nodes in the graph.
"""
return len(self.graph)
# int wrapper is solely to satisfy mypy
return int(self.graph.number_of_nodes())

@property
def n_edges(self) -> int:
"""
Total number of edges in the graph.
"""
# int wrapper is solely to satisfy mypy
return int(self.graph.number_of_edges())

def set_graph_attributes(
self,
Expand Down
8 changes: 8 additions & 0 deletions nxontology/tests/ontology_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
from nxontology.ontology import Node_Info, NXOntology, Similarity, SimilarityIC


def test_n_nodes(metal_nxo: NXOntology[str]) -> None:
assert metal_nxo.n_nodes == 8


def test_n_edges(metal_nxo: NXOntology[str]) -> None:
assert metal_nxo.n_edges == 9


def test_add_node(metal_nxo: NXOntology[str]) -> None:
assert "brass" not in metal_nxo.graph
metal_nxo.add_node("brass", color="#b5a642")
Expand Down

0 comments on commit 5bd9d6e

Please sign in to comment.