public void BFSWithAction_NoVertices_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); foreach (var vertex in graph.BFS(1, v => { })) { } }
public void BFSWithAction_1Vertex_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); graph.AddVertex(1); foreach (var vertex in graph.BFS(1, v => Assert.AreEqual(1, v))) { Assert.AreEqual(1, vertex); } }
public void BFS_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); graph.AddEdge(1, 2); graph.AddEdge(1, 3); graph.AddEdge(1, 5); graph.AddEdge(2, 4); graph.AddEdge(2, 6); graph.AddEdge(3, 7); graph.AddEdge(5, 6); int idx = 0; var path = new[] { 1, 2, 3, 5, 4, 6, 7 }; foreach (var vertex in graph.BFS(1)) { Assert.AreEqual(path[idx++], vertex); } Assert.AreEqual(path.Length, idx); }
public void BFSWithAction_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); graph.AddEdge(1, 2); graph.AddEdge(1, 3); graph.AddEdge(1, 5); graph.AddEdge(2, 4); graph.AddEdge(2, 6); graph.AddEdge(3, 7); graph.AddEdge(5, 6); int pathIdx = 0; int lastVerticesIdx = 0; var lastVertices = new[] { 4, 6, 7 }; var path = new[] { 1, 2, 3, 5, 4, 6, 7 }; foreach (var vertex in graph.BFS(1, v => Assert.AreEqual(lastVertices[lastVerticesIdx++], v))) { Assert.AreEqual(path[pathIdx++], vertex); } Assert.AreEqual(path.Length, pathIdx); Assert.AreEqual(lastVertices.Length, lastVerticesIdx); }