コード例 #1
0
        public void ProtectedEdgesPropertyIsCorrect()
        {
            GraphProtectedMethods_TESTS g = new GraphProtectedMethods_TESTS();

            TestGraphs.Add(g);

            g.AddEdge("n1", "n2");
            g.AddEdge("n2", "n3");
            g.AddEdge("n3", "n4");
            g.AddEdge("n4", "n2");

            Assert.IsTrue(g.EdgesAsNodes.Any(t => t.Item1.Id == "n1" && t.Item2.Id == "n2"));
            Assert.IsTrue(g.EdgesAsNodes.Any(t => t.Item1.Id == "n2" && t.Item2.Id == "n3"));
            Assert.IsTrue(g.EdgesAsNodes.Any(t => t.Item1.Id == "n3" && t.Item2.Id == "n4"));
            Assert.IsTrue(g.EdgesAsNodes.Any(t => t.Item1.Id == "n2" && t.Item2.Id == "n4"));

            Assert.IsFalse(
                g.EdgesAsNodes.Any(
                    t => (t.Item1.Id == "n1" && t.Item2.Id == "n3") || (t.Item1.Id == "n3" && t.Item2.Id == "n1")));
            Assert.IsFalse(
                g.EdgesAsNodes.Any(
                    t => (t.Item1.Id == "n1" && t.Item2.Id == "n4") || (t.Item1.Id == "n4" && t.Item2.Id == "n1")));

            Assert.IsTrue(AllGraphsHaveNoZeroDegreeNodes());
        }
コード例 #2
0
        public void ProtectedAddEdgeThrowsExceptionWhenAddingNodesAndAddToGraphIsFalse()
        {
            GraphProtectedMethods_TESTS g = new GraphProtectedMethods_TESTS();

            g.AddEdge("n1", "n2");
            g.AddEdge("n2", "n3");

            GraphNode n4 = NewGraphNode("n4");

            g.AddEdge(n4, g.Nodes.First(n => n.Id == "n3"), false);
        }
コード例 #3
0
        public void ProtectedAddEdgeAddsEdgeToExistingNodes()
        {
            GraphProtectedMethods_TESTS g = new GraphProtectedMethods_TESTS();

            TestGraphs.Add(g);

            g.AddEdge("n1", "n2");
            g.AddEdge("n2", "n3");

            g.AddEdge(g.Nodes.First(n => n.Id == "n1"), g.Nodes.First(n => n.Id == "n3"));
            Assert.IsTrue(g.Nodes.First(n => n.Id == "n3").Neighbors.Any(n => n.Id == "n1"));

            Assert.IsTrue(AllGraphsHaveNoZeroDegreeNodes());
        }
コード例 #4
0
        public void ProtectedRemoveEdgeRemovesCorrectly()
        {
            GraphProtectedMethods_TESTS graph = new GraphProtectedMethods_TESTS();

            TestGraphs.Add(graph);

            graph.AddEdge("n1", "n2", true);
            graph.AddEdge("n2", "n3", true);
            graph.AddEdge("n1", "n3");

            Assert.IsTrue(graph.Nodes.All(n => n.Degree == 2));

            Node n1 = graph.Nodes.First(n => n.Id == "n1");
            Node n2 = graph.Nodes.First(n => n.Id == "n2");
            Node n3 = graph.Nodes.First(n => n.Id == "n3");

            graph.RemoveEdge(n1, n3);

            Assert.AreEqual("1,1,2", String.Join(",", graph.Nodes.Select(n => n.Degree).OrderBy(n => n)));
            Assert.IsTrue(AllGraphsHaveNoZeroDegreeNodes());
        }
コード例 #5
0
        public void ProtectedAddEdgeAddsNodesToGraph()
        {
            GraphProtectedMethods_TESTS g = new GraphProtectedMethods_TESTS();

            TestGraphs.Add(g);

            g.AddEdge("n1", "n2");
            g.AddEdge("n2", "n3");

            Node n4 = new Node("n4", g);

            g.AddEdge(n4, g.Nodes.First(n => n.Id == "n2"), true);
            Assert.IsTrue(g.Nodes.First(n => n.Id == "n2").Neighbors.Any(n => n.Id == "n4"),
                          "Connecting one existing node with one new one failed.");

            Node n5 = new Node("n5", g);
            Node n6 = new Node("n6", g);

            g.AddEdge(n5, n6, true);
            Assert.IsTrue(g.Nodes.First(n => n.Id == "n5").Neighbors.Any(n => n.Id == "n6"),
                          "Connecting two new nodes and adding to graph failed.");

            Assert.IsTrue(AllGraphsHaveNoZeroDegreeNodes());
        }
コード例 #6
0
        public void ProtectedRemoveEdgeReturnsCorrectValue()
        {
            GraphProtectedMethods_TESTS graph = new GraphProtectedMethods_TESTS();

            TestGraphs.Add(graph);

            Node n1 = graph.NewGraphNode("n1");
            Node n2 = graph.NewGraphNode("n2");

            graph.AddEdge(n1, n2);

            Assert.IsTrue(graph.Nodes.All(n => n.Degree == 1));

            Assert.IsTrue(graph.RemoveEdge(n1, n2));
            Assert.IsFalse(graph.RemoveEdge(n1, n2));

            Assert.IsTrue(AllGraphsHaveNoZeroDegreeNodes());
        }