public void MinimumSpanningTreeTest() { var edges = new List <(string, string)> { ("a", "b"), ("a", "d"), ("b", "c"), ("c", "f"), ("c", "a"), ("d", "c"), ("f", "d"), ("f", "a"), ("f", "c"), ("f", "b"), ("f", "g"), ("g", "b"), ("g", "a"), ("g", "c"), ("g", "d"), }; var graph = ImmutableSparseGraph <string> .Create(edges); var result = graph.MinimumSpanningTree("a"); CollectionAssert.AreEqual( result, new List <(string, string)> { ("a", "b"), ("a", "d"), ("b", "c"), ("c", "f"), ("f", "g") });
public void BfsShortTest() { var edges = new List <(string, string)> { ("a", "b"), ("a", "d"), ("b", "c"), ("c", "f"), ("c", "a"), ("d", "c"), ("f", "d"), ("f", "a"), ("f", "c"), ("f", "b"), ("f", "g"), ("g", "b"), ("g", "a"), ("g", "c"), ("g", "d"), }; var graph = ImmutableSparseGraph <string> .Create(edges); var result = graph.Bfs("f", "g"); CollectionAssert.AreEqual( result, new List <string> { "f", "g" }); }
public void CreateTest() { var edges = new List <(string, string)> { ("a", "b"), ("a", "f"), ("a", "g"), ("a", "c"), ("b", "c"), ("d", "c"), ("f", "d"), ("f", "a"), ("f", "c"), ("f", "b"), ("g", "b"), ("g", "a"), ("g", "c"), ("g", "d"), }; var graph = ImmutableSparseGraph <string> .Create(edges); var matches = new List <string>(10); graph.Find("a", matches.Add); CollectionAssert.AreEquivalent( new [] { "b", "c", "f", "g" }, matches); matches = new List <string>(10); graph.Find("b", matches.Add); CollectionAssert.AreEquivalent( new [] { "c" }, matches); matches = new List <string>(10); graph.Find("d", matches.Add); CollectionAssert.AreEquivalent( new [] { "c" }, matches); matches = new List <string>(10); graph.Find("f", matches.Add); CollectionAssert.AreEquivalent( new [] { "d", "a", "c", "b" }, matches); matches = new List <string>(10); graph.Find("g", matches.Add); CollectionAssert.AreEquivalent( new [] { "b", "a", "c", "d" }, matches); }