public void CanReturnNullListWithNoNeighborNodes()
        {
            Node   nodeOne = new Node("nodeOne");
            Graphs myGraph = new Graphs(nodeOne);

            Assert.Empty(myGraph.GetNeighbors(nodeOne));
        }
        public void RetreiveAllNodeNeighbors()
        {
            ///Test that all node neighbors can be retreived
            Graphs graph  = new Graphs();
            Node   testV1 = new Node("Test1");
            Node   testV2 = new Node("Test2");
            Node   testV3 = new Node("Test3");

            graph.AddNode(testV1);
            graph.AddNode(testV2);
            graph.AddEdge(testV1, testV2, 4);
            graph.AddEdge(testV2, testV3, 8);
            Edge        testEdge  = new Edge(testV1, testV2, 4);
            Edge        testEdge2 = new Edge(testV2, testV3, 8);
            List <Node> expected  = new List <Node>();

            expected.Add(testEdge.V1);
            expected.Add(testEdge2.V1);
            List <Edge> graphEdges = graph.GetNeighbors(testV2);
            List <Node> actual     = new List <Node>();

            foreach (Edge e in graphEdges)
            {
                actual.Add(e.V1);
            }

            Assert.Equal(expected, actual);
        }
        public void AddEdgeToGraph()
        {
            ///Test that edge can be successfully added
            Graphs graph  = new Graphs();
            Node   testV1 = new Node("Test1");
            Node   testV2 = new Node("Test2");

            graph.AddNode(testV1);
            graph.AddNode(testV2);
            graph.AddEdge(testV1, testV2, 4);
            Edge        testEdge = new Edge(testV1, testV2, 4);
            List <Node> expected = new List <Node>();

            expected.Add(testEdge.V1);
            List <Edge> graphEdges = graph.GetNeighbors(testV2);
            List <Node> actual     = new List <Node>();

            foreach (Edge e in graphEdges)
            {
                actual.Add(e.V1);
            }


            Assert.Equal(expected, actual);
        }
        public void CanReturnListOfNeighborNodesWithZeroWeight()
        {
            Node   nodeOne   = new Node("nodeOne");
            Node   nodeTwo   = new Node("nodeTwo");
            Node   nodeThree = new Node("nodeThree");
            Node   nodeFour  = new Node("nodeFour");
            Node   nodeFive  = new Node("nodeFive");
            Graphs myGraph   = new Graphs(nodeOne);

            myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeTwo, 0));
            myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeThree, 0));
            myGraph.AddEdge(nodeThree, new Tuple <Node, int>(nodeFour, 0));
            myGraph.AddEdge(nodeFour, new Tuple <Node, int>(nodeFive, 0));
            myGraph.AddEdge(nodeFive, new Tuple <Node, int>(nodeOne, 0));

            Assert.NotEmpty(myGraph.GetNeighbors(nodeOne));
        }
        public void CanGetMultipleNeighborsFromGraph()
        {
            Node   nodeOne   = new Node("nodeOne");
            Node   nodeTwo   = new Node("nodeTwo");
            Node   nodeThree = new Node("nodeThree");
            Node   nodeFour  = new Node("nodeFour");
            Node   nodeFive  = new Node("nodeFive");
            Graphs myGraph   = new Graphs(nodeOne);

            myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeTwo, 5));
            myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeThree, 10));
            myGraph.AddEdge(nodeThree, new Tuple <Node, int>(nodeFour, 15));
            myGraph.AddEdge(nodeFour, new Tuple <Node, int>(nodeFive, 20));
            myGraph.AddEdge(nodeFive, new Tuple <Node, int>(nodeOne, 25));
            myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeThree, 742));

            Assert.Equal(3, myGraph.GetNeighbors(nodeOne).Count);
        }
        public void RetreiveSingleNodeandEdge()
        {
            ///Test that a single vertex and edge can be found
            Graphs graph  = new Graphs();
            Node   testV1 = new Node("Test1");

            graph.AddNode(testV1);
            graph.AddEdge(testV1, testV1, 4);
            Edge        testEdge = new Edge(testV1, testV1, 4);
            List <Node> expected = new List <Node>();

            expected.Add(testEdge.V1);
            List <Edge> graphEdges = graph.GetNeighbors(testV1);
            List <Node> actual     = new List <Node>();

            foreach (Edge e in graphEdges)
            {
                actual.Add(e.V1);
            }
            Assert.Equal(expected, actual);
        }
        public void RetreiveWeightNeighbors()
        {
            ///Test that all weight can be retrieved from neighbors
            Graphs graph  = new Graphs();
            Node   testV1 = new Node("Test1");
            Node   testV2 = new Node("Test2");

            graph.AddNode(testV1);
            graph.AddNode(testV2);
            graph.AddEdge(testV1, testV2, 4);
            Edge        testEdge   = new Edge(testV1, testV2, 4);
            List <Edge> graphEdges = graph.GetNeighbors(testV2);
            int         weight     = 0;

            foreach (Edge e in graphEdges)
            {
                weight = e.Weight;
            }

            Assert.Equal(testEdge.Weight, weight);
        }
        /// <summary>
        /// Gets the edges.
        /// </summary>
        /// <param name="trip">The trip.</param>
        /// <param name="flights">The flights.</param>
        /// <returns>Returns a string</returns>
        public static string GetEdges(Node[] trip, Graphs flights)
        {
            int  cost  = 0;
            bool check = false;

            for (int i = 0; i < trip.Length - 1; i++)
            {
                if (flights.GetNeighbors(trip[i]).Contains(trip[i + 1]))
                {
                    check = true;
                    var item = flights.AdjacencyList.GetValueOrDefault(trip[i]);
                    foreach (var value in item)
                    {
                        if (value.Item1 == trip[i + 1])
                        {
                            cost += value.Item2;
                        }
                    }
                }
            }
            return($"{check} ${cost}");
        }