Skip to content

Commit

Permalink
Add features to remove edges.
Browse files Browse the repository at this point in the history
  • Loading branch information
theViz343 committed Nov 3, 2023
1 parent 640ea3c commit 25aa765
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/GraphData.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public boolean addEdge(String srcLabel, String dstLabel) {
}
}

public void removeEdge(String srcLabel, String dstLabel) throws Exception {
DefaultEdge edgeexisting = graphObject.getEdge(srcLabel, dstLabel);
if (edgeexisting==null) {
throw new Exception("Edge does not exist!");
} else {
graphObject.removeEdge(srcLabel, dstLabel);
}
}

public boolean outputDOTGraph(String path) {
DOTExporter<String, DefaultEdge> exporter = new DOTExporter<>(v -> v);
Writer writer = new StringWriter();
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/GraphDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ public void TestAddEdgeIfNodeDoesNotExist(){
assertFalse(graphApi.addEdge("Z","C"));
}

@Test
@DisplayName("Test removal of edge")
public void TestRemoveEdge() throws Exception {
graphApi.removeEdge("A","B");
}

@Test
@DisplayName("Test addition of already existing edge")
public void TestRemoveEdgeIfExists(){
assertThrows(Exception.class, () -> graphApi.removeEdge("B","C"));
}

@Test
@DisplayName("Test DOT graph generation")
public void TestOutputDOTGraph() throws IOException {
Expand Down

0 comments on commit 25aa765

Please sign in to comment.