
    sh                         S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJrJrJr  S rS rS rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#g)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                  0    S/n [        U S 5      S:X  d   eg )Nr   c                     U S:  $ Nr    xs    }/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>.test_condition_not_satisfied.<locals>.<lambda>   s    q1u       )r   )iter_ins    r   test_condition_not_satisfiedr      s    cGG_5:::r   c                      [         R                  " [        5         [        / S 5        S S S 5        g ! , (       d  f       g = f)Nc                     U S:  $ r   r   r   s    r   r   %test_empty_iterable.<locals>.<lambda>   s    q1ur   )pytestraises
ValueErrorr   r   r   r   test_empty_iterabler       s$    	z	"_- 
#	"	"s	   2
A c                  b    [        5       n U R                  / SQ5        [        U 5      (       d   eg )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                      [        5       n U R                  / SQ5        U R                  SS5        [        U 5      (       a   eg)z%A tournament must have no self-loops.r"   r   Nr   r,   add_edger	   r-   s    r   test_self_loopsr3   $   s:    	AEFJJq!Qr   c                  b    [        5       n U R                  / SQ5        [        U 5      (       a   eg)zZA 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                      [        5       n U R                  / SQ5        U R                  SS5        [        U 5      (       a   eg)z[A 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   6   s<    
 		AEFJJq!Qr   c                  b    [        S5       H   n [        S5      n[        U5      (       a  M    e   g )N
      ranger
   r	   _r.   s     r   test_graph_is_tournamentr?   A   s+    2Ya Q r   c                  `    [        S5       H  n [        SSS9n[        U5      (       a  M   e   g )Nr9   r:   r   )seedr;   r=   s     r   test_graph_is_tournament_seedrB   G   s-    2Yaa(Q r   c                  >    [        S5      n [        U 5      (       d   eg )Nr   r
   r	   r-   s    r   !test_graph_is_tournament_one_noderE   M       !Ar   c                  >    [        S5      n [        U 5      (       d   eg r   rD   r-   s    r   "test_graph_is_tournament_zero_noderH   R   rF   r   c                  L    [        [        5       5      n [        U 5      S:X  d   eg r   )r   r   len)paths    r   test_hamiltonian_empty_graphrL   W   s    GI&Dt9>>r   c            	         ^ [        5       mTR                  / SQ5        [        T5      n [        U 5      S:X  d   e[	        U4S j[        X SS  5       5       5      (       d   eg )Nr"      c              3   8   >#    U  H  u  pUTU   ;   v   M     g 7fNr   .0uvr.   s      r   	<genexpr>+test_path_is_hamiltonian.<locals>.<genexpr>a        9%8TQqAaDy%8   r   r   r,   r   rJ   allziprK   r.   s    @r   test_path_is_hamiltonianr]   \   sU    	AEFADt9>>9SABx%899999r   c            	         ^ [        5       mTR                  / SQ5        [        T5      n [        U 5      S:X  d   e[	        U4S j[        X SS 5       5       5      (       d   eU S   TU S      ;   d   eg)zTests that :func:`networkx.tournament.hamiltonian_path`
returns a Hamiltonian cycle when provided a strongly connected
tournament.

r"   rN   c              3   8   >#    U  H  u  pUTU   ;   v   M     g 7frP   r   rQ   s      r   rU   )test_hamiltonian_cycle.<locals>.<genexpr>n   rW   rX   r   Nr   rY   r\   s    @r   test_hamiltonian_cyclerb   d   sq     		AEFADt9>>9SABx%8999997aRk!!!r   c                  B    [        S/5      n [        U 5      SS/:X  d   eg )Nr#   r   r   r   r   r-   s    r   test_score_sequence_edgere   r   s%    A!A&&&r   c                  D    [        / SQ5      n [        U 5      / SQ:X  d   eg )Nr#   r$   )r%   r   )r   r   r   rd   r-   s    r   test_score_sequence_trianglerh   w   s     ()A!	)))r   c                     [         R                  " S5      n [         R                  " S5        U R                  n[        S/5      n[	        U5      nUR                  UR                  5       U R                  SS/SS//5      5        g )Nnumpyscipyr#   r   r   ra   )r   importorskiptestingr   r   assert_array_equaltodensearray)npnptr.   ms       r   test_tournament_matrixrt   |   sk    			W	%B
 
**CA!A199;1a&2q'1B(CDr   c                  F    [        / SQ5      n [        U SS5      (       d   eg)z$Tests for a reachable pair of nodes.rg   r   r%   Nr   r   r-   s    r   test_reachable_pairrw      s"    ()A1a    r   c                     ^  [        S [        [        S5      S5       5       5      m [        U 4S jT  5       5      (       d   eg)z.Tests that a node is always reachable from it.c              3   8   #    U  H  n[        U5      v   M     g 7frP   )sorted)rR   ps     r   rU   .test_same_node_is_reachable.<locals>.<genexpr>   s     >#=aq		#=s   r9   r%   c              3   <   >#    U  H  n[        TX5      v   M     g 7frP   )r   )rR   rT   r.   s     r   rU   r|      s     0a|Aq$$as   N)r   r   r<   rZ   r-   s   @r   test_same_node_is_reachabler~      s7     	><b	1#=>>A0a00000r   c                  F    [        / SQ5      n [        U SS5      (       a   eg)z'Tests for an unreachable pair of nodes.r#   r*   r$   r   r   Nrv   r-   s    r   test_unreachable_pairr      s%    ()AAq!$$$$$r   c                  B    [        / SQ5      n [        U 5      (       d   eg)z*Tests for a strongly connected tournament.rg   Nr   r   r-   s    r   test_is_strongly_connectedr      s    ()A ####r   c                  B    [        / SQ5      n [        U 5      (       a   eg)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]   rb   re   rh   rt   rw   r~   r   r   r   r   r   r   <module>r      s    F "  	 	 	;
.
     


:"'
*
E!1%$(r   