public static void TestMakeGraphFromTree() { var graph = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root }); var expected = new Dictionary <string, List <string> > { { "a", new List <string> { "c" } }, { "c", new List <string> { "e", "d", "a" } }, { "e", new List <string> { "c" } }, { "d", new List <string> { "f", "b", "c" } }, { "f", new List <string> { "d" } }, { "b", new List <string> { "d" } } }; CollectionAssert.AreEquivalent(expected, graph.VertexChildNodes); }
public static void TestIsTheSameGraph() { var graph = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root }); var tour = EulerGraph <string> .MakeTour(graph, "a"); graph.Tours.Add(tour); var expected = new List <string> { "a", "c", "e", "c", "d", "f", "d", "b", "d", "c", "a" }; CollectionAssert.AreEquivalent(expected, tour); var graph2 = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root2 }); var tour2 = EulerGraph <string> .MakeTour(graph2, "g"); graph2.Tours.Add(tour2); var expected2 = new List <string> { "g", "h", "g", "j", "k", "j", "i", "j", "g" }; CollectionAssert.AreEquivalent(expected2, tour2); Assert.IsTrue(graph.BothBelong("f", "e")); Assert.IsFalse(graph.BothBelong("f", "g")); Assert.IsTrue(graph2.BothBelong("j", "i")); Assert.IsFalse(graph2.BothBelong("f", "i")); }
private void CreateEuler(object sender, RoutedEventArgs e) { var window = new CreateEulerWindow(); window.ShowDialog(); int nodes = window.NodesCount; Graph.Set(EulerGraph.RandEulerGraph(nodes)); Graph.OnChange(); GraphRenderer.Displayer = new CircleDisplayer(); }
public static void TestMakeTourFromGraph() { var graph = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root }); var tour = EulerGraph <string> .MakeTour(graph, graph.Roots[0]); graph.Tours.Add(tour); var expected = new List <string> { "a", "c", "e", "c", "d", "f", "d", "b", "d", "c", "a" }; CollectionAssert.AreEquivalent(expected, tour); }
private void IsEuler(object sender, RoutedEventArgs e) { List <int> path = EulerGraph.EulerianPath(Graph); string message = "Oto trasa eulera : "; if (path != null) { path.ForEach(v => message += (v + 1) + " "); message = "Graf ma cykl eulera." + Environment.NewLine + message; MessageBox.Show(message); } else { message = "Graf nie ma cyklu eulera"; MessageBox.Show(message); } }
public static void TestChangeGraphRoot() { var graph = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root }); var tour = EulerGraph <string> .MakeTour(graph, "a"); var expected = new List <string> { "a", "c", "e", "c", "d", "f", "d", "b", "d", "c", "a" }; CollectionAssert.AreEquivalent(expected, tour); tour = EulerGraph <string> .MakeTour(graph, "d"); expected = new List <string> { "d", "f", "d", "b", "d", "c", "e", "c", "a", "c", "d" }; CollectionAssert.AreEquivalent(expected, tour); }
public static void TestAddEdgeForTwoGraph() { var graph = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root }); var tour = EulerGraph <string> .MakeTour(graph, "a"); graph.Tours.Add(tour); var expected = new List <string> { "a", "c", "e", "c", "d", "f", "d", "b", "d", "c", "a" }; CollectionAssert.AreEquivalent(expected, tour); var graph2 = EulerGraph <string> .MakeGraph(new List <EulerNode <string> > { Root2 }); var tour2 = EulerGraph <string> .MakeTour(graph2, "g"); graph2.Tours.Add(tour2); var expected2 = new List <string> { "g", "h", "g", "j", "k", "j", "i", "j", "g" }; CollectionAssert.AreEquivalent(expected2, tour2); var mergedGraph = EulerGraph <string> .Merge(graph, graph2); var expected3 = new List <string> { "a", "c", "e", "c", "d", "f", "d", "b", "d", "c", "a", "g", "h", "g", "j", "k", "j", "i", "j", "g", "a" }; CollectionAssert.AreEquivalent(expected3, mergedGraph.Tours[0]); }