From 8195fe962230b47933c7c5281efddf60c9d40cb4 Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Thu, 17 Aug 2023 09:11:19 -0400 Subject: [PATCH 1/5] Updating to use current gradle and JDK --- .idea/modules.xml | 8 -------- .idea/modules/erdos.iml | 20 ------------------- .idea/runConfigurations.xml | 12 ----------- .idea/vcs.xml | 6 ------ build.gradle => build.gradle.kts | 0 settings.gradle => settings.gradle.kts | 0 .../hendrix/test/SimpleDirectedGraphTest.java | 2 ++ 7 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 .idea/modules.xml delete mode 100644 .idea/modules/erdos.iml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 .idea/vcs.xml rename build.gradle => build.gradle.kts (100%) rename settings.gradle => settings.gradle.kts (100%) create mode 100644 src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 853614b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/erdos.iml b/.idea/modules/erdos.iml deleted file mode 100644 index 999be40..0000000 --- a/.idea/modules/erdos.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle.kts similarity index 100% rename from build.gradle rename to build.gradle.kts diff --git a/settings.gradle b/settings.gradle.kts similarity index 100% rename from settings.gradle rename to settings.gradle.kts diff --git a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java new file mode 100644 index 0000000..e01f53a --- /dev/null +++ b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java @@ -0,0 +1,2 @@ +package com.hendrix.test;public class SimpleDirectedGraphTest { +} From df1ad57435071281274d542fa5091d14a7e5af0b Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Thu, 17 Aug 2023 09:23:03 -0400 Subject: [PATCH 2/5] Updating gradle --- .gitignore | 3 + .travis.yml | 2 +- CONTRIBUTING.md | 2 +- build.gradle.kts | 32 ++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 3 +- .../com/hendrix/example/GraphExamples.java | 58 +--------------- .../java/com/hendrix/test/GraphTestsTest.java | 23 ++----- .../hendrix/test/SimpleDirectedGraphTest.java | 69 ++++++++++++++++++- 9 files changed, 97 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 0b35ec1..207313f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ erdos.iml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +.idea/ +.gradle/ diff --git a/.travis.yml b/.travis.yml index 9bcf999..3e54967 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java jdk: - - oraclejdk8 + - openjdk17 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f1a32a..43aa82f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ * factory methods for bulk generation of nodes. * more graph engines, for example an engine that is based on the adjacency matrix * more graph algorithms -* visulaization tool, i prefer html 5 based. +* visualization tool, I prefer html 5 based. * github page * unit testing contributions will be awesome. diff --git a/build.gradle.kts b/build.gradle.kts index 5ea3676..75fb48e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,27 +1,27 @@ -apply plugin: 'java' -apply plugin: 'maven' +plugins { + `java-library` +} -group 'com.github.erdos-graph-framework' -version '1.0-SNAPSHOT' +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} -sourceCompatibility = 1.7 -targetCompatibility = 1.8 +group="com.github.erdos-graph-framework" +version="1.0-SNAPSHOT" repositories { - jcenter() + mavenLocal() mavenCentral() } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile "junit:junit:4.11" -} + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.1.0") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.1.0") -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource } -artifacts { - archives sourcesJar -} \ No newline at end of file +tasks.test { + useJUnitPlatform() +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..27a0110 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/settings.gradle.kts b/settings.gradle.kts index 00273b2..b0a0170 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,3 @@ -rootProject.name = 'erdos' +// known issue: case sensitivity for IDEA +rootProject.name = "Erdos" diff --git a/src/main/java/com/hendrix/example/GraphExamples.java b/src/main/java/com/hendrix/example/GraphExamples.java index a7da232..20cfe41 100644 --- a/src/main/java/com/hendrix/example/GraphExamples.java +++ b/src/main/java/com/hendrix/example/GraphExamples.java @@ -56,7 +56,7 @@ public GraphExamples() { //BellmanFord(); //DijkstraShortestPath(); //matrixUtils(); - floyd_Warshall_and_johnson(); + // floyd_Warshall_and_johnson(); //transitiveClosure(); } @@ -100,62 +100,6 @@ private void transitiveClosure() { } - private void floyd_Warshall_and_johnson() { - SimpleDirectedGraph graph = new SimpleDirectedGraph(); - - Vertex v1 = new Vertex(); - v1.setTag("1"); - Vertex v2 = new Vertex(); - v2.setTag("2"); - Vertex v3 = new Vertex(); - v3.setTag("3"); - Vertex v4 = new Vertex(); - v4.setTag("4"); - Vertex v5 = new Vertex(); - v5.setTag("5"); - - graph.addVertex(v1); - graph.addVertex(v2); - graph.addVertex(v3); - graph.addVertex(v4); - graph.addVertex(v5); - - Edge e1_2 = new DirectedEdge(v1, v2, 3); - Edge e1_3 = new DirectedEdge(v1, v3, 8); - Edge e1_5 = new DirectedEdge(v1, v5, 4); - - Edge e2_4 = new DirectedEdge(v2, v4, 1); - Edge e2_5 = new DirectedEdge(v2, v5, 7); - - Edge e3_2 = new DirectedEdge(v3, v2, 4); - - Edge e4_1 = new DirectedEdge(v4, v1, 2); - Edge e4_3 = new DirectedEdge(v4, v3, 5); - - Edge e5_4 = new DirectedEdge(v5, v4, 6); - - graph.addEdge(e1_2); - graph.addEdge(e1_3); - graph.addEdge(e1_5); - graph.addEdge(e2_4); - graph.addEdge(e2_5); - graph.addEdge(e3_2); - graph.addEdge(e4_1); - graph.addEdge(e4_3); - graph.addEdge(e5_4); - - AllPairsShortPathResult floyd_result = new FloydWarshall(graph).applyAlgorithm(); - - floyd_result.shortestPathsTreeOf(v1).print(); - - System.out.println(floyd_result.shortestPathBetween(v5, v2).toString()); - - AllPairsShortPathResult johnson_result = AllPairsShortPathFactory.newAllPairsShortPath(graph, AllPairsShortPathFactory.APSPAlgorithm.Johnson).applyAlgorithm(); - - - System.out.println(""); - } - private void matrixUtils() { SimpleDirectedGraph graph = new SimpleDirectedGraph(); diff --git a/src/test/java/com/hendrix/test/GraphTestsTest.java b/src/test/java/com/hendrix/test/GraphTestsTest.java index 298287b..7016217 100644 --- a/src/test/java/com/hendrix/test/GraphTestsTest.java +++ b/src/test/java/com/hendrix/test/GraphTestsTest.java @@ -1,31 +1,16 @@ package com.hendrix.test; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.util.concurrent.ThreadPoolExecutor; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * Created by tshalev on 09/02/2017. */ public class GraphTestsTest { - @Before - public void setUp() throws Exception { - - } - - @After - public void tearDown() throws Exception { - - } @Test public void testHello() { - - assert (true); + assertTrue(true); } -} \ No newline at end of file +} diff --git a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java index e01f53a..cdb6fd0 100644 --- a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java +++ b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java @@ -1,2 +1,69 @@ -package com.hendrix.test;public class SimpleDirectedGraphTest { +package com.hendrix.test; + +import com.hendrix.erdos.algorithms.FloydWarshall; +import com.hendrix.erdos.algorithms.factories.AllPairsShortPathFactory; +import com.hendrix.erdos.graphs.SimpleDirectedGraph; +import com.hendrix.erdos.types.DirectedEdge; +import com.hendrix.erdos.types.Edge; +import com.hendrix.erdos.types.Vertex; +import org.junit.jupiter.api.Test; + +public class SimpleDirectedGraphTest { + @Test + public void testSimpleDirectedGraph() { + // TODO this might be a good thing to load from JSON or XML + SimpleDirectedGraph graph = new SimpleDirectedGraph(); + + var v1 = new Vertex(); + v1.setTag("1"); + var v2 = new Vertex(); + v2.setTag("2"); + var v3 = new Vertex(); + v3.setTag("3"); + var v4 = new Vertex(); + v4.setTag("4"); + var v5 = new Vertex(); + v5.setTag("5"); + + graph.addVertex(v1); + graph.addVertex(v2); + graph.addVertex(v3); + graph.addVertex(v4); + graph.addVertex(v5); + + var e1_2 = new DirectedEdge(v1, v2, 3); + var e1_3 = new DirectedEdge(v1, v3, 8); + var e1_5 = new DirectedEdge(v1, v5, 4); + + var e2_4 = new DirectedEdge(v2, v4, 1); + var e2_5 = new DirectedEdge(v2, v5, 7); + + var e3_2 = new DirectedEdge(v3, v2, 4); + + var e4_1 = new DirectedEdge(v4, v1, 2); + var e4_3 = new DirectedEdge(v4, v3, 5); + + var e5_4 = new DirectedEdge(v5, v4, 6); + + graph.addEdge(e1_2); + graph.addEdge(e1_3); + graph.addEdge(e1_5); + graph.addEdge(e2_4); + graph.addEdge(e2_5); + graph.addEdge(e3_2); + graph.addEdge(e4_1); + graph.addEdge(e4_3); + graph.addEdge(e5_4); + + // TODO what should this value be to be correct? + var pathResult = new FloydWarshall(graph).applyAlgorithm(); + + // TODO what should THIS be? + pathResult.shortestPathsTreeOf(v1).print(); + + // System.out.println("path result:" + pathResult.shortestPathBetween(v5, v2).toString()); + + // TODO why is this here? + var johnsonResult = AllPairsShortPathFactory.newAllPairsShortPath(graph, AllPairsShortPathFactory.APSPAlgorithm.Johnson).applyAlgorithm(); + } } From 3b6c41b36e7ca9a16208d5a394f991731cd74fc8 Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Thu, 17 Aug 2023 09:40:21 -0400 Subject: [PATCH 3/5] Adding tests for addEdge --- .../exceptions/VertexNotFoundException.java | 2 +- .../hendrix/erdos/graphs/AbstractGraph.java | 4 +-- .../hendrix/test/SimpleDirectedGraphTest.java | 27 ++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hendrix/erdos/exceptions/VertexNotFoundException.java b/src/main/java/com/hendrix/erdos/exceptions/VertexNotFoundException.java index c8fb737..b20882a 100644 --- a/src/main/java/com/hendrix/erdos/exceptions/VertexNotFoundException.java +++ b/src/main/java/com/hendrix/erdos/exceptions/VertexNotFoundException.java @@ -5,6 +5,6 @@ public class VertexNotFoundException extends GraphException { public VertexNotFoundException(IVertex v, IGraph graph) { - super(v.getId() + " not found in graph", graph); + super(String.format("%s (%s) not found in graph", v.getId(), v.toString()), graph); } } diff --git a/src/main/java/com/hendrix/erdos/graphs/AbstractGraph.java b/src/main/java/com/hendrix/erdos/graphs/AbstractGraph.java index 4b7766f..cd7ced5 100644 --- a/src/main/java/com/hendrix/erdos/graphs/AbstractGraph.java +++ b/src/main/java/com/hendrix/erdos/graphs/AbstractGraph.java @@ -182,8 +182,8 @@ public boolean hasEdge(Edge edge) { /** * connect an edge (v1, v2) into the graph, v1 and v2 have to be members * - * @param v1 a vertex that already belong to the graph - * @param v2 a vertex that already belong to the graph + * @param v1 a vertex that already belongs to the graph + * @param v2 a vertex that already belongs to the graph * * @return the edge so use can query the id */ diff --git a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java index cdb6fd0..d2198fe 100644 --- a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java +++ b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java @@ -2,13 +2,38 @@ import com.hendrix.erdos.algorithms.FloydWarshall; import com.hendrix.erdos.algorithms.factories.AllPairsShortPathFactory; +import com.hendrix.erdos.exceptions.VertexNotFoundException; import com.hendrix.erdos.graphs.SimpleDirectedGraph; import com.hendrix.erdos.types.DirectedEdge; -import com.hendrix.erdos.types.Edge; import com.hendrix.erdos.types.Vertex; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + public class SimpleDirectedGraphTest { + + @Test + public void validateVertexBelongsToGraph() { + var graph = new SimpleDirectedGraph(); + var first = new Vertex("first"); + var second = new Vertex("second"); + try { + graph.addEdge(first, second); + fail("Should receive a vertex not found exception"); + } catch (VertexNotFoundException e) { + assertTrue(e.getMessage().contains("(first) not found in graph"), e.getMessage()); + } + graph.addVertex(first); + try { + graph.addEdge(first, second); + fail("Should receive a vertex not found exception"); + } catch (VertexNotFoundException e) { + assertTrue(e.getMessage().contains("(second) not found in graph"), e.getMessage()); + } + + } + + @Test public void testSimpleDirectedGraph() { // TODO this might be a good thing to load from JSON or XML From 26254ad62ff37126266cd51f2c9cda3725aa352f Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Thu, 17 Aug 2023 09:47:32 -0400 Subject: [PATCH 4/5] Adding jacoco for coverage reports --- build.gradle.kts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 75fb48e..2314664 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ plugins { `java-library` + jacoco } java { @@ -8,8 +9,8 @@ java { } } -group="com.github.erdos-graph-framework" -version="1.0-SNAPSHOT" +group = "com.github.erdos-graph-framework" +version = "1.0-SNAPSHOT" repositories { mavenLocal() @@ -22,6 +23,16 @@ dependencies { } +jacoco { + toolVersion = "0.8.9" + reportsDirectory.set(layout.buildDirectory.dir("customJacocoReportDir")) +} + tasks.test { useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run } +tasks.jacocoTestReport { + dependsOn(tasks.test) // tests are required to run before generating the report +} + From 5e1b1c0ea107c30d0c716ad1dac90c7d5ad7ed67 Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Thu, 17 Aug 2023 11:05:15 -0400 Subject: [PATCH 5/5] Adding jacoco verifications for complexity and coverage --- build.gradle.kts | 27 +++++++++++++++++++ .../hendrix/test/SimpleDirectedGraphTest.java | 7 +++++ 2 files changed, 34 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 2314664..10ad201 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,5 +34,32 @@ tasks.test { } tasks.jacocoTestReport { dependsOn(tasks.test) // tests are required to run before generating the report + finalizedBy(tasks.jacocoTestCoverageVerification) } +tasks.jacocoTestCoverageVerification { + violationRules { + rule { + limit { + counter = "INSTRUCTION" + minimum = "0.80".toBigDecimal() + } + limit { + counter = "BRANCH" + minimum = "0.80".toBigDecimal() + } + limit { + counter = "LINE" + minimum = "0.80".toBigDecimal() + } + limit { + counter = "CLASS" + minimum = "0.90".toBigDecimal() + } + limit { + counter = "COMPLEXITY" + maximum = "0.30".toBigDecimal() + } + } + } +} diff --git a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java index d2198fe..f5168ea 100644 --- a/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java +++ b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java @@ -11,6 +11,13 @@ import static org.junit.jupiter.api.Assertions.*; public class SimpleDirectedGraphTest { + @Test + public void validateGraphHasVertex() { + var graph=new SimpleDirectedGraph(); + var first=new Vertex("first"); + graph.addVertex(first); + assertTrue(graph.hasVertex(first)); + } @Test public void validateVertexBelongsToGraph() {