------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class DIGRAPH_VIEWS_TEST is
   -- Testing various graph views
   include TEST;
   
   indi(s,d: INT): DIEDGE{INT} is return #DIEDGE{INT}(s,d) end;
   
   main is
      class_name("DIGRAPH_VIEWS");
      g2 ::= #DIGRAPH{INT};
      g2.add_node(1); g2.add_node(2); g2.add_node(3); g2.add_node(4);
      g2.add_node(5);
      g2.connect(1,2);  g2.connect(2,4);  g2.connect(2,5); g2.connect(1,3);
      --    1
      --    /\
      --   2   3
      -- /  \ 
      --4    5
      
      -- Testing node view
      views:STD_DIGRAPH_VIEWS{INT};
      g2nv ::= views.node_view(g2);
      test("num nodes",g2nv.size,5);
      test("nodes:"+g2nv.str,
	   g2nv.equals(#SET{INT}(#ARRAY{INT}(|1,2,3,4,5|))),true);
      
      -- Testing edge view
      g2ev ::= views.edge_view(g2);
      test("num edges",g2ev.size,4);
      es ::= SET{DIEDGE{INT}}::create(|indi(1,2),indi(1,3),indi(2,4),indi(2,5)|);
      test("edges:"+g2ev.str,g2ev.equals(es),true);

      -- Testing reverse digraph view
      g2rev::= views.reverse_edge_view(g2);
      #OUT+"Reversed graph:"+g2rev.str+"\n";
      g2revev ::= views.edge_view(g2rev);
      reves ::= SET{DIEDGE{INT}}::create(|indi(2,1),indi(3,1),indi(4,2),indi(5,2)|);
      test("reveedges:"+g2revev.str,reves.equals(g2revev),true);
      rev_nodes ::= #SET{INT}(#ARRAY{INT}(|1,2,3,4,5|));
      g2revnv ::= views.node_view(g2rev);
      test("revnodes:"+g2revnv.str,rev_nodes.equals(g2revnv),true);
      
      -- Filter graph view
      g ::= #DIGRAPH{INT};
      g.add_node(1);g.add_node(2);g.add_node(3);g.add_node(4);
      g.add_node(5);g.add_node(0);g.connect(3,0);
      g.connect(1,2).connect(2,4).connect(2,5).connect(1,3);
      --    1
      --    /\
      --   2   3
      -- /  \   \
      --4    5   0

      finish;
   end;
	 
   my_edge_filter(e: DIEDGE{INT}): BOOL is
      -- A filter that only returns edges starting at 1 or 2
      return e.first <= 2;
   end;	 
end; 
-------------------------------------------------------------------

