o
    3ήc                     @   sr   d dl mZmZ d dlZd dlZd dlmZmZ dd Z	dd Z
dd	 Zd
d Zdd Zdd ZG dd dZdS )    )chaincombinationsN)asyn_lpa_communitieslabel_propagation_communitiesc                  C   sf   t tj# t } | dd | dd | dd t| }W d    d S 1 s,w   Y  d S )Nabcd)pytestraisesnxNetworkXNotImplementedDiGraphadd_edger   )testresult r   a/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/community/tests/test_label_propagation.pytest_directed_not_supported   s   
"r   c                  C   sT   t d} tt| dhgksJ t| D ]	}|dhksJ qtttt|  d S )Nr   )r   empty_graphlistr   r
   r   	TypeErrornext)G	communityr   r   r   test_iterator_vs_iterable   s
   
r   c                  C   sD   t  } | d tdgh}t| }dd |D }||ks J d S )Nr   c                 S      h | ]}t |qS r   	frozenset.0r   r   r   r   	<setcomp>&       z test_one_node.<locals>.<setcomp>)r   Graphadd_noder   r   r   ground_truthcommunitiesr   r   r   r   test_one_node   s   
r(   c                  C   s   t  } | dd | dd | dd | dd | dd | dd tg dtg dh}t| }d	d
 |D }||ksEJ d S )Nr   r   r	   r   ef)r   r   r	   )r   r)   r*   c                 S   r   r   r   r   r   r   r   r!   9   r"   z/test_unconnected_communities.<locals>.<setcomp>)r   r#   r   r   r   r%   r   r   r   test_unconnected_communities*   s   r+   c                  C   s  t  } | dd | dd | dd | dd | dd | dd | dd | dd | dd | dd | dd | dd | dd | d	d | d	d | d	d | d
d | d
d | d
d | d
d	 | dd | dd | d tg dtg dtddgtdgh}tg dtddgtdgh}||f}t| }dd |D }||v sJ d S )Nr   r   r   r	   r)   12345xyz)r   r   r   r	   r)   )r,   r-   r.   r/   r0   )
r   r   r   r	   r)   r,   r-   r.   r/   r0   c                 S   r   r   r   r   r   r   r   r!   k   r"   z-test_connected_communities.<locals>.<setcomp>)r   r#   r   r$   r   r   )r   ground_truth1ground_truth2r&   r'   r   r   r   r   test_connected_communities=   sJ   





r6   c                  C   s6   t  } t dd}|ddg t|  t| d S )N   
   )r      )r9   r8   )r   karate_club_graphcaveman_graphadd_edges_fromr   )test1test2r   r   r   test_terminationo   s
   r?   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestAsynLpaCommunitiesc                 C   s&   t |}dd |D }||ksJ dS )aE  Checks that the communities computed from the given graph ``G``
        using the :func:`~networkx.asyn_lpa_communities` function match
        the set of nodes given in ``expected``.

        ``expected`` must be a :class:`set` of :class:`frozenset`
        instances, each element of which is a node in the graph.

        c                 S   r   r   r   r   r   r   r   r!      r"   z<TestAsynLpaCommunities._check_communities.<locals>.<setcomp>N)r   )selfr   expectedr'   r   r   r   r   _check_communitiesz   s   	z)TestAsynLpaCommunities._check_communitiesc                 C   s   t  }t }| || d S )N)r   
null_graphsetrC   rA   r   r&   r   r   r   test_null_graph   s   z&TestAsynLpaCommunities.test_null_graphc                 C   s&   t d}tdgh}| || d S )N   r   )r   r   r   rC   rF   r   r   r   test_single_node   s   
z'TestAsynLpaCommunities.test_single_nodec                 C   s.   t g d}tdtdh}| || d S )Nabacbcdedffeabcdef)r   r#   r   rC   rF   r   r   r   test_simple_communities   s   z.TestAsynLpaCommunities.test_simple_communitiesc                 C   sH   t g d}tdtdh}t|dd}dd |D }||ks"J d S )NrJ   rQ   rR   rH   )seedc                 S   r   r   r   r   r   r   r   r!      r"   z<TestAsynLpaCommunities.test_seed_argument.<locals>.<setcomp>)r   r#   r   r   )rA   r   r&   r'   r   r   r   r   test_seed_argument   s
   z)TestAsynLpaCommunities.test_seed_argumentc                 C   s@   dd t dD }tdd |D }t|}| || d S )Nc                 S   s&   h | ]}t td | d |d  qS )   rH   )r   range)r    ir   r   r   r!      s   & zBTestAsynLpaCommunities.test_several_communities.<locals>.<setcomp>   c                 s   s    | ]}t |d V  qdS )r7   N)r   r   r   r   r   	<genexpr>   s    zBTestAsynLpaCommunities.test_several_communities.<locals>.<genexpr>)rW   r   from_iterabler   r#   rC   )rA   r&   edgesr   r   r   r   test_several_communities   s   
z/TestAsynLpaCommunities.test_several_communitiesN)	__name__
__module____qualname__rC   rG   rI   rS   rU   r]   r   r   r   r   r@   y   s    r@   )	itertoolsr   r   r
   networkxr   networkx.algorithms.communityr   r   r   r   r(   r+   r6   r?   r@   r   r   r   r   <module>   s    
2
