예제 #1
0
        public void AddVerticesAndEdge_TwiceTheSameEdgeInstance_ReturnsFalse()
        {
            var graph = new UndirectedUnweightedGraph <string>();

            var edge = new Tuple <string, string>("Arnold Schwarzenegger", "The Terminator");

            graph.AddVerticesAndEdgeRange(new[] { edge });
            var added = graph.AddVerticesAndEdgeRange(new[] { edge });

            Assert.IsFalse(added);
        }
예제 #2
0
        public void AddVerticesAndEdge_TwoEdgesWithSameData_ReturnsFalse()
        {
            var graph = new UndirectedUnweightedGraph <string>();

            var edge1 = new Tuple <string, string>("Arnold Schwarzenegger", "The Terminator");
            var edge2 = new Tuple <string, string>("Arnold Schwarzenegger", "The Terminator");

            graph.AddVerticesAndEdgeRange(new[] { edge1 });
            var added = graph.AddVerticesAndEdgeRange(new[] { edge2 });

            Assert.IsFalse(added);
        }
예제 #3
0
        public void AddVerticesAndEdge_SelfEdge_ReturnsFalse()
        {
            var graph = new UndirectedUnweightedGraph <string>();

            var edge = new Tuple <string, string>("Arnold Schwarzenegger", "Arnold Schwarzenegger");

            var added = graph.AddVerticesAndEdgeRange(new[] { edge });

            Assert.IsFalse(added);
        }
예제 #4
0
        public void GetSuccessors_VertexExist_ReturnsChildren()
        {
            var graph = new UndirectedUnweightedGraph <int>();

            graph.AddVerticesAndEdgeRange(new List <Tuple <int, int> >
            {
                new Tuple <int, int>(1, 2),
                new Tuple <int, int>(1, 3)
            });

            var res = graph.GetSuccessors(1);

            Assert.AreEqual(2, res.Count);
            Assert.IsTrue(res.Contains(2));
            Assert.IsTrue(res.Contains(3));
        }
예제 #5
0
        public void GetShortestPath_ShortestPathExist_CorrectPath()
        {
            var graph = new UndirectedUnweightedGraph <int>();

            graph.AddVerticesAndEdgeRange(new List <Tuple <int, int> >
            {
                new Tuple <int, int>(1, 2),
                new Tuple <int, int>(2, 3),
                new Tuple <int, int>(3, 4)
            });

            int fromVertex = 1;
            int toVertex   = 4;

            var algo = new UndirectedUnweightedGraphAlgorithms <int>(graph);
            var func = algo.ComputeShortestPathFunc(fromVertex);

            var res = func.Invoke(toVertex).ToList();

            Assert.AreEqual(3, res.Count);
            Assert.AreEqual(2, res[0]);
            Assert.AreEqual(3, res[1]);
            Assert.AreEqual(4, res[2]);
        }