ó
`™xTc           @   sú   d  d l  m Z d  d l m Z d  d l Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d	 „  ƒ  YZ e j	 ƒ  j
 e ƒ Z e j	 ƒ  j
 e ƒ Z e j	 ƒ  j
 e ƒ Z e j e e e g ƒ Z e d
 k rö e j d d ƒ j e ƒ n  d S(   iÿÿÿÿ(   t   division(   t   undirected_graphNt	   TestGraphc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s5  t  j d d d d ƒ t  j d d d d ƒ t  j d d d d ƒ t  j d d d d ƒ g |  _ d d d g |  _ t d d d d d d g ƒ |  _ i t |  j d	 g ƒ d 6t |  j d	 |  j d |  j d g ƒ d 6t |  j d |  j d g ƒ d 6t |  j d |  j d g ƒ d 6t ƒ  d 6t ƒ  d 6|  _ d  S(
   Nt   vertex1i   t   vertex2i   i   i   i   i   i    (   R   t   Edget   edgest   add_verticest   sett   verticest
   edges_from(   t   self(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   setUp	   s    !+!!
c         C   s  |  j  t | j ƒ t ƒ  ƒ |  j  t | j ƒ t ƒ  ƒ x! |  j D] } | j d | ƒ qB Wx! |  j D] } | j d | ƒ qf W|  j  t | j ƒ t |  j ƒ ƒ |  j  t | j ƒ |  j ƒ x? |  j j ƒ  D]. \ } } |  j  t | j d | ƒ ƒ | ƒ qÎ Wd  S(   Nt   edget   vertex(   t   assertEqualR   R	   R   t   add_edget
   add_vertexR
   t   items(   R   t   grapht   et   vR   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   build_and_test_graph   s    "c         C   s   |  j  d t j ƒ  ƒ d  S(   NR   (   R   R   t   Graph(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt
   test_graph1   s    c         C   s   |  j  d t j ƒ  ƒ d  S(   NR   (   R   R   t   VertexIndexedGraph(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   test_vertex_indexed_graph6   s    (   t   __name__t
   __module__R   R   R   R   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR      s   			t   TestPreorderDepthFirstIterationc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s1   t  j ƒ  } x | D] } | j d | ƒ q W| S(   NR   (   R   R   R   (   R   R   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   create_graph_from_edges=   s    c         C   sV   |  j  d t j d d d d ƒ g ƒ } |  j t t j d d d | ƒ ƒ d g ƒ d  S(   NR   R   i   R   R   R   (   R   R   R   R   t   listt   preorder_depth_first_iteration(   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   test_1G   s
    	c         C   s‡   |  j  d t j d d d d ƒ g ƒ } |  j t t j d d d | ƒ ƒ d d g ƒ |  j t t j d d d | ƒ ƒ d d g ƒ d  S(   NR   R   i   R   i   R   R   (   R   R   R   R   R   R    (   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   test_2T   s    	c         C   sñ   |  j  d t j d d d d ƒ t j d d d d ƒ g ƒ } |  j t t j d d d | ƒ ƒ d d d g ƒ |  j t t j d d d | ƒ ƒ d d d g ƒ t t j d d d | ƒ ƒ } |  j | d d d g k pé | d d d g k ƒ d  S(	   NR   R   i   R   i   i   R   R   (   R   R   R   R   R   R    t
   assertTrue(   R   R   t   middle(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   test_3e   s    	c      
   C   s  |  j  d t j d d d d ƒ t j d d d d ƒ t j d d d d ƒ t j d d d d ƒ g ƒ } t t j d d d	 | ƒ ƒ } |  j | d d d d g k p· | d d d d g k ƒ t t j d d d	 | ƒ ƒ } |  j | d d d d g k p<| d d d d g k p<| d d d d g k p<| d d d d g k ƒ t t j d d d	 | ƒ ƒ } |  j | d d d d g k p©| d d d d g k p©| d d d d g k ƒ t t j d d d	 | ƒ ƒ } |  j | d d d d g k p| d d d d g k p| d d d d g k ƒ d  S(
   NR   R   i   R   i   i   i   R   R   (   R   R   R   R   R    R#   (   R   R   t   res(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   test_4{   s6    	7(   R   R   R   R!   R"   R%   R'   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR   ;   s
   	
			t   TestConnectedComponentsc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sZ   t  j ƒ  } | j d t  j d d d d ƒ ƒ |  j t t  j d | ƒ ƒ d g g ƒ d  S(   NR   R   i   R   R   (   R   R   R   R   R   R   t   connected_components(   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR!   ©   s
    "c         C   s»   t  j ƒ  } | j d t  j d d d d ƒ ƒ |  j t d „  t  j d | ƒ Dƒ ƒ d d g g ƒ t  j ƒ  } | j d ƒ | j d ƒ |  j t t  j d | ƒ ƒ d g d g g ƒ d  S(   NR   R   i   R   i   c         s   s   |  ] } t  | ƒ Vq d  S(   N(   t   sorted(   t   .0t   c(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pys	   <genexpr>º   s    R   (	   R   R   R   R   R   R   R)   R   R*   (   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR"   ³   s    "c         C   s  t  j ƒ  } | j t  j d d d d ƒ ƒ | j t  j d d d d ƒ ƒ | j t  j d d d d ƒ ƒ | j t  j d d d d ƒ ƒ | j t  j d d d d	 ƒ ƒ | j t  j d d d d	 ƒ ƒ |  j t d
 „  t  j d | ƒ Dƒ ƒ d d d g d d d d	 g g ƒ d  S(   NR   i   R   i   i   i   i   i   i   c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R*   (   R+   R,   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pys	   <genexpr>Ó   s    R   (   R   R   R   R   R   R*   R)   (   R   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR%   È   s    (   R   R   R!   R"   R%   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyR(   §   s   	
	t   __main__t	   verbosityi   (   t
   __future__R    t   scitbx.mathR   t   unittestt   TestCaseR   R   R(   t
   TestLoadert   loadTestsFromTestCaset   suite_grapht   suite_preorder_depth_firstt   suite_connected_componentst	   TestSuitet   alltestsR   t   TextTestRunnert   run(    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_undirected_graph.pyt   <module>   s"   4l1			