Example #1
0
        //[InlineData(new[] { "Metroville", "Pandora," }, new TripResult(true, 82))]
        public void Airplane_Trip_Test()
        {
            //arrange
            myGraph <string> testFlight = new myGraph <string>();
            var pandora      = testFlight.AddVertex("Pandora");
            var metroville   = testFlight.AddVertex("Metroville");
            var narnia       = testFlight.AddVertex("Narnia");
            var arendelle    = testFlight.AddVertex("Arendelle");
            var naboo        = testFlight.AddVertex("Naboo");
            var monstropolis = testFlight.AddVertex("Monstropolis");

            testFlight.AddEdge(pandora, metroville, 82);
            testFlight.AddEdge(pandora, arendelle, 150);
            testFlight.AddEdge(narnia, metroville, 37);
            testFlight.AddEdge(narnia, naboo, 250);

            testFlight.AddEdge(narnia, monstropolis, 73);
            testFlight.AddEdge(naboo, metroville, 26);
            testFlight.AddEdge(arendelle, metroville, 99);
            testFlight.AddEdge(arendelle, monstropolis, 42);

            testFlight.AddEdge(monstropolis, metroville, 105);
            var expected = new TripResult(true, 82);

            string[] stops = new string[] { "Metroville", "Pandora," };

            //act
            TripResult actual = GraphChallenges.GraphChallenges.PlaneTrip(testFlight, stops);

            //Assert
            Assert.Equal(expected, actual);
        }
Example #2
0
        public void Get_Vertices_Test()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");

            //Arrange
            var actual = testGraph.GetVertices();

            //Assert
            Assert.Equal(bob, actual[0]);
        }
Example #3
0
        public void Size_Method_Works()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();

            testGraph.AddVertex("Bob");

            //act
            var actual = testGraph.Size();

            //Assert
            Assert.Equal(1, actual);
        }
Example #4
0
        public void Add_Edge_Works()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");

            //Arrange
            testGraph.AddEdge(bob, carol, 13);
            var actual = bob.Neighbors[0].Weight;

            //Assert
            Assert.Equal(13, actual);
        }
Example #5
0
        public void Add_Vertex_Works()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();


            //act
            var actual   = testGraph.AddVertex("Bob");
            var expected = testGraph.Vertices[0];



            //Assert
            Assert.Equal(expected, actual);
        }
Example #6
0
        public void Breadth_First_Test_A()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");
            var diana = testGraph.AddVertex("Diana");

            testGraph.AddEdge(bob, carol, 13);
            testGraph.AddEdge(bob, diana, 9);

            //act
            var actual = testGraph.BreadthFirst(bob);

            //Assert
            Assert.Equal(testGraph.Size(), actual.Count());
        }
Example #7
0
        public void Get_Neighbors_Test()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");
            var diana = testGraph.AddVertex("Diana");

            testGraph.AddEdge(bob, carol, 13);
            testGraph.AddEdge(bob, diana, 9);

            //act
            var actual = testGraph.GetNeighbors(bob);

            //Assert
            Assert.Equal(diana, actual[1]);
        }
Example #8
0
        public static TripResult PlaneTrip(myGraph <string> graph, string[] stops)
        {
            int length  = stops.Length;
            var current = graph.FindVertex(stops[0]);
            int?sum     = 0;


            while (current != null)
            {
                int i = 1;
                for (int j = 0; j < current.Neighbors.Count; j++)
                {
                    //if (current.Neighbors[j].Neighbor.Value == stops[i])
                    //{
                    //sum += current.Neighbors[j].Weight;
                    //current = current.Neighbors[j].Neighbor;
                    //  break;
                    //}
                    if (current.HasNeighbor(stops[i]))
                    {
                        var neighbor = current.FindEdge(stops[i]);
                        sum += neighbor.Weight;
                    }
                    else
                    {
                        var resultFalse = new TripResult(false, null);
                        return(resultFalse);
                    }
                }

                if (current.Value == stops[length - 1])
                {
                    var resultTrue = new TripResult(true, sum);
                    return(resultTrue);
                }
                i++;
            }

            var result = new TripResult(false, null);

            return(result);
        }
Example #9
0
        public void Depth_First_Test()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");
            var diana = testGraph.AddVertex("Diana");
            var bill  = testGraph.AddVertex("Bill");

            testGraph.AddEdge(bob, carol, 13);
            testGraph.AddEdge(bob, diana, 9);
            testGraph.AddEdge(diana, bill, 23);
            Vertex <string>[] expected = new Vertex <string>[] { bob, diana, bill, carol };


            //act
            var actual = testGraph.DepthFirst();


            //Assert
            Assert.Equal(expected, actual);
        }
Example #10
0
        public void Breadth_First_Test_B()
        {
            //arrange
            myGraph <string> testGraph = new myGraph <string>();
            var bob   = testGraph.AddVertex("Bob");
            var carol = testGraph.AddVertex("Carol");
            var diana = testGraph.AddVertex("Diana");
            var bill  = testGraph.AddVertex("Bill");

            testGraph.AddEdge(bob, carol, 13);
            testGraph.AddEdge(bob, diana, 9);
            testGraph.AddEdge(diana, bill, 23);
            string expected = "Bob, Carol, Diana, Bill";


            //act
            var actual = testGraph.BreadthFirstHandler(bob);


            //Assert
            Assert.Equal(expected, actual);
        }