-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from rabestro/develop
Added sample application
- Loading branch information
Showing
20 changed files
with
148 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
plugins { | ||
id 'groovy' | ||
id 'java-library' | ||
id 'maven-publish' | ||
} | ||
|
||
group 'lv.id.jc' | ||
version '1.1' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
// Configures the publishing | ||
publishing { | ||
repositories { | ||
// The target repository | ||
maven { | ||
// Choose whatever name you want | ||
name = "Algorithms" | ||
// The url of the repository, where the artifacts will be published | ||
url = "https://maven.pkg.github.com/rabestro/algorithms" | ||
credentials { | ||
// The credentials (described in the next section) | ||
username = project.findProperty("gpr.user") | ||
password = project.findProperty("gpr.key") | ||
} | ||
} | ||
} | ||
publications { | ||
gpr(MavenPublication) { | ||
from(components.java) | ||
// Fixes the error with dynamic versions when using Spring Boot | ||
versionMapping { | ||
usage('java-api') { | ||
fromResolutionOf('runtimeClasspath') | ||
} | ||
usage('java-runtime') { | ||
fromResolutionResult() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
// Spock Framework | ||
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0' | ||
testImplementation 'org.codehaus.groovy:groovy-all:3.0.9' | ||
|
||
// Spock Reports | ||
testRuntimeClasspath( "com.athaydes:spock-reports:2.1.1-groovy-3.0" ) { | ||
transitive = false // this avoids affecting your version of Groovy/Spock | ||
} | ||
// Required for spock-reports | ||
testImplementation 'org.slf4j:slf4j-api:1.7.32' | ||
testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.32' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...roovy/graph/BreadthFirstSearchSpec.groovy → ...id/jc/graph/BreadthFirstSearchSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...roovy/graph/DijkstrasAlgorithmSpec.groovy → ...id/jc/graph/DijkstrasAlgorithmSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/groovy/graph/GraphSpec.groovy → ...st/groovy/lv/id/jc/graph/GraphSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package graph | ||
package lv.id.jc.graph | ||
|
||
import lv.id.jc.algorithm.graph.Graph | ||
import spock.lang.Narrative | ||
|
2 changes: 1 addition & 1 deletion
2
...t/groovy/graph/SearchAlgorithmSpec.groovy → ...lv/id/jc/graph/SearchAlgorithmSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
plugins { | ||
id 'application' | ||
} | ||
|
||
dependencies { | ||
implementation project(':algorithm') | ||
} | ||
|
||
application { | ||
mainModule = 'lv.id.jc.application' | ||
mainClass = 'lv.id.jc.application.GraphApp' | ||
applicationDefaultJvmArgs = ['-Dgreeting.language=en'] | ||
} |
46 changes: 46 additions & 0 deletions
46
application/src/main/java/lv/id/jc/application/GraphApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package lv.id.jc.application; | ||
|
||
import lv.id.jc.algorithm.graph.BreadthFirstSearch; | ||
import lv.id.jc.algorithm.graph.DijkstrasAlgorithm; | ||
import lv.id.jc.algorithm.graph.Graph; | ||
import lv.id.jc.algorithm.graph.SearchAlgorithm; | ||
|
||
import java.util.Map; | ||
|
||
public class GraphApp { | ||
private static final Graph<Character> graph = Graph.of(Map.of( | ||
'A', Map.of('B', 5, 'H', 2), | ||
'B', Map.of('A', 5, 'C', 7), | ||
'C', Map.of('B', 7, 'D', 3, 'G', 4), | ||
'D', Map.of('C', 20, 'E', 4), | ||
'E', Map.of('F', 5), | ||
'F', Map.of('G', 6), | ||
'G', Map.of('C', 4), | ||
'H', Map.of('G', 3) | ||
)); | ||
private static final SearchAlgorithm<Character> fastest = new DijkstrasAlgorithm<>(); | ||
private static final SearchAlgorithm<Character> shortest = new BreadthFirstSearch<>(); | ||
|
||
public static void main(String[] args) { | ||
printRoute('D', 'C'); | ||
printRoute('A', 'G'); | ||
printRoute('D', 'H'); | ||
} | ||
|
||
@SuppressWarnings("squid:S106") | ||
private static void printRoute(Character source, Character target) { | ||
var routeOne = shortest.findPath(graph, source, target); | ||
var routeTwo = fastest.findPath(graph, source, target); | ||
var message = """ | ||
Find the path from %s to %s | ||
- the shortest take %.0f min and the path is %s | ||
- the fastest take %.0f min and the path is %s""" | ||
.formatted( | ||
source, target, | ||
graph.getDistance(routeOne), routeOne, | ||
graph.getDistance(routeTwo), routeTwo); | ||
|
||
System.out.println(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module lv.id.jc.application { | ||
requires lv.id.jc.algorithm.graph; | ||
exports lv.id.jc.application; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
rootProject.name = 'search-algorithm' | ||
rootProject.name = 'graphs-algorithms' | ||
include 'algorithm', 'application' |