Example #1
0
        public void TestGraph()
        {
            MyGraph ourGraph = new MyGraph();
            Knude   A        = new Knude();
            Knude   B        = new Knude();
            Knude   C        = new Knude();
            Knude   D        = new Knude();

            // add the four vertices to the graph
            ourGraph.Add_vertex(A);
            ourGraph.Add_vertex(B);
            ourGraph.Add_vertex(C);
            ourGraph.Add_vertex(D);

            // add the edges between the vertices
            ourGraph.Add_edge(A, B);
            ourGraph.Add_edge(B, C);
            ourGraph.Add_edge(B, D);

            // add the edge weights to the edges
            ourGraph.Set_edge_value(A, B, 5);
            ourGraph.Set_edge_value(B, C, 3);
            ourGraph.Set_edge_value(B, D, 1);

            // now do some checks
            Assert.IsTrue(ourGraph.Neighbors(D).Contains(B));
            Assert.AreEqual(ourGraph.Get_edge_value(A, B), ourGraph.Get_edge_value(B, A));
            Assert.IsTrue(ourGraph.Adjacent(C, B));
            Assert.IsTrue(ourGraph.Adjacent(A, B));
            ourGraph.Remove_vertex(B);
            Assert.IsFalse(ourGraph.Adjacent(A, B));
        }