Skip to content

Commit

Permalink
tests in. run
Browse files Browse the repository at this point in the history
  • Loading branch information
RobRossmiller-TG committed May 21, 2024
1 parent ce724c0 commit b494116
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 0 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"@@top_scores_heap": [
{
"Vertex_ID": "A",
"score": 1.2857142857142856
},
{
"Vertex_ID": "B",
"score": 1.2857142857142856
},
{
"Vertex_ID": "C",
"score": 1.2857142857142856
},
{
"Vertex_ID": "D",
"score": 1.2857142857142856
},
{
"Vertex_ID": "E",
"score": 1.2857142857142856
},
{
"Vertex_ID": "F",
"score": 1.2857142857142856
},
{
"Vertex_ID": "G",
"score": 1.2857142857142856
},
{
"Vertex_ID": "H",
"score": 1.2857142857142856
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"@@top_scores_heap": [
{
"Vertex_ID": "A",
"score": 1.2857142857142856
},
{
"Vertex_ID": "B",
"score": 1.2857142857142856
},
{
"Vertex_ID": "C",
"score": 1.2857142857142856
},
{
"Vertex_ID": "D",
"score": 1.2857142857142856
},
{
"Vertex_ID": "E",
"score": 1.2857142857142856
},
{
"Vertex_ID": "F",
"score": 1.2857142857142856
},
{
"Vertex_ID": "G",
"score": 1.2857142857142856
},
{
"Vertex_ID": "H",
"score": 1.2857142857142856
}
]
}
]
Binary file added tests/data/complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions tests/data/create_baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import csv
import json

import networkx as nx
import numpy as np

baseline_path_root = "baseline/graph_algorithms_baselines"


def run_degree_baseline(g: nx.Graph):
res = nx.centrality.degree_centrality(g)
nx.centrality.degree_centrality

out = []
for k, v in res.items():
out.append({"Vertex_ID": k, "score": v})

out = [{"@@top_scores_heap": out}]
return out


def create_graph(path, edges, weights):
g = nx.Graph()
# include edge weights if they exist
if weights is not None:
g.add_weighted_edges_from(edges)
else:
g.add_edges_from(edges)
return g


def create_degree_baseline():
# input, output
paths = [
(
"unweighted_edges/complete_edges.csv",
f"{baseline_path_root}/centrality/degree_centrality/CompleteUnweighted.json",
False,
),
(
"weighted_edges/complete_edges.csv",
f"{baseline_path_root}/centrality/degree_centrality/CompleteWeighted.json",
True,
),
]

for p, o_path, w in paths:
with open(p) as f:
edges = np.array(list(csv.reader(f)))

g = create_graph(p, edges, w)

res = run_degree_baseline(g)
with open(o_path, "w") as f:
json.dump(res, f, indent=2)


if __name__ == "__main__":
create_degree_baseline()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/test/test_centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class TestCentrality:
"Ring_Weighted",
"Hub_Spoke_Weighted",
"Tree_Weighted",
"CompleteWeighted",
]
# weighted directed graphs
graph_types4 = [
"Line_Directed_Weighted",
"Ring_Directed_Weighted",
"Hub_Spoke_Directed_Weighted",
"Tree_Directed_Weighted",
"CompleteUnweighted",
]

@pytest.mark.parametrize("test_name", graph_types1)
Expand Down

0 comments on commit b494116

Please sign in to comment.