o
    ]Zh?                     @   s   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d Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Z d*d+ Z!d,d- Z"d.d/ Z#dS )0z@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                  C   s$   dd } dg}t || dksJ d S )Nc                 S      | dkS Nr    xr   r   X/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>       z.test_condition_not_satisfied.<locals>.<lambda>r      )r   )	conditionZiter_inr   r   r   test_condition_not_satisfied   s   r   c                  C   sB   dd } t t tg |  W d    d S 1 sw   Y  d S )Nc                 S   r   r   r   r   r   r   r   r      r   z%test_empty_iterable.<locals>.<lambda>)pytestZraises
ValueErrorr   )r   r   r   r   test_empty_iterable   s   "r   c                  C   s$   t  } | g d t| sJ d S )Nr   r   r      r      r   r   r   r   r   r   r   add_edges_fromr   Gr   r   r   test_is_tournament    s   r'   c                  C   s0   t  } | g d | dd t| rJ dS )z%A tournament must have no self-loops.r   r   Nr   r$   Zadd_edger   r%   r   r   r   test_self_loops&   s   r)   c                  C   s$   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%   r   r   r   test_missing_edges.   s   r*   c                  C   s0   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%   r   r   r   test_bidirectional_edges8   s   r+   c                  C   s&   t dD ]} td}t|sJ qd S )N
      ranger	   r   _r&   r   r   r   test_graph_is_tournamentC   s   r2   c                  C   s*   t dD ]} tddd}t|sJ qd S )Nr,   r-   r   )seedr.   r0   r   r   r   test_graph_is_tournament_seedI   s   r4   c                  C      t d} t| s
J d S )Nr   r	   r   r%   r   r   r   !test_graph_is_tournament_one_nodeO      r7   c                  C   r5   r   r6   r%   r   r   r   "test_graph_is_tournament_zero_nodeT   r8   r9   c                  C   s   t t } t| dksJ d S r   )r   r   lenpathr   r   r   test_hamiltonian_empty_graphY   s   
r=   c                     sX   t    g d t } t| dksJ t fddt| | dd  D s*J d S )Nr      c                 3        | ]\}}| | v V  qd S Nr   .0uvr%   r   r   	<genexpr>c       z+test_path_is_hamiltonian.<locals>.<genexpr>r   r   r$   r   r:   allzipr;   r   r%   r   test_path_is_hamiltonian^   s
   ,rJ   c                     sp   t    g d t } t| dksJ t fddt| | dd D s*J | d  | d  v s6J dS )	zTests that :func:`networkx.tournament.hamiltonian_path`
    returns a Hamiltonian cycle when provided a strongly connected
    tournament.

    r   r>   c                 3   r?   r@   r   rA   r%   r   r   rE   p   rF   z)test_hamiltonian_cycle.<locals>.<genexpr>r   Nr   rG   r;   r   r%   r   test_hamiltonian_cyclef   s   (rL   c                  C   s"   t dg} t| ddgksJ d S )Nr   r   r   r   r
   r%   r   r   r   test_score_sequence_edget   s   
rN   c                  C   s$   t g d} t| g dksJ d S )Nr   r   )r   r   )r   r   r   rM   r%   r   r   r   test_score_sequence_triangley   s   rP   c                  C   sR   t d} t d | j}tdg}t|}|| | ddgddgg d S )NnumpyZscipyr   r   r   rK   )r   Zimportorskiptestingr   r   Zassert_array_equalZtodensearray)npZnptr&   mr   r   r   test_tournament_matrix~   s   


&rV   c                  C   s    t g d} t| ddsJ dS )z$Tests for a reachable pair of nodes.rO   r   r   Nr   r   r%   r   r   r   test_reachable_pair      rX   c                      s:   t dd ttddD  t fdd D sJ dS )z.Tests that a node is always reachable from it.c                 s   s    | ]}t |V  qd S r@   )sorted)rB   pr   r   r   rE      s    z.test_same_node_is_reachable.<locals>.<genexpr>r,   r   c                 3   s    | ]	}t  ||V  qd S r@   )r   )rB   rD   r%   r   r   rE      s    N)r   r   r/   rH   r   r   r%   r   test_same_node_is_reachable   s   r\   c                  C   s    t g d} t| ddrJ dS )z'Tests for an unreachable pair of nodes.r   r"   r   r   r   NrW   r%   r   r   r   test_unreachable_pair   rY   r^   c                  C   s   t g d} t| sJ dS )z*Tests for a strongly connected tournament.rO   Nr   r   r%   r   r   r   test_is_strongly_connected      r`   c                  C   s   t g d} t| rJ dS )z6Tests for a tournament that is not strongly connected.r]   Nr_   r%   r   r   r   test_not_strongly_connected   ra   rb   )$__doc__	itertoolsr   r   Znetworkxr   Znetworkx.algorithms.tournamentr   r   r   r   r   r	   r
   r   r   r   r'   r)   r*   r+   r2   r4   r7   r9   r=   rJ   rL   rN   rP   rV   rX   r\   r^   r`   rb   r   r   r   r   <module>   s4    (
	