Ein bisschen testen...

This commit is contained in:
joachimschmidt557 2019-02-14 14:58:03 +01:00
parent ed08dfd060
commit 2b5543b279
2 changed files with 45 additions and 1 deletions

View file

@ -131,7 +131,8 @@ public class Graph<T> {
* @return true, wenn alle Knoten erreichbar sind
*/
public boolean allNodesConnected() {
// TODO: Graph<T>#allNodesConnected()
return false;
}
}

View file

@ -1,5 +1,48 @@
package tests.student;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import base.*;
public class GraphConnectionTest {
@Test
public void testCorrectGraph() {
Graph<String> testGraph = new Graph<String>();
Node<String> a = testGraph.addNode("A");
Node<String> b = testGraph.addNode("B");
Node<String> c = testGraph.addNode("C");
Node<String> d = testGraph.addNode("D");
testGraph.addEdge(a, b);
testGraph.addEdge(a, c);
testGraph.addEdge(c, d);
assertTrue(testGraph.allNodesConnected());
}
@Test
public void testIncorrectGraph() {
Graph<Integer> testGraph = new Graph<Integer>();
Node<Integer> one = testGraph.addNode(1);
Node<Integer> two = testGraph.addNode(2);
Node<Integer> four = testGraph.addNode(4);
Node<Integer> seven = testGraph.addNode(7);
Node<Integer> nine = testGraph.addNode(9);
testGraph.addEdge(one, seven);
testGraph.addEdge(two, nine);
assertFalse(testGraph.allNodesConnected());
}
}