public void Prim_WhenDifferentSources_ThenSameMST() { // when IUndirectedGraph <int, object, WeightProp> result1 = MinimalSpanningTree.Prim(graph, graph[1]); IUndirectedGraph <int, object, WeightProp> result4 = MinimalSpanningTree.Prim(graph, graph[4]); // then result1.EdgesCount.Should().Be(result4.EdgesCount); result1.Edges.Should().BeEquivalentTo(result4.Edges); }
public void Prim_ThenMST() { // when IUndirectedGraph <int, object, WeightProp> result = MinimalSpanningTree.Prim(graph, graph[0]); // then double mstSize = result.Edges .Select(edge => result.Properties[edge].Weight) .Sum(); result.VerticesCount.Should().Be(graph.VerticesCount); result.Vertices.Should().BeEquivalentTo(graph.Vertices); result.EdgesCount.Should().Be(4); result.Edges.Should().BeEquivalentTo( new Edge <int>[] { graph[0, 1], graph[0, 2], graph[2, 4], graph[3, 4] }); mstSize.Should().BeApproximately(12.0, precision); }