public void CycleDirectedGraph_Returns_False() { // Arrange var graph = GraphBuilderHelper.CreateListArray(5); graph[0].Add(1); graph[0].Add(2); graph[3].Add(0); graph[4].Add(0); // Act bool result = CycleDirectedGraph.DoesGraphContainsCycle(graph); // Assert Assert.IsFalse(result); }
public void GetLongestPath_Returns_LongestPath_With_ListGraph_And_Source_Vertix() { // Arrange var graph = GraphBuilderHelper.CreateListArray <EdgeNode>(6); graph[0].Add(new EdgeNode(1, 3)); graph[1].Add(new EdgeNode(2, 4)); graph[1].Add(new EdgeNode(5, 2)); graph[5].Add(new EdgeNode(3, 6)); graph[5].Add(new EdgeNode(4, 5)); // Act int[] parents; int longestPath = LongestPathInDirectedAcyclicGraph.GetLongestPath(graph, 0, out parents).Max(); // Assert Assert.AreEqual(11, longestPath); CollectionAssert.AreEqual(new int[] { -1, 0, 1, 5, 5, 1 }, parents); }