diff --git a/src/main/java/GraphData.java b/src/main/java/GraphData.java index 8762dd4..4192395 100644 --- a/src/main/java/GraphData.java +++ b/src/main/java/GraphData.java @@ -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 exporter = new DOTExporter<>(v -> v); Writer writer = new StringWriter(); diff --git a/src/test/java/GraphDataTest.java b/src/test/java/GraphDataTest.java index e0047ee..7fed958 100644 --- a/src/test/java/GraphDataTest.java +++ b/src/test/java/GraphDataTest.java @@ -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 {