public void AddDuplicateGraphExceptionThrowTest() { GraphCompositeBuilder<int, string> gcb = new GraphCompositeBuilder<int, string>(EqualityComparer<int>.Default, 0, "root"); gcb.AddNode(0, 1, "C1", false); gcb.AddNode(0, 2, "C2", false); gcb.AddEdge(1, 2); gcb.AddEdge(1, 2); }
public static void TraverSubgraphsClassInitialize(TestContext tc) { GraphCompositeBuilder<int, string> gcb = new GraphCompositeBuilder<int, string>(EqualityComparer<int>.Default, 0, "root"); gcb.AddNode(0, 1, "apple", true); gcb.AddNode(1, 2, "orange", false); gcb.AddNode(0, 3, "kiwi", true); gcb.AddNode(3, 4, "potato", false); gcb.AddNode(3, 5, "carrot", false); gcb.AddEdge(1, 2); gcb.AddEdge(3, 4); gcb.AddEdge(3, 5); gcb.AddEdge(4, 5); gc = gcb.GenerateCopy(); }
public void ConvertTest() { ConvertFromGraphToXElement<string, string> converter = new ConvertFromGraphToXElement<string, string>(); GraphCompositeBuilder<string, string> gc = new GraphCompositeBuilder<string, string>(EqualityComparer<string>.Default, "a", "root"); gc.AddNode("a", "a1", "apple", true); gc.AddNode("a", "a2", "orange", true); gc.AddNode("a1", "a11", "pear", true); gc.AddNode("a2", "a21", "potato", true); gc.AddEdge("a1", "a2"); gc.AddEdge("a1", "a11"); gc.AddEdge("a2", "a21"); gc.AddEdge("a11", "a21"); XElement result = converter.Convert(gc.GenerateCopy()); Assert.AreEqual(result.Descendants().Count(), 4); }
public void AddEdgeTest() { GraphCompositeBuilder<int, string> gcb = new GraphCompositeBuilder<int, string>(EqualityComparer<int>.Default, 0, "root"); gcb.AddNode(0, 1, "C1", false); gcb.AddNode(0, 2, "C2", false); gcb.AddEdge(1, 2); GraphComposite<int, string> gc = gcb.GenerateCopy(); Assert.AreNotEqual(gc.Subgraph.First(x => x.Key == 1).Outgoing[0], null); Assert.AreNotEqual(gc.Subgraph.First(x => x.Key == 2).Incoming[0], null); Assert.AreEqual(gc.Subgraph.First(x => x.Key == 1).Outgoing.Count, 1); Assert.AreEqual(gc.Subgraph.First(x => x.Key == 2).Incoming.Count, 1); Assert.AreEqual(gc.Subgraph.First(x => x.Key == 1).Incoming.Count, 0); Assert.AreEqual(gc.Subgraph.First(x => x.Key == 2).Outgoing.Count, 0); }
public void GenerateCopyTest() { GraphCompositeBuilder<int, string> gcb = new GraphCompositeBuilder<int, string>(EqualityComparer<int>.Default, 0, "root"); gcb.AddNode(0, 1, "C1", true); gcb.AddNode(0, 2, "C2", false); gcb.AddNode(1, 3, "C1a", true); gcb.AddNode(1, 4, "C3", false); gcb.AddNode(3, 5, "C1a1", false); gcb.AddEdge(1, 2); gcb.AddEdge(1, 3); gcb.AddEdge(4, 5); GraphComposite<int, string> gc = gcb.GenerateCopy(); Assert.AreEqual(gc.Subgraph.Count, 2); GraphComposite<int, string> c1 = gc.Subgraph.First(x => x.Key == 1); GraphComposite<int, string> c2 = gc.Subgraph.First(x => x.Key == 2); Assert.AreEqual(c1.Subgraph.Count, 2); Assert.AreEqual(c2.Subgraph, null); GraphComposite<int, string> c1a = c1.Subgraph.First(x => x.Key == 3); GraphComposite<int, string> c3 = c1.Subgraph.First(x => x.Key == 4); Assert.AreEqual(c1a.Subgraph.Count, 1); Assert.AreEqual(c3.Subgraph, null); GraphComposite<int, string> seeOneA1 = c1a.Subgraph.First(x => x.Key == 5); Assert.AreEqual(c1.Outgoing.Count, 2); Assert.ReferenceEquals(c1.Outgoing.First(x => x.Key == 2), c2); Assert.ReferenceEquals(c1.Outgoing.First(x => x.Key == 3), c3); Assert.AreEqual(c3.Outgoing.Count, 1); Assert.ReferenceEquals(c3.Outgoing.First(x => x.Key == 5), seeOneA1); Assert.AreEqual(c2.Incoming.Count, 1); Assert.ReferenceEquals(c2.Incoming[0], c1); Assert.AreEqual(c1a.Incoming.Count, 1); Assert.ReferenceEquals(c1a.Incoming[0], c1); Assert.AreEqual(seeOneA1.Incoming.Count, 1); Assert.ReferenceEquals(seeOneA1.Incoming[0], c1); }
public void KeyNotFoundGraphExceptionThrowTest2() { GraphCompositeBuilder<int, string> gcb = new GraphCompositeBuilder<int, string>(EqualityComparer<int>.Default, 0, "root"); gcb.AddEdge(0, 1); }