Exemple #1
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);
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public void addNodeListTest()
        {
            try
            {
                Map map = new Map();
                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);

                map.setPoiList(nodeList);

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

                Assert.IsNotNull(nodeList);
                Assert.IsNotNull(mapNodes);
                Assert.Equals(nodeList, mapNodes);
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Exemple #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);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
0
        public List<Node> populateNodes()
        {
            List<Node> tmpNodeList = new List<Node>();
            foreach (JSONObject n in nodes.list) //1st degree : list of nodes (only 1 element)
            {
                //Debug.Log(n.ToString());
                foreach (JSONObject poi in n.list[0].list) //3rd degree : list of pois
                {
                    //print(poi.ToString());
                    PointOfInterest p = new PointOfInterest((int)poi.list[0].n, (int)poi.list[3].n, (int)poi.list[4].n, (int)poi.list[5].n);

                    foreach (JSONObject b in poi.list[6].list)
                    {
                        //Debug.Log(b.ToString() + "\n");
                        iBeaconServer beacon = new iBeaconServer(poi.list[6].list[0].str, int.Parse(poi.list[6].list[1].str), int.Parse(poi.list[6].list[2].str));
                        p.setBeacon(beacon);
                    }
                    //foreach (JSONObject c in poi.list[7].list) //Media list
                    //{
                        //Debug.Log(c.ToString() + "\n");
                        /*foreach (JSONObject i in poi.list[8].list[0].list) // Image list
                        {
                            ExhibitionContent image = new Image(i.list[0].str, i.list[1].str, i.list[2].str);
                            p.addContent(image);
                            //Debug.Log(i.ToString() + "\n");
                        }*/
                        if (poi.list[7].list[1].list.Count > 0)
                        {
                            foreach (JSONObject v in poi.list[7].list[1].list) // Video list
                            {
                                string videoPath = v.list[0].str.Remove(0, 13);
                                //Remove extension type of the file
                                //print(videoPath);
                                Video video = new Video(videoPath, v.list[1].str, v.list[2].str);
                                p.addContent(video);
                                //Debug.Log(v.list[0].ToString() + "\n");
                            }
                        }

                        if (poi.list[7].list[2].list.Count > 0)
                        {
                            foreach (var a in poi.list[7].list[2].list) // Audio list
                            {
                                string audioPath = a.list[0].str.Remove(0, 13);
                                string mp3Path = audioPath.Remove(audioPath.Length - 4);
                                //print(mp3Path);
                                Audio audio = new Audio(mp3Path, a.list[1].str, a.list[2].str);
                                p.addContent(audio);
                            }
                        }
                    //}

                    for (int i = 0; i < poi.list[1].Count; i++) //Add all the poi description in the point of interest
                    {
                        string title = RemoveHtml.RemoveHtmlTags(poi.list[1].list[i].list[1].str);
                        string descr = RemoveHtml.RemoveHtmlTags(poi.list[2].list[i].list[1].str);
                        Description poiD = new Description(title, descr, poi.list[1].list[i].list[0].str);
                        p.addPoiDescription(poiD);
                    }

                    foreach (var sp in poi.list[8].list)
                    {
                        POS storyPoint = new POS((int)poi.list[0].n, (int)poi.list[3].n, (int)poi.list[4].n, (int)poi.list[5].n, (int)sp.list[1].n);

                        for (int i = 0; i < sp.list[2].Count; i++) // description and title JSON object
                        {
                            string title = RemoveHtml.RemoveHtmlTags(sp.list[2].list[i].list[1].str);
                            string descr = RemoveHtml.RemoveHtmlTags(sp.list[3].list[i].list[1].str);
                            Description spd = new Description(title, descr, sp.list[2].list[i].list[0].str);
                            storyPoint.addPoiDescription(spd);
                        }

                        //foreach (var c in sp.list[4].list) //storypoint content list
                        //{
                            /*foreach (var i in sp.list[4].list[0].list) //image list
                            {
                                if (i != null)
                                {
                                    ExhibitionContent image = new Image(i.list[0].str, i.list[2].str, i.list[1].str);
                                    storyPoint.addContent(image);
                                }
                            }*/

                            if (sp.list[4].list[1].list.Count > 0)
                            {
                                foreach (var v in sp.list[4].list[1].list) //video list
                                {
                                    string videoPath = v.list[0].str.Remove(0, 13);
                                    //Remove extension type of the file
                                    //print(videoPath);
                                    Video video = new Video(videoPath, v.list[1].str, v.list[2].str);
                                    storyPoint.addContent(video);
                                }
                            }

                            if (sp.list[4].list[2].list.Count > 0)
                            {
                                foreach (var a in sp.list[4].list[2].list) //audio list
                                {
                                    string audioPath = a.list[0].str.Remove(0, 13);
                                    string mp3Path = audioPath.Remove(audioPath.Length - 4);
                                    //print(mp3Path);
                                    Audio audio = new Audio(mp3Path, a.list[1].str, a.list[2].str);
                                    storyPoint.addContent(audio);
                                }
                            }
                        //}
                        tmpNodeList.Add(storyPoint);
                    }

                    tmpNodeList.Add(p);
                }//end of poi foreach

                foreach (JSONObject pot in n.list[1].list) //3rd degree : list of pot
                {
                    PointOfTransition pointOfTransition = new PointOfTransition((int)pot.list[0].n, (int)pot.list[2].n, (int)pot.list[3].n, (int)pot.list[4].n, pot.list[1].str);
                    tmpNodeList.Add(pointOfTransition);
                    //Debug.Log(pot.ToString() + "\n");
                }

            }//end of root foreach

            return tmpNodeList;
        }
Exemple #7
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);
            }
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
            }
        }
Exemple #10
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);
            }
        }
Exemple #11
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);
            }
        }
Exemple #12
0
        public void BFSTestTwoNodesVerticesIsNull()
        {
            try
            {
                Graph g = new Graph();
                Node n1 = new PointOfInterest(1, 0, 0, 1);
                Node n2 = new PointOfInterest(2, 0, 0, 1);

                Assert.Equals(null, g.BFS(n1, n2));
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception:\n\n{0}", e.Message);
            }
        }
Exemple #13
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);
            }
        }