diff --git a/tests/data/unweighted edges/empty_graph_edges.csv b/.github/workflows/tests.yml similarity index 100% rename from tests/data/unweighted edges/empty_graph_edges.csv rename to .github/workflows/tests.yml diff --git a/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteUnweighted.json b/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteUnweighted.json new file mode 100644 index 00000000..2228929b --- /dev/null +++ b/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteUnweighted.json @@ -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 + } + ] + } +] \ No newline at end of file diff --git a/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteWeighted.json b/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteWeighted.json new file mode 100644 index 00000000..2228929b --- /dev/null +++ b/tests/data/baseline/graph_algorithms_baselines/centrality/degree_centrality/CompleteWeighted.json @@ -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 + } + ] + } +] \ No newline at end of file diff --git a/tests/data/complete.png b/tests/data/complete.png new file mode 100644 index 00000000..b7f922d0 Binary files /dev/null and b/tests/data/complete.png differ diff --git a/tests/data/create_baseline.py b/tests/data/create_baseline.py new file mode 100644 index 00000000..6cd7bf1e --- /dev/null +++ b/tests/data/create_baseline.py @@ -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() diff --git a/tests/data/unweighted edges/complete_edges.csv b/tests/data/unweighted_edges/complete_edges.csv similarity index 100% rename from tests/data/unweighted edges/complete_edges.csv rename to tests/data/unweighted_edges/complete_edges.csv diff --git a/tests/data/unweighted edges/complete_edges_directed.csv b/tests/data/unweighted_edges/complete_edges_directed.csv similarity index 100% rename from tests/data/unweighted edges/complete_edges_directed.csv rename to tests/data/unweighted_edges/complete_edges_directed.csv diff --git a/tests/data/unweighted edges/dag_edges.csv b/tests/data/unweighted_edges/dag_edges.csv similarity index 100% rename from tests/data/unweighted edges/dag_edges.csv rename to tests/data/unweighted_edges/dag_edges.csv diff --git a/tests/data/weighted edges/empty_graph_edges.csv b/tests/data/unweighted_edges/empty_graph_edges.csv similarity index 100% rename from tests/data/weighted edges/empty_graph_edges.csv rename to tests/data/unweighted_edges/empty_graph_edges.csv diff --git a/tests/data/unweighted edges/hubspoke_connected_spoke_edges.csv b/tests/data/unweighted_edges/hubspoke_connected_spoke_edges.csv similarity index 100% rename from tests/data/unweighted edges/hubspoke_connected_spoke_edges.csv rename to tests/data/unweighted_edges/hubspoke_connected_spoke_edges.csv diff --git a/tests/data/unweighted edges/hubspoke_edges.csv b/tests/data/unweighted_edges/hubspoke_edges.csv similarity index 100% rename from tests/data/unweighted edges/hubspoke_edges.csv rename to tests/data/unweighted_edges/hubspoke_edges.csv diff --git a/tests/data/unweighted edges/line_edges.csv b/tests/data/unweighted_edges/line_edges.csv similarity index 100% rename from tests/data/unweighted edges/line_edges.csv rename to tests/data/unweighted_edges/line_edges.csv diff --git a/tests/data/unweighted edges/mulithub_shared_spoke_edges.csv b/tests/data/unweighted_edges/mulithub_shared_spoke_edges.csv similarity index 100% rename from tests/data/unweighted edges/mulithub_shared_spoke_edges.csv rename to tests/data/unweighted_edges/mulithub_shared_spoke_edges.csv diff --git a/tests/data/unweighted edges/ring_edges.csv b/tests/data/unweighted_edges/ring_edges.csv similarity index 100% rename from tests/data/unweighted edges/ring_edges.csv rename to tests/data/unweighted_edges/ring_edges.csv diff --git a/tests/data/unweighted edges/tree_edges.csv b/tests/data/unweighted_edges/tree_edges.csv similarity index 100% rename from tests/data/unweighted edges/tree_edges.csv rename to tests/data/unweighted_edges/tree_edges.csv diff --git a/tests/data/weighted edges/complete_edges.csv b/tests/data/weighted_edges/complete_edges.csv similarity index 100% rename from tests/data/weighted edges/complete_edges.csv rename to tests/data/weighted_edges/complete_edges.csv diff --git a/tests/data/weighted edges/complete_edges_directed.csv b/tests/data/weighted_edges/complete_edges_directed.csv similarity index 100% rename from tests/data/weighted edges/complete_edges_directed.csv rename to tests/data/weighted_edges/complete_edges_directed.csv diff --git a/tests/data/weighted edges/dag_edges.csv b/tests/data/weighted_edges/dag_edges.csv similarity index 100% rename from tests/data/weighted edges/dag_edges.csv rename to tests/data/weighted_edges/dag_edges.csv diff --git a/tests/data/weighted_edges/empty_graph_edges.csv b/tests/data/weighted_edges/empty_graph_edges.csv new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/weighted edges/hubspoke_connected_spoke_edges.csv b/tests/data/weighted_edges/hubspoke_connected_spoke_edges.csv similarity index 100% rename from tests/data/weighted edges/hubspoke_connected_spoke_edges.csv rename to tests/data/weighted_edges/hubspoke_connected_spoke_edges.csv diff --git a/tests/data/weighted edges/hubspoke_edges.csv b/tests/data/weighted_edges/hubspoke_edges.csv similarity index 100% rename from tests/data/weighted edges/hubspoke_edges.csv rename to tests/data/weighted_edges/hubspoke_edges.csv diff --git a/tests/data/weighted edges/line_edges.csv b/tests/data/weighted_edges/line_edges.csv similarity index 100% rename from tests/data/weighted edges/line_edges.csv rename to tests/data/weighted_edges/line_edges.csv diff --git a/tests/data/weighted edges/mulithub_shared_spoke_edges.csv b/tests/data/weighted_edges/mulithub_shared_spoke_edges.csv similarity index 100% rename from tests/data/weighted edges/mulithub_shared_spoke_edges.csv rename to tests/data/weighted_edges/mulithub_shared_spoke_edges.csv diff --git a/tests/data/weighted edges/negative_cycles_edges.csv b/tests/data/weighted_edges/negative_cycles_edges.csv similarity index 100% rename from tests/data/weighted edges/negative_cycles_edges.csv rename to tests/data/weighted_edges/negative_cycles_edges.csv diff --git a/tests/data/weighted edges/ring_edges.csv b/tests/data/weighted_edges/ring_edges.csv similarity index 100% rename from tests/data/weighted edges/ring_edges.csv rename to tests/data/weighted_edges/ring_edges.csv diff --git a/tests/data/weighted edges/tree_edges.csv b/tests/data/weighted_edges/tree_edges.csv similarity index 100% rename from tests/data/weighted edges/tree_edges.csv rename to tests/data/weighted_edges/tree_edges.csv diff --git a/tests/test/test_centrality.py b/tests/test/test_centrality.py index e228f12f..d06036e4 100644 --- a/tests/test/test_centrality.py +++ b/tests/test/test_centrality.py @@ -21,6 +21,7 @@ class TestCentrality: "Ring_Weighted", "Hub_Spoke_Weighted", "Tree_Weighted", + "CompleteWeighted", ] # weighted directed graphs graph_types4 = [ @@ -28,6 +29,7 @@ class TestCentrality: "Ring_Directed_Weighted", "Hub_Spoke_Directed_Weighted", "Tree_Directed_Weighted", + "CompleteUnweighted", ] @pytest.mark.parametrize("test_name", graph_types1)