Example #1
0
        public void testGetEdgesWithUncontainedstrings()
        {
            AdjacencyListGraph <string, string> g = graph(n1);

            Assert.IsNull(g.GetEdges(n1, n2));
            Assert.IsNull(g.GetEdges(n2, n1));
            Assert.IsNull(g.GetEdges(n3, n4));
        }
Example #2
0
        public void testGetEdgesSimple()
        {
            AdjacencyListGraph <string, string> g = graph(n1, n2);

            g.AddEdge(e1);

            ISet <string> s1 = g.GetEdges(n1, n2);

            Assert.IsTrue(s1.Contains(e1.Label));
            Assert.AreEqual(1, s1.Count);

            ISet <string> s2 = g.GetEdges(n2, n1);

            Assert.IsFalse(s2.Contains(e1.Label));
            Assert.AreEqual(0, s2.Count);
        }
Example #3
0
        public void testRemovestringWithChildren()
        {
            AdjacencyListGraph <string, string> g = graph(n1, n2);

            g.AddEdge(e1);

            Assert.IsTrue(g.RemoveNode(n1));
            Assert.IsFalse(g.ContainsNode(n1));
            Assert.IsFalse(g.EdgeExists(n1, n2));
            Assert.IsNull(g.GetEdges(n1, n2));
        }
Example #4
0
        public void CalcPath()
        {
            for (int i = 2; i <= _length; i++)
            {
                if (i == 2)
                {
                    var paths = new List <List <int> >();
                    var edges = _graph.GetEdges();
                    foreach (var item in edges)
                    {
                        if (item.Start.Key < item.End.Key)
                        {
                            var path = new List <int>()
                            {
                                item.Start.Identifier,
                                item.End.Identifier
                            };
                            paths.Add(path);
                        }
                    }
                    _lengthPaths[i] = paths;
                }
                else
                {
                    var paths    = new List <List <int> >();
                    var prePaths = _lengthPaths[i - 1];

                    foreach (var prePath in prePaths)
                    {
                        var startVertex = _graph.GetVertexByKey(prePath[0]);
                        var startEdges  = _graph.GetVertexEdge(startVertex);
                        foreach (var startEdge in startEdges)
                        {
                            var endVertex = startEdge.End;
                            if (!prePath.Contains(endVertex.Identifier))
                            {
                                var path = new List <int>(prePath);
                                path.Insert(0, endVertex.Identifier);
                                paths.Add(path);
                            }
                        }
                    }


                    _lengthPaths[i] = paths;
                }
            }
        }
Example #5
0
        public void testReplaceNodeWithParents()
        {
            AdjacencyListGraph <string, string> g = graph(n1, n2);
            Edge <string, string> e1 = new Edge <string, string>(n2, n1, "one");

            g.AddEdge(e1);
            Assert.IsTrue(g.EdgeExists(n2, n1));

            string n2_post = "new_label";

            g.ReplaceNode(n2, n2_post);
            Assert.IsFalse(g.ContainsNode(n2));
            Assert.IsTrue(g.ContainsNode(n2_post));

            Assert.IsFalse(g.EdgeExists(n2, n1));
            Assert.IsTrue(g.EdgeExists(n2_post, n1));
            Assert.AreEqual(1, g.GetEdges(n2_post, n1).Count);
        }
Example #6
0
        public void testGetEdgesBothNull()
        {
            AdjacencyListGraph <string, string> g = graph();

            g.GetEdges(null, null);
        }
Example #7
0
        public void testGetEdgesOneNull()
        {
            AdjacencyListGraph <string, string> g = graph(n1);

            g.GetEdges(null, n1);
        }