
    h?                         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                  2    S n S/n[        X5      S:X  d   eg )Nc                     U S:  $ Nr    xs    [/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>.test_condition_not_satisfied.<locals>.<lambda>       !a%    r      )r   )	conditioniter_ins     r   test_condition_not_satisfiedr      s!    IcGG/1444r   c                      S n [         R                  " [        5         [        / U 5        S S S 5        g ! , (       d  f       g = f)Nc                     U S:  $ r   r   r   s    r   r   %test_empty_iterable.<locals>.<lambda>   r   r   )pytestraises
ValueErrorr   )r   s    r   test_empty_iterabler"      s)    I	z	"Y' 
#	"	"s	   4
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_tournamentr1       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_loopsr5   &   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_edgesr7   .   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   Nr3   r/   s    r   test_bidirectional_edgesr9   8   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	   _r0   s     r   test_graph_is_tournamentrA   C   s+    2Ya Q r   c                  `    [        S5       H  n [        SSS9n[        U5      (       a  M   e   g )Nr;   r<   r   )seedr=   r?   s     r   test_graph_is_tournament_seedrD   I   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_noderG   O       !Ar   c                  >    [        S5      n [        U 5      (       d   eg r   rF   r/   s    r   "test_graph_is_tournament_zero_noderJ   T   rH   r   c                  L    [        [        5       5      n [        U 5      S:X  d   eg r   )r   r   len)paths    r   test_hamiltonian_empty_graphrN   Y   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vr0   s      r   	<genexpr>+test_path_is_hamiltonian.<locals>.<genexpr>c        9%8TQqAaDy%8   r   r   r.   r   rL   allziprM   r0   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$   rP   c              3   8   >#    U  H  u  pUTU   ;   v   M     g 7frR   r   rS   s      r   rW   )test_hamiltonian_cycle.<locals>.<genexpr>p   rY   rZ   r   Nr   r[   r^   s    @r   test_hamiltonian_cyclerd   f   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_edgerg   t   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   rf   r/   s    r   test_score_sequence_trianglerj   y   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   rc   )r   importorskiptestingr   r   assert_array_equaltodensearray)npnptr0   ms       r   test_tournament_matrixrv   ~   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.ri   r   r'   Nr   r   r/   s    r   test_reachable_pairry      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rR   )sorted)rT   ps     r   rW   .test_same_node_is_reachable.<locals>.<genexpr>   s     >#=aq		#=s   r;   r'   c              3   <   >#    U  H  n[        TX5      v   M     g 7frR   )r   )rT   rV   r0   s     r   rW   r~      s     0a|Aq$$as   N)r   r   r>   r\   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   Nrx   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.ri   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"   r1   r5   r7   r9   rA   rD   rG   rJ   rN   r_   rd   rg   rj   rv   ry   r   r   r   r   r   r   r   <module>r      s    F "  	 	 	5(     


:"'
*
E!1%$(r   