38 lines
930 B
Java
Raw Normal View History

2019-07-25 23:11:26 +03:00
package com.baeldung.graph;
import org.junit.Test;
public class GraphUnitTest {
@Test
public void givenDirectedGraph_whenDFS_thenPrintAllValues() {
Graph graph = createDirectedGraph();
graph.dfs(0);
System.out.println();
graph.dfsWithoutRecursion(0);
}
@Test
public void givenDirectedGraph_whenGetTopologicalSort_thenPrintValuesSorted() {
Graph graph = createDirectedGraph();
graph.topologicalSort(0);
}
private Graph createDirectedGraph() {
2019-07-28 00:01:06 +03:00
Graph graph = new Graph();
graph.addVertex(0);
graph.addVertex(1);
graph.addVertex(2);
graph.addVertex(3);
graph.addVertex(4);
graph.addVertex(5);
2019-07-25 23:11:26 +03:00
graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 3);
graph.addEdge(2, 3);
graph.addEdge(3, 4);
graph.addEdge(4, 5);
return graph;
}
}