o
    3ήc!                     @   sP   d Z ddlZddlZG dd dZG dd dZG dd dZG d	d
 d
ZdS )z%
Tests for Group Centrality Measures
    Nc                   @   sL   e Z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 )TestGroupBetweennessCentralityc                 C   s8   t d}dg}t j||dddd}d}||ksJ dS )D
        Group betweenness centrality for single node group
              NFweight
normalized	endpoints      @nx
path_graphgroup_betweenness_centralityselfGCbb_answer r   V/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/centrality/tests/test_group.py"test_group_betweenness_single_node      

zATestGroupBetweennessCentrality.test_group_betweenness_single_nodec                 C   s8   t d}dg}t j||dddd}d}||ksJ dS )r   r   r   NFTr   g      @r   r   r   r   r   %test_group_betweenness_with_endpoints   r   zDTestGroupBetweennessCentrality.test_group_betweenness_with_endpointsc                 C   s:   t d}ddg}t j||dddd}d}||ksJ dS )	ze
        Group betweenness centrality for group with more than
        1 node and normalized
        r   r      NTFr   g      ?r   r   r   r   r   !test_group_betweenness_normalized$   s   

z@TestGroupBetweennessCentrality.test_group_betweenness_normalizedc                 C   sD   t d}g dg dg}t j||ddd}ddg}||ks J dS )	9
        Group betweenness centrality value of 0
           )r   r      r   r   r   NFr   r           r
   r   cycle_graphr   r   r   r   r   %test_two_group_betweenness_value_zero1   s
   
zDTestGroupBetweennessCentrality.test_two_group_betweenness_value_zeroc                 C   s8   t d}g d}t j||ddd}d}||ksJ dS )r   r   r   NFr    r!   r"   r   r   r   r   !test_group_betweenness_value_zero;   s
   
z@TestGroupBetweennessCentrality.test_group_betweenness_value_zeroc                 C   sB   t d}|dd dg}t j||ddd}d}||ksJ dS )zF
        Group betweenness centrality in a disconnected graph
        r   r   r   NFr    r!   )r   r   remove_edger   r   r   r   r   )test_group_betweenness_disconnected_graphE   s   
zHTestGroupBetweennessCentrality.test_group_betweenness_disconnected_graphc                 C   H   t tj ttdg d W d   dS 1 sw   Y  dS )J
        Node(s) in C not in graph, raises NodeNotFound exception
        r   )   r      N)pytestraisesr   NodeNotFoundr   r   r   r   r   r   (test_group_betweenness_node_not_in_graphP      "zGTestGroupBetweennessCentrality.test_group_betweenness_node_not_in_graphc                 C   s   t  }|jdddd |jdddd |jdddd |jdddd |jdddd |jdddd |jdddd ddg}t j||d	d
d}d}||ksQJ dS zO
        Group betweenness centrality in a directed and weighted graph
        r   r   )r      r   r*   r   r   r   Fr    g      @N)r   DiGraphadd_edger   r   r   r   r   (test_group_betweenness_directed_weightedW   s   zGTestGroupBetweennessCentrality.test_group_betweenness_directed_weightedN)__name__
__module____qualname__r   r   r   r$   r%   r'   r0   r6   r   r   r   r   r      s    

r   c                   @   sX   e Zd ZedZe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 )TestProminentGroupnumpypandasc                 C   sH   t d}d}t j||ddd\}}ddg}}||kr ||ks"J dS )z1
        Prominent group for single node
        r   r   Fr   r	         @r3   Nr   r   prominent_groupr   r   kr   gr   g_answerr   r   r    test_prominent_group_single_nodem   s
   
z3TestProminentGroup.test_prominent_group_single_nodec                 C   sJ   t d}d}t j||ddgd\}}ddg}}||kr!||ks#J dS )z4
        Prominent group without some nodes
        r   r   Fr3   )r   r   r
   Nr?   rA   r   r   r   test_prominent_group_with_cw   s
   
z.TestProminentGroup.test_prominent_group_with_cc                 C   sJ   t d}d}t j||ddd\}}dddg}}||kr!||ks#J dS )zH
        Prominent group with normalized result, with endpoints
        r   r3   Tr=   333333?r   Nr   r#   r@   rA   r   r   r   )test_prominent_group_normalized_endpoints   s
   
z<TestProminentGroup.test_prominent_group_normalized_endpointsc                 C   sT   t d}|dd d}t j||ddd\}}ddg}}||kr&||ks(J dS )	z7
        Prominent group of disconnected graph
        r   r   r   NFr    r>   r   )r   r   r&   r@   rA   r   r   r   'test_prominent_group_disconnected_graph   s   
