
    wg?                         d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZmZ d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#y)z@Unit tests for the :mod:`networkx.algorithms.tournament` module.    )combinationsN)DiGraph)hamiltonian_pathindex_satisfyingis_reachableis_strongly_connectedis_tournamentrandom_tournamentscore_sequencetournament_matrixc                  2    d } dg}t        ||       dk(  sJ y )Nc                     | dkD  S Nr    xs    n/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>z.test_condition_not_satisfied.<locals>.<lambda>   
    !a%     r      )r   )	conditioniter_ins     r   test_condition_not_satisfiedr      s#    IcGGY/1444r   c                  ~    d } t        j                  t              5  t        g |        d d d        y # 1 sw Y   y xY w)Nc                     | dkD  S r   r   r   s    r   r   z%test_empty_iterable.<locals>.<lambda>   r   r   )pytestraises
ValueErrorr   )r   s    r   test_empty_iterabler       s2    I	z	" (Y'( ( (s   3<c                  X    t               } | j                  g d       t        |       sJ y )Nr   r   r      r%      r'   r   r   r'   r   r%   r   add_edges_fromr	   Gs    r   test_is_tournamentr/       s&    	AEFr   c                  |    t               } | j                  g d       | j                  dd       t        |       rJ y)z%A tournament must have no self-loops.r"   r   Nr   r,   add_edger	   r-   s    r   test_self_loopsr3   &   s7    	AEFJJq!Qr   c                  X    t               } | j                  g d       t        |       rJ y)zbA tournament must not have any pair of nodes without at least
    one edge joining the pair.

    )r#   r$   r&   r(   r)   Nr+   r-   s    r   test_missing_edgesr5   .   s+    
 		A=>Qr   c                  |    t               } | j                  g d       | j                  dd       t        |       rJ y)zcA tournament must not have any pair of nodes with greater
    than one edge joining the pair.

    r"   r   r   Nr1   r-   s    r   test_bidirectional_edgesr7   8   s9    
 		AEFJJq!Qr   c                  T    t        d      D ]  } t        d      }t        |      rJ  y )N
      ranger
   r	   _r.   s     r   test_graph_is_tournamentr?   C   s-    2Y  a Q r   c                  X    t        d      D ]  } t        dd      }t        |      rJ  y )Nr9   r:   r   )seedr;   r=   s     r   test_graph_is_tournament_seedrB   I   s/    2Y  aa(Q r   c                  4    t        d      } t        |       sJ y )Nr   r
   r	   r-   s    r   !test_graph_is_tournament_one_noderE   O       !Ar   c                  4    t        d      } t        |       sJ y r   rD   r-   s    r   "test_graph_is_tournament_zero_noderH   T   rF   r   c                  J    t        t                     } t        |       dk(  sJ y r   )r   r   len)paths    r   test_hamiltonian_empty_graphrL   Y   s    GI&Dt9>>r   c            	          t               j                  g d       t              } t        |       dk(  sJ t	        fdt        | | dd        D              sJ y )Nr"      c              3   2   K   | ]  \  }}||   v   y wNr   .0uvr.   s      r   	<genexpr>z+test_path_is_hamiltonian.<locals>.<genexpr>c        9TQqAaDy9   r   r   r,   r   rJ   allziprK   r.   s    @r   test_path_is_hamiltonianr\   ^   sT    	AEFADt9>>9StABx%89999r   c            	          t               j                  g d       t              } t        |       dk(  sJ t	        fdt        | | dd       D              sJ | d   | d      v sJ y)zTests that :func:`networkx.tournament.hamiltonian_path`
    returns a Hamiltonian cycle when provided a strongly connected
    tournament.

    r"   rN   c              3   2   K   | ]  \  }}||   v   y wrP   r   rQ   s      r   rU   z)test_hamiltonian_cycle.<locals>.<genexpr>p   rV   rW   r   Nr   rX   r[   s    @r   test_hamiltonian_cycler`   f   sp     		AEFADt9>>9StABx%899997aRk!!!r   c                  @    t        dg      } t        |       ddgk(  sJ y )Nr#   r   r   r   r   r-   s    r   test_score_sequence_edgerc   t   s%    A!A&&&r   c                  B    t        g d      } t        |       g dk(  sJ y )Nr#   r$   )r%   r   )r   r   r   rb   r-   s    r   test_score_sequence_trianglerf   y   s     ()A!	)))r   c                     t        j                  d      } t        j                  d       | j                  }t        dg      }t	        |      }|j                  |j                         | j                  ddgddgg             y )Nnumpyscipyr#   r   r   r_   )r   importorskiptestingr   r   assert_array_equaltodensearray)npnptr.   ms       r   test_tournament_matrixrr   ~   sk    			W	%B
 
**CA!A199;1a&2q'1B(CDr   c                  <    t        g d      } t        | dd      sJ y)z$Tests for a reachable pair of nodes.re   r   r%   Nr   r   r-   s    r   test_reachable_pairru      s    ()A1a   r   c                  |     t        d t        t        d      d      D               t         fd D              sJ y)z.Tests that a node is always reachable from it.c              3   2   K   | ]  }t        |        y wrP   )sorted)rR   ps     r   rU   z.test_same_node_is_reachable.<locals>.<genexpr>   s     >aq	>s   r9   r%   c              3   8   K   | ]  }t        ||        y wrP   )r   )rR   rT   r.   s     r   rU   z.test_same_node_is_reachable.<locals>.<genexpr>   s     0|Aq!$0s   N)r   r   r<   rY   r-   s   @r   test_same_node_is_reachabler{      s4     	><b	1#=>>A0a0000r   c                  <    t        g d      } t        | dd      rJ y)z'Tests for an unreachable pair of nodes.r#   r*   r$   r   r   Nrt   r-   s    r   test_unreachable_pairr~      s"    ()AAq!$$$$r   c                  8    t        g d      } t        |       sJ y)z*Tests for a strongly connected tournament.re   Nr   r   r-   s    r   test_is_strongly_connectedr      s    ()A ###r   c                  8    t        g d      } t        |       rJ y)z6Tests for a tournament that is not strongly connected.r}   Nr   r-   s    r   test_not_strongly_connectedr      s    ()A$Q''''r   )$__doc__	itertoolsr   r   networkxr   networkx.algorithms.tournamentr   r   r   r   r	   r
   r   r   r   r    r/   r3   r5   r7   r?   rB   rE   rH   rL   r\   r`   rc   rf   rr   ru   r{   r~   r   r   r   r   r   <module>r      s    F "  	 	 	5(     


:"'
*
E!1%$(r   