U
    ?h>                     @   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 td S )Nc                 S   s   | dkS Nr    xr   r   [/var/www/html/venv/lib/python3.8/site-packages/networkx/algorithms/tests/test_tournament.py<lambda>       z.test_condition_not_satisfied.<locals>.<lambda>r      )r   AssertionError)	conditionZiter_inr   r   r   test_condition_not_satisfied   s    r   c               	   C   s,   dd } t t tg |  W 5 Q R X d S )Nc                 S   s   | dkS 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  } | ddddddg t| s(td S )Nr   r   r      r      r   r   r   r   r   r   r   add_edges_fromr   r   Gr   r   r   test_is_tournament   s    r&   c                  C   s8   t  } | ddddddg | dd t| r4tdS )	z%A tournament must have no self-loops.r   r   r   r   r    r!   r   Nr   r#   Zadd_edger   r   r$   r   r   r   test_self_loops%   s    r(   c                  C   s*   t  } | dddddg t| r&t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   s8   t  } | ddddddg | dd t| r4td	S )
zcA tournament must not have any pair of nodes with greater
    than one edge joining the pair.

    r   r   r   r   r    r!   r   r   Nr'   r$   r   r   r   test_bidirectional_edges7   s    r*   c                  C   s&   t dD ]} td}t|stqd S )N
      ranger	   r   r   _r%   r   r   r   test_graph_is_tournamentB   s    r1   c                  C   s*   t dD ]} tddd}t|stqd S )Nr+   r,   r   )seedr-   r/   r   r   r   test_graph_is_tournament_seedH   s    r3   c                  C   s   t d} t| std S )Nr   r	   r   r   r$   r   r   r   !test_graph_is_tournament_one_nodeN   s    r5   c                  C   s   t d} t| std S r   r4   r$   r   r   r   "test_graph_is_tournament_zero_nodeS   s    r6   c                  C   s   t t } t| dkstd S r   )r   r   lenr   pathr   r   r   test_hamiltonian_empty_graphX   s    
r:   c                     s`   t    ddddddg t } t| dks4tt fdd	t| | d
d  D s\td S )Nr   r   r   r   r    r!      c                 3   s   | ]\}}| | kV  qd S Nr   .0uvr$   r   r   	<genexpr>b   s     z+test_path_is_hamiltonian.<locals>.<genexpr>r   r   r#   r   r7   r   allzipr8   r   r$   r   test_path_is_hamiltonian]   s
    rE   c                     sx   t    ddddddg t } t| dks4tt fdd	t| | d
d D s\t| d  | d  ksttdS )zTests that :func:`networkx.tournament.hamiltonian_path`
    returns a Hamiltonian cycle when provided a strongly connected
    tournament.

    r   r   r   r   r    r!   r;   c                 3   s   | ]\}}| | kV  qd S r<   r   r=   r$   r   r   rA   o   s     z)test_hamiltonian_cycle.<locals>.<genexpr>r   Nr   rB   r8   r   r$   r   test_hamiltonian_cyclee   s    (rG   c                  C   s"   t dg} t| ddgkstd S )Nr   r   r   r   r
   r   r$   r   r   r   test_score_sequence_edges   s    
rI   c                  C   s(   t dddg} t| dddgks$td S )Nr   r   r   r   r   rH   r$   r   r   r   test_score_sequence_trianglex   s    rK   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   rF   )r   ZimportorskipZtestingr   r   Zassert_array_equalZtodensearray)npZnptr%   mr   r   r   test_tournament_matrix}   s    


rP   c                  C   s"   t dddg} t| ddstdS )z$Tests for a reachable pair of nodes.r   r   rJ   r   r   Nr   r   r   r$   r   r   r   test_reachable_pair   s    rR   c                      s:   t dd ttddD  t fdd D s6tdS )z.Tests that a node is always reachable from it.c                 s   s   | ]}t |V  qd S r<   )sorted)r>   pr   r   r   rA      s     z.test_same_node_is_reachable.<locals>.<genexpr>r+   r   c                 3   s   | ]}t  ||V  qd S r<   )r   )r>   r@   r$   r   r   rA      s     N)r   r   r.   rC   r   r   r   r$   r   test_same_node_is_reachable   s    rU   c                  C   s"   t dddg} t| ddrtdS )z'Tests for an unreachable pair of nodes.r   r!   r   r   r   NrQ   r$   r   r   r   test_unreachable_pair   s    rV   c                  C   s   t dddg} t| stdS )z*Tests for a strongly connected tournament.r   r   rJ   Nr   r   r   r$   r   r   r   test_is_strongly_connected   s    rX   c                  C   s   t dddg} t| rtdS )z6Tests for a tournament that is not strongly connected.r   r!   r   NrW   r$   r   r   r   test_not_strongly_connected   s    rY   )$__doc__	itertoolsr   r   Znetworkxr   Znetworkx.algorithms.tournamentr   r   r   r   r   r	   r
   r   r   r   r&   r(   r)   r*   r1   r3   r5   r6   r:   rE   rG   rI   rK   rP   rR   rU   rV   rX   rY   r   r   r   r   <module>   s2   (
	