
    fi                         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#dS )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 d S )Nr   c                     | dk    S Nr    xs    /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/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5::::::r   c                      t          j        t                    5  t          g d            d d d            d S # 1 swxY w Y   d S )Nc                     | dk    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   9= =c                  r    t                      } |                     g d           t          |           sJ d S )Nr   r   r      r#      r%   r   r   r%   r   r#   r   add_edges_fromr	   Gs    r   test_is_tournamentr-      s@    		AEEEFFFr   c                      t                      } |                     g d           |                     dd           t          |           rJ dS )z%A tournament must have no self-loops.r    r   Nr   r*   add_edger	   r+   s    r   test_self_loopsr1   $   sT    		AEEEFFFJJq!Qr   c                  r    t                      } |                     g d           t          |           rJ dS )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   ,   sB    
 			A===>>>Qr   c                      t                      } |                     g d           |                     dd           t          |           rJ dS )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   sV    
 			AEEEFFFJJq!Qr   c                  j    t          d          D ]"} t          d          }t          |          sJ #d S )N
      ranger
   r	   _r,   s     r   test_graph_is_tournamentr=   A   sE    2YY    a  Q   r   c                  n    t          d          D ]$} t          dd          }t          |          sJ %d S )Nr7   r8   r   )seedr9   r;   s     r   test_graph_is_tournament_seedr@   G   sJ    2YY    aa(((Q   r   c                  F    t          d          } t          |           sJ d S )Nr   r
   r	   r+   s    r   !test_graph_is_tournament_one_noderC   M   )    !Ar   c                  F    t          d          } t          |           sJ d S r   rB   r+   s    r   "test_graph_is_tournament_zero_noderF   R   rD   r   c                  f    t          t                                } t          |           dk    sJ d S r   )r   r   len)paths    r   test_hamiltonian_empty_graphrJ   W   s*    GII&&Dt99>>>>>>r   c            	          t                                          g d           t                    } t          |           dk    sJ t	          fdt          | | dd                    D                       sJ d S )Nr       c              3   2   K   | ]\  }}||         v V  d S Nr   .0uvr,   s      r   	<genexpr>z+test_path_is_hamiltonian.<locals>.<genexpr>a   /      99TQqAaDy999999r   r   r   r*   r   rH   allziprI   r,   s    @r   test_path_is_hamiltonianrY   \   s    		AEEEFFFADt99>>>>9999StABBx%8%89999999999r   c            	      0   t                                          g d           t                    } t          |           dk    sJ t	          fdt          | | dd                   D                       sJ | d         | d                  v sJ dS )zTests that :func:`networkx.tournament.hamiltonian_path`
    returns a Hamiltonian cycle when provided a strongly connected
    tournament.

    r    rL   c              3   2   K   | ]\  }}||         v V  d S rN   r   rO   s      r   rS   z)test_hamiltonian_cycle.<locals>.<genexpr>n   rT   r   r   Nr   rU   rX   s    @r   test_hamiltonian_cycler]   d   s     			AEEEFFFADt99>>>>9999StABBx%8%8999999997aRk!!!!!!r   c                  T    t          dg          } t          |           ddgk    sJ d S )Nr!   r   r   r   r   r+   s    r   test_score_sequence_edger`   r   s4    A!A&&&&&&r   c                  V    t          g d          } t          |           g dk    sJ d S )Nr!   r"   )r#   r   )r   r   r   r_   r+   s    r   test_score_sequence_trianglerc   w   s9    ((())A!			))))))r   c                  $   t          j        d          } t          j        d           | j        }t          dg          }t	          |          }|                    |                                |                     ddgddgg                     d S )Nnumpyscipyr!   r   r   r\   )r   importorskiptestingr   r   assert_array_equaltodensearray)npnptr,   ms       r   test_tournament_matrixro   |   s    		W	%	%B
   
*CA!A199;;1a&2q'1B(C(CDDDDDr   c                  N    t          g d          } t          | dd          sJ dS )z$Tests for a reachable pair of nodes.rb   r   r#   Nr   r   r+   s    r   test_reachable_pairrr      s4    ((())A1a       r   c                       t          d t          t          d          d          D                        t           fd D                       sJ dS )z.Tests that a node is always reachable from it.c              3   4   K   | ]}t          |          V  d S rN   )sorted)rP   ps     r   rS   z.test_same_node_is_reachable.<locals>.<genexpr>   s(      >>aq		>>>>>>r   r7   r#   c              3   :   K   | ]}t          ||          V  d S rN   )r   )rP   rR   r,   s     r   rS   z.test_same_node_is_reachable.<locals>.<genexpr>   s/      00|Aq!$$000000r   N)r   r   r:   rV   r+   s   @r   test_same_node_is_reachablerx      s`     	>><b		1#=#=>>>>>A0000a0000000000r   c                  N    t          g d          } t          | dd          rJ dS )z'Tests for an unreachable pair of nodes.r!   r(   r"   r   r   Nrq   r+   s    r   test_unreachable_pairr{      s4    ((())AAq!$$$$$$$r   c                  J    t          g d          } t          |           sJ dS )z*Tests for a strongly connected tournament.rb   Nr   r   r+   s    r   test_is_strongly_connectedr~      s0    ((())A #######r   c                  J    t          g d          } t          |           rJ dS )z6Tests for a tournament that is not strongly connected.rz   Nr}   r+   s    r   test_not_strongly_connectedr      s0    ((())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   rY   r]   r`   rc   ro   rr   rx   r{   r~   r   r   r   r   <module>r      s   F F " " " " " "       	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	; ; ;
. . .
                             
  
  
: : :" " "' ' '
* * *
E E E! ! !1 1 1% % %$ $ $( ( ( ( (r   