o
    ˷e>                     @   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   `/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>       z.test_condition_not_satisfied.<locals>.<lambda>r      )r   )	condition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>)pytest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&   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_edges7   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_tournamentB   s   r5   c                  C   s*   t dD ]} tddd}t|sJ qd S )Nr/   r0   r   )seedr1   r3   r   r   r   test_graph_is_tournament_seedH   s   r7   c                  C      t d} t| s
J d S )Nr   r	   r   r'   r   r   r   !test_graph_is_tournament_one_nodeN      r:   c                  C   r8   r   r9   r'   r   r   r   "test_graph_is_tournament_zero_nodeS   r;   r<   c                  C   s   t t } t| dksJ d S r   )r   r   lenpathr   r   r   test_hamiltonian_empty_graphX   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>b       z+test_path_is_hamiltonian.<locals>.<genexpr>r   r   r&   r   r=   allzipr>   r   r'   r   test_path_is_hamiltonian]   s
   ,rM   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   rA   c                 3   rB   rC   r   rD   r'   r   r   rH   o   rI   z)test_hamiltonian_cycle.<locals>.<genexpr>r   Nr   rJ   r>   r   r'   r   test_hamiltonian_cyclee   s   (rO   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_edges   s   
rQ   c                  C   s$   t g d} t| g dksJ d S )Nr   r   )r   r   )r   r   r   rP   r'   r   r   r   test_score_sequence_trianglex   s   rS   c                  C   sR   t d} t d | j}tdg}t|}|| | ddgddgg d S )Nnumpyscipyr   r   r   rN   )r   importorskiptestingr   r   assert_array_equaltodensearray)npnptr(   mr   r   r   test_tournament_matrix}   s   


&r^   c                  C   s    t g d} t| ddsJ dS )z$Tests for a reachable pair of nodes.rR   r   r   Nr   r   r'   r   r   r   test_reachable_pair      r`   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 rC   )sorted)rE   pr   r   r   rH      s    z.test_same_node_is_reachable.<locals>.<genexpr>r/   r   c                 3   s    | ]	}t  ||V  qd S rC   )r   )rE   rG   r'   r   r   rH      s    N)r   r   r2   rK   r   r   r'   r   test_same_node_is_reachable   s   rd   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   Nr_   r'   r   r   r   test_unreachable_pair   ra   rf   c                  C   s   t g d} t| sJ dS )z*Tests for a strongly connected tournament.rR   Nr   r   r'   r   r   r   test_is_strongly_connected      rh   c                  C   s   t g d} t| rJ dS )z6Tests for a tournament that is not strongly connected.re   Nrg   r'   r   r   r   test_not_strongly_connected   ri   rj   )$__doc__	itertoolsr   r   networkxr   networkx.algorithms.tournamentr   r   r   r   r   r	   r
   r   r   r   r)   r,   r-   r.   r5   r7   r:   r<   r@   rM   rO   rQ   rS   r^   r`   rd   rf   rh   rj   r   r   r   r   <module>   s4    (
	