public void DijkstraSimpleGraphShould_Find_Path_In_Multi_Edges() { var graph = new Graph.Simple.Graph(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.Connect(1, 2, 2); graph.Connect(1, 3, 3); graph.Connect(2, 4, 4); graph.Connect(3, 4, 3); graph.Connect(3, 4, 2); graph.Connect(3, 4, 4); graph.Connect(3, 5, 1); graph.Connect(4, 6, 6); var result = graph.Dijkstra(1, 6); uint[] path = result.GetPath().ToArray(); Assert.Equal <uint>(1, path[0]); Assert.Equal <uint>(3, path[1]); Assert.Equal <uint>(4, path[2]); Assert.Equal <uint>(6, path[3]); Assert.Equal(11, result.Distance); Assert.True(result.IsFounded); }
public void DijkstraSimpleGraphNot_Should_Find_Path_In_Graph() { var graph = new Graph.Simple.Graph(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.Connect(1, 2, 2); graph.Connect(1, 3, 3); graph.Connect(2, 4, 4); graph.Connect(3, 4, 2); graph.Connect(3, 5, 1); var result = graph.Dijkstra(1, 6); Assert.False(result.IsFounded); }
public void DijkstraSimpleGraphShould_Find_Path_In_Override_Node() { var graph = new Graph.Simple.Graph(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.Connect(1, 2, 2); graph.Connect(1, 3, 6); graph.Connect(2, 3, 2); graph.Connect(3, 4, 1); graph.Connect(4, 5, 1); graph.Connect(1, 6, 5); var result = graph.Dijkstra(1, 5); uint[] path = result.GetPath().ToArray(); Assert.Equal <uint>(1, path[0]); Assert.Equal <uint>(2, path[1]); Assert.Equal <uint>(3, path[2]); Assert.Equal <uint>(4, path[3]); Assert.Equal <uint>(5, path[4]); Assert.Equal(6, result.Distance); Assert.True(result.IsFounded); }
public void Dijkstra_Should_Concern_Depth_In_SimpleGraph() { var graph = new Graph.Simple.Graph(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.AddNode(); graph.Connect(1, 2, 1); graph.Connect(1, 3, 1); graph.Connect(1, 4, 5); graph.Connect(3, 4, 2); var result = graph.Dijkstra(1, 4, 1); Assert.True(result.IsFounded); Assert.Equal(5, result.Distance); uint[] path = result.GetPath().ToArray(); Assert.Equal((uint)1, path[0]); Assert.Equal((uint)4, path[1]); }
public void SimpleGraph_CalculatePageRank_Should_Calculate_Correct_PageRank() { var g = new Graph.Simple.Graph(); uint a = g.AddNode(); uint b = g.AddNode(); uint c = g.AddNode(); uint d = g.AddNode(); g.Connect(a, b); g.Connect(a, c); g.Connect(b, d); g.Connect(c, a); g.Connect(c, b); g.Connect(c, d); g.Connect(d, c); var result = g.PageRank(); Assert.True(Math.Abs(result[c] - 0.35625) < 0.0001); }