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/.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/.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 b/build.gradle deleted file mode 100644 index 5ea3676..0000000 --- a/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -apply plugin: 'java' -apply plugin: 'maven' - -group 'com.github.erdos-graph-framework' -version '1.0-SNAPSHOT' - -sourceCompatibility = 1.7 -targetCompatibility = 1.8 - -repositories { - jcenter() - mavenCentral() -} - -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile "junit:junit:4.11" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -artifacts { - archives sourcesJar -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..10ad201 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,65 @@ +plugins { + `java-library` + jacoco +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + +group = "com.github.erdos-graph-framework" +version = "1.0-SNAPSHOT" + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.1.0") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.1.0") + +} + +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 + 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/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 b/settings.gradle deleted file mode 100644 index 00273b2..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'erdos' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..b0a0170 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,3 @@ +// known issue: case sensitivity for IDEA +rootProject.name = "Erdos" + 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/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 new file mode 100644 index 0000000..f5168ea --- /dev/null +++ b/src/test/java/com/hendrix/test/SimpleDirectedGraphTest.java @@ -0,0 +1,101 @@ +package com.hendrix.test; + +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.Vertex; +import org.junit.jupiter.api.Test; + +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() { + 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 + 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(); + } +}