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); } }
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); } }
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); } }
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); } }