-
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.
- Loading branch information
1 parent
35a63d8
commit 29e2cff
Showing
6 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
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,9 @@ | ||
package algorithms.Dijkstra; | ||
|
||
import elements.Graph; | ||
|
||
public class DijkstraAlgorithm { | ||
public static void FindShortestPath(Graph graph, String sourceNodeIdentification, String targetNodeIdentification) { | ||
|
||
} | ||
} |
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,7 +1,25 @@ | ||
package algorithms.Dijkstra; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import algorithms.GraphBuilder; | ||
import elements.Graph; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DijkstraAlgorithmTest { | ||
|
||
Graph graph; | ||
|
||
@BeforeEach | ||
void SetUp() { | ||
|
||
} | ||
|
||
@Test | ||
void Test1() { | ||
graph = GraphBuilder.Build().WithNodes(0).getGraph(); | ||
|
||
Assertions.assertThrows(IllegalArgumentException.class, | ||
() -> DijkstraAlgorithm.FindShortestPath(graph, "0", "0")); | ||
} | ||
} |
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,59 @@ | ||
package algorithms; | ||
|
||
import elements.Graph; | ||
import elements.GraphNode; | ||
|
||
public class GraphBuilder { | ||
private Graph graph; | ||
|
||
private GraphBuilder() { | ||
graph = new Graph(); | ||
} | ||
|
||
public static GraphBuilder Build() { | ||
return new GraphBuilder(); | ||
} | ||
|
||
public GraphBuilder WithNodes(int nodeCount) { | ||
for (int index = 0; index < nodeCount; index++) | ||
graph.addNode(String.format("%d", nodeCount)); | ||
|
||
return this; | ||
} | ||
|
||
public GraphBuilder AllConnected(int... weights) { | ||
int weightIndex = 0; | ||
for (GraphNode graphNode1 : graph.getNodes()) { | ||
for (GraphNode graphNode2 : graph.getNodes()) { | ||
if (graphNode1 != graphNode2) { | ||
graph.addDirectionalEdge(weights[weightIndex], graphNode1, graphNode2); | ||
weightIndex++; | ||
} | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public GraphBuilder SomeConnected(String[] sourceIdentifiers, String[] targetIdentifiers, int... weights) { | ||
int identifierIndex = 0; | ||
int weightIndex = 0; | ||
for (GraphNode graphNode1 : graph.getNodes()) { | ||
for (GraphNode graphNode2 : graph.getNodes()) { | ||
if (graphNode1 != graphNode2) { | ||
if (graphNode1.getIdentifier().equals(sourceIdentifiers[identifierIndex]) && graphNode2.getIdentifier().equals(targetIdentifiers[identifierIndex])) { | ||
graph.addDirectionalEdge(weights[weightIndex], graphNode1, graphNode2); | ||
weightIndex++; | ||
identifierIndex++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public Graph getGraph() { | ||
return graph; | ||
} | ||
} |
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