Skip to content

Commit b494116

Browse files
tests in. run
1 parent ce724c0 commit b494116

27 files changed

+137
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"@@top_scores_heap": [
4+
{
5+
"Vertex_ID": "A",
6+
"score": 1.2857142857142856
7+
},
8+
{
9+
"Vertex_ID": "B",
10+
"score": 1.2857142857142856
11+
},
12+
{
13+
"Vertex_ID": "C",
14+
"score": 1.2857142857142856
15+
},
16+
{
17+
"Vertex_ID": "D",
18+
"score": 1.2857142857142856
19+
},
20+
{
21+
"Vertex_ID": "E",
22+
"score": 1.2857142857142856
23+
},
24+
{
25+
"Vertex_ID": "F",
26+
"score": 1.2857142857142856
27+
},
28+
{
29+
"Vertex_ID": "G",
30+
"score": 1.2857142857142856
31+
},
32+
{
33+
"Vertex_ID": "H",
34+
"score": 1.2857142857142856
35+
}
36+
]
37+
}
38+
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"@@top_scores_heap": [
4+
{
5+
"Vertex_ID": "A",
6+
"score": 1.2857142857142856
7+
},
8+
{
9+
"Vertex_ID": "B",
10+
"score": 1.2857142857142856
11+
},
12+
{
13+
"Vertex_ID": "C",
14+
"score": 1.2857142857142856
15+
},
16+
{
17+
"Vertex_ID": "D",
18+
"score": 1.2857142857142856
19+
},
20+
{
21+
"Vertex_ID": "E",
22+
"score": 1.2857142857142856
23+
},
24+
{
25+
"Vertex_ID": "F",
26+
"score": 1.2857142857142856
27+
},
28+
{
29+
"Vertex_ID": "G",
30+
"score": 1.2857142857142856
31+
},
32+
{
33+
"Vertex_ID": "H",
34+
"score": 1.2857142857142856
35+
}
36+
]
37+
}
38+
]

tests/data/complete.png

88.7 KB
Loading

tests/data/create_baseline.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import csv
2+
import json
3+
4+
import networkx as nx
5+
import numpy as np
6+
7+
baseline_path_root = "baseline/graph_algorithms_baselines"
8+
9+
10+
def run_degree_baseline(g: nx.Graph):
11+
res = nx.centrality.degree_centrality(g)
12+
nx.centrality.degree_centrality
13+
14+
out = []
15+
for k, v in res.items():
16+
out.append({"Vertex_ID": k, "score": v})
17+
18+
out = [{"@@top_scores_heap": out}]
19+
return out
20+
21+
22+
def create_graph(path, edges, weights):
23+
g = nx.Graph()
24+
# include edge weights if they exist
25+
if weights is not None:
26+
g.add_weighted_edges_from(edges)
27+
else:
28+
g.add_edges_from(edges)
29+
return g
30+
31+
32+
def create_degree_baseline():
33+
# input, output
34+
paths = [
35+
(
36+
"unweighted_edges/complete_edges.csv",
37+
f"{baseline_path_root}/centrality/degree_centrality/CompleteUnweighted.json",
38+
False,
39+
),
40+
(
41+
"weighted_edges/complete_edges.csv",
42+
f"{baseline_path_root}/centrality/degree_centrality/CompleteWeighted.json",
43+
True,
44+
),
45+
]
46+
47+
for p, o_path, w in paths:
48+
with open(p) as f:
49+
edges = np.array(list(csv.reader(f)))
50+
51+
g = create_graph(p, edges, w)
52+
53+
res = run_degree_baseline(g)
54+
with open(o_path, "w") as f:
55+
json.dump(res, f, indent=2)
56+
57+
58+
if __name__ == "__main__":
59+
create_degree_baseline()

tests/data/weighted_edges/empty_graph_edges.csv

Whitespace-only changes.

tests/test/test_centrality.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ class TestCentrality:
2121
"Ring_Weighted",
2222
"Hub_Spoke_Weighted",
2323
"Tree_Weighted",
24+
"CompleteWeighted",
2425
]
2526
# weighted directed graphs
2627
graph_types4 = [
2728
"Line_Directed_Weighted",
2829
"Ring_Directed_Weighted",
2930
"Hub_Spoke_Directed_Weighted",
3031
"Tree_Directed_Weighted",
32+
"CompleteUnweighted",
3133
]
3234

3335
@pytest.mark.parametrize("test_name", graph_types1)

0 commit comments

Comments
 (0)