Esempio n. 1
0
        public void hasAdjacentNodeTest()
        {
            try
            {

                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);
                Node n3 = new PointOfInterest(3, 0, 0, 1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);
                g.InsertNewVertex(n3);

                n1.addListOfAdjacentNodes(new Dictionary<Node, float>() { { n2, 4 } });
                n2.addListOfAdjacentNodes(new Dictionary<Node, float>() { { n1, 3 } });
                Assert.IsNotNull(g);
                Assert.IsNotNull(n1);
                Assert.IsNotNull(n2);
                Assert.IsNotNull(n3);
                Assert.True(n1.isAdjacent(n2),
                    "This tests if isAdjacent returns true if a node is adjacent to a given one.");
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 2
0
        public void addNodeTest()
        {
            try
            {
                Map map = new Map();
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);

                List<Node> nodeList = new List<Node>();

                nodeList.Add(n1);
                nodeList.Add(n2);
                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);

                map.addNode(n1);
                map.addNode(n2);

                Graph mapGraph = map.getGraph();
                List<Node> mapNodes = map.GetPoiNodes();

                Assert.IsNotNull(nodeList);
                Assert.IsNotNull(g);
                Assert.IsNotNull(mapGraph);
                Assert.IsNotNull(mapNodes);

                Assert.Equals(nodeList, mapNodes);
                Assert.Equals(g, mapGraph);
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 3
0
        public void BFSTestOneNodeIsVisited()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);
                Node n3 = new PointOfInterest(3, 0, 0, 1);
                Node n4 = new PointOfInterest(4, 0, 0, 1);
                Node n5 = new PointOfInterest(5, 0, 0, 1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);
                g.InsertNewVertex(n3);
                g.InsertNewVertex(n4);
                g.InsertNewVertex(n5);
                n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n2, 4}, {n3, 2}});
                n2.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n3, 3}, {n5, 3}, {n4, 2}});
                n3.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 4}, {n5, 5}, {n2, 1}});
                n4.addListOfAdjacentNodes(new Dictionary<Node, float>() {});
                n5.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 1}});
                g.BFS(n1);
                State status = n4.getState();

                Assert.IsNotNull(g);
                Assert.IsNotNull(n1);
                Assert.IsNotNull(n2);
                Assert.IsNotNull(n3);
                Assert.IsNotNull(n4);
                Assert.IsNotNull(n5);
                Assert.IsNotNull(status);
                Assert.Equals(State.Visited, status);
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 4
0
        public void BFSTestOneNodeNoPath()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                g.InsertNewVertex(n1);

                State status = n1.getState();

                Assert.Equals(State.UnVisited, status);
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 5
0
        public void shortest_pathTestWithOneNode()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);

                List<Node> nodelist = new List<Node>();
                nodelist.Add(n1);
                nodelist.Add(n2);

                g.InsertNewVertex(n1);
                n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n1, 4}});

                Assert.Equals(nodelist, g.shortest_path(n1, n1));
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 6
0
        public void shortest_pathTestNoPath()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0,  1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);
                Node n3 = new PointOfInterest(3, 0, 0,  1);
                Node n4 = new PointOfInterest(4, 0, 0,  1);
                Node n5 = new PointOfInterest(5, 0, 0,  1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);
                g.InsertNewVertex(n3);
                g.InsertNewVertex(n4);
                g.InsertNewVertex(n5);

                n1.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n2, 4}, {n3, 2}});
                n2.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n3, 3}, {n4, 2}});
                n3.addListOfAdjacentNodes(new Dictionary<Node, float>() {{n4, 4}, {n2, 1}});
                n4.addListOfAdjacentNodes(new Dictionary<Node, float>() {});
                n5.addListOfAdjacentNodes(new Dictionary<Node, float>() {});

                Assert.IsNotNull(g);
                Assert.IsNotNull(n1);
                Assert.IsNotNull(n2);
                Assert.IsNotNull(n3);
                Assert.IsNotNull(n4);
                Assert.IsNotNull(n5);
                Assert.Equals(null, g.shortest_path(n1, n5));
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 7
0
        public void shortest_pathTestIsNull()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);

                Assert.Equals(null, g.shortest_path(n1, n2));
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 8
0
        public void FindByKeyTest()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0,  1);
                Node n2 = new PointOfInterest(2, 0, 0,  1);
                Node n3 = new PointOfInterest(3, 0, 0,  1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);
                g.InsertNewVertex(n3);

                Assert.Equals(n2, g.FindByKey(2));
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 9
0
        public void ExistKeyTest()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);

                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);

                Assert.True(false);
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Esempio n. 10
0
        public void getGraphTest()
        {
            try
            {
                Map map = new Map();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);
                map.addNode(n1);
                map.addNode(n2);

                Graph g = new Graph();
                g.InsertNewVertex(n1);
                g.InsertNewVertex(n2);

                Assert.Equals(g, map.getGraph());
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }