
    Vh                         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                  .    dg} t        | d       dk(  sJ y )Nr   c                     | dkD  S Nr    xs    Y/home/dcms/DCMS/lib/python3.12/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>z.test_condition_not_satisfied.<locals>.<lambda>   s
    q1u        )r   )iter_ins    r   test_condition_not_satisfiedr      s    cGG_5:::r   c                  z    t        j                  t              5  t        g d        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>   s
    q1u r   )pytestraises
ValueErrorr   r   r   r   test_empty_iterabler      s-    	z	" ._-. . .s   1: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_loopsr1   $   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_edgesr3   ,   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   Nr/   r+   s    r   test_bidirectional_edgesr5   6   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=   A   s-    2Y  a Q r   c                  X    t        d      D ]  } t        dd      }t        |      rJ  y )Nr7   r8   r   )seedr9   r;   s     r   test_graph_is_tournament_seedr@   G   s/    2Y  aa(Q r   c                  4    t        d      } t        |       sJ y )Nr   r
   r	   r+   s    r   !test_graph_is_tournament_one_noderC   M       !Ar   c                  4    t        d      } t        |       sJ y r   rB   r+   s    r   "test_graph_is_tournament_zero_noderF   R   rD   r   c                  J    t        t                     } t        |       dk(  sJ y r   )r   r   len)paths    r   test_hamiltonian_empty_graphrJ   W   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>a        9TQqAaDy9   r   r   r*   r   rH   allziprI   r,   s    @r   test_path_is_hamiltonianrZ   \   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    rL   c              3   2   K   | ]  \  }}||   v   y wrN   r   rO   s      r   rS   z)test_hamiltonian_cycle.<locals>.<genexpr>n   rT   rU   r   Nr   rV   rY   s    @r   test_hamiltonian_cycler^   d   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_edgera   r   s%    A!A&&&r   c                  B    t        g d      } t        |       g dk(  sJ y )Nr!   r"   )r#   r   )r   r   r   r`   r+   s    r   test_score_sequence_trianglerd   w   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_matrixrp   |   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.rc   r   r#   Nr   r   r+   s    r   test_reachable_pairrs      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rN   )sorted)rP   ps     r   rS   z.test_same_node_is_reachable.<locals>.<genexpr>   s     >aq	>s   r7   r#   c              3   8   K   | ]  }t        ||        y wrN   )r   )rP   rR   r,   s     r   rS   z.test_same_node_is_reachable.<locals>.<genexpr>   s     0|Aq!$0s   N)r   r   r:   rW   r+   s   @r   test_same_node_is_reachablery      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   Nrr   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.rc   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-   r1   r3   r5   r=   r@   rC   rF   rJ   rZ   r^   ra   rd   rp   rs   ry   r|   r   r   r   r   r   <module>r      s    F "  	 	 	;
.
     


:"'
*
E!1%$(r   