Skip to content

Commit 72f42d6

Browse files
committed
algorithms -> components...
and one of the tests in algorithms beloned in test_base.py
1 parent 91bef1e commit 72f42d6

File tree

5 files changed

+99
-83
lines changed

5 files changed

+99
-83
lines changed

pymathics/graph/measures_and_metrics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,13 @@ class GraphDistance(_NetworkXBuiltin):
110110
= Infinity
111111
112112
>> GraphDistance[g, 5]
113-
= [Infinity, Infinity, Infinity, 0]
113+
= {Infinity, Infinity, Infinity, Infinity, 0}
114114
115115
>> GraphDistance[g, 3]
116116
= {Infinity, 1, 2, 0, 3}
117117
118118
>> GraphDistance[g, 4]
119-
= {1, 2, 1, 0, 2}
120-
121-
#> GraphDistance[{1 -> 2}, 3, 4]
122-
: The vertex at position 2 in GraphDistance[{1 -> 2}, 3, 4] does not belong to the graph at position 1.
123-
= GraphDistance[{1 -> 2}, 3, 4]
119+
= {Infinity, 1, 0, 1, 1}
124120
"""
125121

126122
summary_text = "get path distance"

test/test_algorithms.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

test/test_base.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Unit tests for pymathics.graph.base
4+
"""
5+
from test.helper import check_evaluation, evaluate, evaluate_value
6+
7+
import pytest
8+
9+
10+
def setup_module(module):
11+
"""Load pymathics.graph"""
12+
assert evaluate_value('LoadModule["pymathics.graph"]') == "pymathics.graph"
13+
evaluate("SortList[list_] := Sort[Map[Sort, list]]")
14+
15+
16+
@pytest.mark.parametrize(
17+
("str_expr", "str_expected", "msg"),
18+
[
19+
(None, None, None),
20+
(
21+
"g = Graph[{a -> b, b <-> c, d -> c, d -> a, e <-> c, d -> b}];",
22+
"Null",
23+
"Intialize graph",
24+
),
25+
("Sort[DegreeCentrality[g]]", "{2, 2, 3, 4, 5}", None),
26+
('Sort[DegreeCentrality[g, "In"]]', "{0, 1, 1, 3, 3}", None),
27+
('Sort[DegreeCentrality[g, "Out"]]', "{1, 1, 1, 2, 3}", None),
28+
(None, None, None),
29+
],
30+
)
31+
def test_degree_centrality(str_expr, str_expected, msg):
32+
check_evaluation(str_expr, str_expected, failure_message=msg)

test/test_components.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Unit tests for pymathics.graph.components
4+
"""
5+
from test.helper import check_evaluation, evaluate, evaluate_value
6+
7+
8+
def setup_module(module):
9+
"""Load pymathics.graph"""
10+
assert evaluate_value('LoadModule["pymathics.graph"]') == "pymathics.graph"
11+
evaluate("SortList[list_] := Sort[Map[Sort, list]]")
12+
13+
14+
def test_connected_components():
15+
for str_expr, str_expected in [
16+
("PlanarGraphQ[Graph[{}]]", "False"),
17+
("g = Graph[{1 -> 2, 2 -> 3, 3 <-> 4}];", "Null"),
18+
("SortList[ConnectedComponents[g]]", "{{1}, {2}, {3, 4}}"),
19+
("g = Graph[{1 -> 2, 2 -> 3, 3 -> 1}];", "Null"),
20+
("SortList[ConnectedComponents[g]]", "{{1, 2, 3}}"),
21+
]:
22+
check_evaluation(str_expr, str_expected)

test/test_measures_and_metrics.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Unit tests for pymathics.graph.measures_and_metrics
3+
"""
4+
5+
from test.helper import check_evaluation
6+
7+
8+
def test_graph_distance():
9+
for str_expr, str_expected, mess in [
10+
(
11+
"GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 2 <-> 4, 4 -> 5}, 1, 5]",
12+
"3",
13+
None,
14+
),
15+
("GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 4 -> 2, 4 -> 5}, 1, 5]", "4", None),
16+
(
17+
"GraphDistance[{1 <-> 2, 2 <-> 3, 4 -> 3, 4 -> 2, 4 -> 5}, 1, 5]",
18+
"Infinity",
19+
None,
20+
),
21+
(
22+
"Sort[GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 2 <-> 4, 4 -> 5}, 3]]",
23+
"{0, 1, 1, 2, 2}",
24+
None,
25+
),
26+
(
27+
"GraphDistance[{}, 1, 1]",
28+
"GraphDistance[{}, 1, 1]",
29+
[
30+
"The vertex at position 2 in GraphDistance[{}, 1, 1] does not belong to "
31+
"the graph at position 1."
32+
],
33+
),
34+
(
35+
"GraphDistance[{1 -> 2}, 3, 4]",
36+
"GraphDistance[{1 -> 2}, 3, 4]",
37+
[
38+
"The vertex at position 2 in GraphDistance[{1 -> 2}, 3, 4] does not belong "
39+
"to the graph at position 1."
40+
],
41+
),
42+
]:
43+
check_evaluation(str_expr, str_expected, expected_messages=mess)

0 commit comments

Comments
 (0)