Example #1
0
        public void IndexedGraphTest()
        {
            IndexedGraph g   = new IndexedGraph();
            int          a   = g.AddNode();
            int          b   = g.AddNode();
            int          c   = g.AddNode();
            int          ab  = g.AddEdge(a, b);
            int          bb  = g.AddEdge(b, b); // self loop
            int          bc  = g.AddEdge(b, c);
            int          bc2 = g.AddEdge(b, c); // double edge

            Assert.Equal(c, g.TargetOf(bc));
            Assert.Equal(bb, g.GetEdge(b, b));
            Assert.Equal(0, g.EdgeCount(a, c));
            Assert.Equal(2, g.EdgeCount(b, c));
            Assert.Equal(4, g.EdgeCount());
            Assert.Equal(1, g.NeighborCount(a));
            Assert.Equal(2, g.NeighborCount(c));
            Assert.Equal(1, g.TargetCount(a));
            Assert.Equal(0, g.SourceCount(a));

            Console.Write("EdgesOf(b):");
            foreach (int edge in g.EdgesOf(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesInto(b):");
            foreach (int edge in g.EdgesInto(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesOutOf(b):");
            foreach (int edge in g.EdgesOutOf(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesLinking(b,c):");
            foreach (int edge in g.EdgesLinking(b, c))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
        }