src/test/java/org/jboss/test/util/test/graph/GraphTestCase.java
/** Breadth first search of digraph1
    * @throws Exception
    */
Breadth first search of digraph1
@throws Exception
Breadth first search of digraph1 @throws Exception
public void testBFS()
      throws Exception
   {
      Graph graph = buildGraph1();
      final ArrayList<Vertex> order = new ArrayList<Vertex>();
      Visitor visitor = new Visitor()
      {
         public void visit(Graph g, Vertex v)
         {
            System.out.println("visit "+v.getName());
            order.add(v);
         }
      };
      graph.breadthFirstSearch(a, visitor);
      assertTrue("Visted count == 8("+order.size()+")", order.size() == 8);
      for(int n = 0; n < order.size(); n ++)
      {
         Vertex v = order.get(n);
         System.out.println(v);
         assertTrue(v.getName()+" is visited", v.visited());
      }
      String[] names = {"A", "B", "F", "C", "G", "E", "I", "H"};
      for(int n = 0; n < order.size(); n ++)
      {
         Vertex v = order.get(n);
         assertTrue("#"+n+" is "+names[n]+"("+v.getName()+")",
            v.getName().equals(names[n]));
      }
   }
public void testBFS ( ) throws Exception { Graph graph = buildGraph1 ( ) ; final ArrayList < Vertex > order = new ArrayList < Vertex > ( ) ; Visitor visitor = new Visitor ( ) { public void visit ( Graph g , Vertex v ) { System . out . println ( "visit " + v . getName ( ) ) ; order . add ( v ) ; } } ; graph . breadthFirstSearch ( a , visitor ) ; assertTrue ( "Visted count == 8(" + order . size ( ) + ")" , order . size ( ) == 8 ) ; for ( int n = 0 ; n < order . size ( ) ; n ++ ) { Vertex v = order . get ( n ) ; System . out . println ( v ) ; assertTrue ( v . getName ( ) + " is visited" , v . visited ( ) ) ; } String [ ] names = { "A" , "B" , "F" , "C" , "G" , "E" , "I" , "H" } ; for ( int n = 0 ; n < order . size ( ) ; n ++ ) { Vertex v = order . get ( n ) ; assertTrue ( "#" + n + " is " + names [ n ] + "(" + v . getName ( ) + ")" , v . getName ( ) . equals ( names [ n ] ) ) ; } }
Breadth first search of digraph1
 @throws Exception
Breadth first search of digraph1 @throws Exception
// Validate the expected order and visited state