o
    3ήc                     @   sd   d Z ddlZddlmZmZmZmZ dd Zdd Z	G dd	 d	Z
G d
d dZdd Zdd ZdS )zJUnit tests for the :mod:`networkx.algorithms.approximation.clique` module.    N)clique_removallarge_clique_size
max_cliquemaximum_independent_setc                 C   s   |  | dkS )zReturns True if and only if `nodes` is a clique in `G`.

    `G` is a NetworkX graph. `nodes` is an iterable of nodes in
    `G`.

    r   )subgraphnumber_of_edges)Gnodes r
   Z/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/approximation/tests/test_clique.pyis_independent_set   s   r   c                 C   s*   |  |}t|}| ||d  d kS )zReturns True if and only if `nodes` is an independent set
    in `G`.

    `G` is an undirected simple graph. `nodes` is an iterable of
    nodes in `G`.

          )r   lenr   )r   r	   Hnr
   r
   r   	is_clique   s   
r   c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	TestCliqueRemovalz`Unit tests for the
    :func:`~networkx.algorithms.approximation.clique_removal` function.

    c                    sV   t   t \}}t |sJ t fdd|D sJ tdd |D s)J d S )Nc                 3       | ]}t  |V  qd S Nr   .0cliquer   r
   r   	<genexpr>.       z7TestCliqueRemoval.test_trivial_graph.<locals>.<genexpr>c                 s   s    | ]	}t |d kV  qdS )r   N)r   r   r
   r
   r   r   0   s    )nxtrivial_graphr   r   allselfindependent_setcliquesr
   r   r   test_trivial_graph*   s
   z$TestCliqueRemoval.test_trivial_graphc                    sB   t d t \}}t |sJ t fdd|D sJ d S )N
   c                 3   r   r   r   r   r   r
   r   r   6   r   z8TestCliqueRemoval.test_complete_graph.<locals>.<genexpr>)r   complete_graphr   r   r    r!   r
   r   r   test_complete_graph2   s   
z%TestCliqueRemoval.test_complete_graphc                    sD   t dd t \}}t |sJ t fdd|D s J d S )Nr&      c                 3   r   r   r   r   r   r
   r   r   <   r   z7TestCliqueRemoval.test_barbell_graph.<locals>.<genexpr>)r   barbell_graphr   r   r    r!   r
   r   r   test_barbell_graph8   s   z$TestCliqueRemoval.test_barbell_graphN)__name__
__module____qualname____doc__r%   r(   r+   r
   r
   r
   r   r   $   s
    r   c                   @   r   )	TestMaxCliquez[Unit tests for the :func:`networkx.algorithms.approximation.max_clique`
    function.

    c                 C   s    t  }tt|dksJ d S Nr   )r   
null_graphr   r   )r"   r   r
   r
   r   test_null_graphE   s   zTestMaxClique.test_null_graphc                 C   s&   t d}t|}dt|ksJ d S )N   )r   r'   r   r   )r"   graphmcr
   r
   r   r(   I   s   
z!TestMaxClique.test_complete_graphc                 C   sV   t d}|dd t|}t|dksJ t dd}t|}t|dks)J dS )zTests that the maximal clique is computed according to maximum
        cardinality of the sets.

        For more information, see pull request #1531.

        r)      r   r4   r   N)r   r'   add_edger   r   lollipop_graph)r"   r   r   r
   r
   r   test_maximal_by_cardinalityO   s   
z)TestMaxClique.test_maximal_by_cardinalityN)r,   r-   r.   r/   r3   r(   r:   r
   r
   r
   r   r0   ?   s
    r0   c                  C   s   t d} t | g d | dd | dd | d t| dks&J | d t| dks3J | dd	 t| d
ksAJ d S )N	   )r;   r&         r         r)   r         )r   r'   	add_cycler8   add_noder   remove_noderemove_edger   r
   r
   r   test_large_clique_size`   s   


rF   c                  C   s    t  } tt| dksJ d S r1   )r   Graphr   r   r   r
   r
   r   test_independent_setn   s   rH   )r/   networkxr   !networkx.algorithms.approximationr   r   r   r   r   r   r   r0   rF   rH   r
   r
   r
   r   <module>   s    
!