z:TestProminentGroup.test_prominent_group_disconnected_graphc                 C   sJ   t tj tjtdddgd W d   dS 1 sw   Y  dS )r)   r   r   
   )r   N)r,   r-   r   r.   r@   r   r/   r   r   r   &test_prominent_group_node_not_in_graph   s   "z9TestProminentGroup.test_prominent_group_node_not_in_graphc                 C   s   t  }|jdddd |jdddd |jdddd |jdddd |jdddd |jdddd |jdddd d}t j||d	d
d\}}dddg}}||krX||ksZJ dS r2   )r   r4   r5   r@   rA   r   r   r   r6      s   z;TestProminentGroup.test_group_betweenness_directed_weightedc                 C   sL   t d}d}t j||dddd\}}dddg}}||kr"||ks$J dS )	zD
        Group betweenness centrality in a greedy algorithm
        r   r3   T)r   r	   greedyrG   r   r   NrH   rA   r   r   r   %test_prominent_group_greedy_algorithm   s
   
z8TestProminentGroup.test_prominent_group_greedy_algorithmN)r7   r8   r9   r,   importorskipnppdrE   rF   rI   rJ   rL   r6   rN   r   r   r   r   r:   i   s    




r:   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestGroupClosenessCentralityc                 C   s4   t d}t |dg}t |d}||ksJ dS )zD
        Group closeness centrality for a single node group
        r   r   N)r   r   group_closeness_centralitycloseness_centralityr   r   cc_answerr   r   r    test_group_closeness_single_node   s   
z=TestGroupClosenessCentrality.test_group_closeness_single_nodec                 C   s:   t  }|g d t |ddg}d}||ksJ dS )zE
        Group closeness centrality for a disconnected graph
        )r   r3   r   r*   r   r3   r   N)r   Graphadd_nodes_fromrS   rU   r   r   r   !test_group_closeness_disconnected   s
   z>TestGroupClosenessCentrality.test_group_closeness_disconnectedc                 C   s.   t d}t |ddg}d}||ksJ dS )zV
        Group closeness centrality for a group with more than
        1 node
        r*   r   r3   N)r   r   rS   rU   r   r   r   "test_group_closeness_multiple_node   s   
z?TestGroupClosenessCentrality.test_group_closeness_multiple_nodec                 C   r(   )zJ
        Node(s) in S not in graph, raises NodeNotFound exception
        r   r   r   r+   N)r,   r-   r   r.   rS   r   r/   r   r   r   &test_group_closeness_node_not_in_graph   r1   zCTestGroupClosenessCentrality.test_group_closeness_node_not_in_graphN)r7   r8   r9   rX   r[   r\   r^   r   r   r   r   rR      s
    	

rR   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestGroupDegreeCentralityc                 C   s6   t d}t |dg}t |d }||ksJ dS )zA
        Group degree centrality for a single node group
        r*   r   N)r   r   group_degree_centralitydegree_centralityr   r   dd_answerr   r   r   (test_group_degree_centrality_single_node   s   
zBTestGroupDegreeCentrality.test_group_degree_centrality_single_nodec                 C   H   t  }|g d |g d t |ddg}d}||ks"J dS )zQ
        Group degree centrality for group with more than
        1 node
        r   r3   r   r*   r   r   r   r+   )r   r3   )r   r   )r   r   )r   r   )r   r+   )r3   r   )r3   r*   )r3   r   r   r3   N)r   rY   rZ   add_edges_fromr`   rb   r   r   r   *test_group_degree_centrality_multiple_node   s   zDTestGroupDegreeCentrality.test_group_degree_centrality_multiple_nodec                 C   sH   t  }|g d |g d t |ddg}d}||ks"J dS )z9
        Group in-degree centrality in a DiGraph
        rg   rh   r   r3   r   N)r   r4   rZ   ri   group_in_degree_centralityrb   r   r   r   test_group_in_degree_centrality      z9TestGroupDegreeCentrality.test_group_in_degree_centralityc                 C   rf   )z:
        Group out-degree centrality in a DiGraph
        rg   rh   r   r3   N)r   r4   rZ   ri   group_out_degree_centralityrb   r   r   r    test_group_out_degree_centrality  rm   z:TestGroupDegreeCentrality.test_group_out_degree_centralityc                 C   r(   )zA
        Node(s) in S not in graph, raises NetworkXError
        r   r]   N)r,   r-   r   NetworkXErrorr`   r   r/   r   r   r   .test_group_degree_centrality_node_not_in_graph  r1   zHTestGroupDegreeCentrality.test_group_degree_centrality_node_not_in_graphN)r7   r8   r9   re   rj   rl   ro   rq   r   r   r   r   r_      s    	r_   )__doc__r,   networkxr   r   r:   rR   r_   r   r   r   r   <module>   s    ^P&