Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.
Open
15 changes: 15 additions & 0 deletions dijkstra-algorythm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>java-core-exercises</artifactId>
<groupId>com.bobocode</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dijkstra-algorythm</artifactId>


</project>
28 changes: 28 additions & 0 deletions dijkstra-algorythm/src/main/java/com/bobocode/GraphImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bobocode;

import com.bobocode.interfaces.Graph;

import java.util.Set;

public class GraphImpl implements Graph {

@Override
public void addNode(String nodeName) {
throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method
}

@Override
public void addDestination(String nodeFromName, String nodeToName, int distance) {
throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method
}

@Override
public int calculateShortestDistance(String nodeStart, String nodeEnd) {
throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method
}

@Override
public Set<String> calculateShortestPath(String nodeStart, String nodeEnd) {
throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bobocode.interfaces;

import java.util.Set;

public interface Graph {
void addNode(String nodeName);
void addDestination(String nodeFromName, String nodeToName, int distance);
int calculateShortestDistance(String nodeStart, String nodeEnd);
Set<String> calculateShortestPath(String nodeStart, String nodeEnd);
}
41 changes: 41 additions & 0 deletions dijkstra-algorythm/src/test/java/com/bobocode/GraphImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.bobocode;

import com.bobocode.interfaces.Graph;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;

class GraphImplTest {
private Graph graph = new GraphImpl();

@Test
public void testAddNodesIntoEmptyGraph() {
graph.addNode("nodeA");
graph.addNode("nodeB");
graph.addNode("nodeC");
graph.addNode("nodeD");
graph.addNode("nodeE");
graph.addNode("nodeF");

graph.addDestination("nodeA", "nodeB", 2);
graph.addDestination("nodeA", "nodeC", 4);
graph.addDestination("nodeA", "nodeD", 5);

graph.addDestination("nodeB", "nodeE", 7);
graph.addDestination("nodeB", "nodeC", 1);

graph.addDestination("nodeC", "nodeD", 3);
graph.addDestination("nodeC", "nodeF", 4);

graph.addDestination("nodeD", "nodeF", 2);
graph.addDestination("nodeE", "nodeF", 8);

assertEquals(graph.calculateShortestDistance("nodeA", "nodeF"), 7);
assertEquals(graph.calculateShortestDistance("nodeA", "nodeE"), 9);

assertEquals(graph.calculateShortestPath("nodeA", "nodeF"), Set.of("nodeA", "nodeD", "NodeF"));
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>declarative-sum-of-squares</module>
<module>crazy-lambdas</module>
<module>crazy-optionals</module>
<module>dijkstra-algorythm</module>
</modules>
<packaging>pom</packaging>

Expand Down