
    Vh!                     h    d Z ddlZddlZ G d d      Z G d d      Z G d d      Z G d	 d
      Zy)z%
Tests for Group Centrality Measures
    Nc                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestGroupBetweennessCentralityc                 z    t        j                  d      }dg}t        j                  ||ddd      }d}||k(  sJ y)D
        Group betweenness centrality for single node group
              NFweight
normalized	endpoints      @nx
path_graphgroup_betweenness_centralityselfGCbb_answers        _/home/dcms/DCMS/lib/python3.12/site-packages/networkx/algorithms/centrality/tests/test_group.py"test_group_betweenness_single_nodezATestGroupBetweennessCentrality.test_group_betweenness_single_node   sG     MM!C++q%5
 H}}    c                 z    t        j                  d      }dg}t        j                  ||ddd      }d}||k(  sJ y)r   r   r   NFTr	   g      @r   r   s        r   %test_group_betweenness_with_endpointszDTestGroupBetweennessCentrality.test_group_betweenness_with_endpoints   sG     MM!C++q%4
 H}}r   c                 |    t        j                  d      }ddg}t        j                  ||ddd      }d}||k(  sJ y)	ze
        Group betweenness centrality for group with more than
        1 node and normalized
        r   r      NTFr	   g      ?r   r   s        r   !test_group_betweenness_normalizedz@TestGroupBetweennessCentrality.test_group_betweenness_normalized#   sI    
 MM!F++q$%
 H}}r   c                     t        j                  d      }g dg dg}t        j                  ||dd      }ddg}||k(  sJ y)	9
        Group betweenness centrality value of 0
           )r   r      r   r   r   NFr
   r           r   r   cycle_graphr   r   s        r   %test_two_group_betweenness_value_zerozDTestGroupBetweennessCentrality.test_two_group_betweenness_value_zero0   sG     NN1	"++Aq%P:H}}r   c                 z    t        j                  d      }g d}t        j                  ||dd      }d}||k(  sJ y)r!   r#   r$   NFr%   r&   r'   r   s        r   !test_group_betweenness_value_zeroz@TestGroupBetweennessCentrality.test_group_betweenness_value_zero:   s>     NN1++Aq%PH}}r   c                     t        j                  d      }|j                  dd       dg}t        j                  ||dd      }d}||k(  sJ y)zF
        Group betweenness centrality in a disconnected graph
        r   r   r   NFr%   r&   )r   r   remove_edger   r   s        r   )test_group_betweenness_disconnected_graphzHTestGroupBetweennessCentrality.test_group_betweenness_disconnected_graphD   sN     MM!	aC++Aq%PH}}r   c                     t        j                  t        j                        5  t        j                  t        j
                  d      g d       ddd       y# 1 sw Y   yxY w)J
        Node(s) in C not in graph, raises NodeNotFound exception
        r   )   r"      N)pytestraisesr   NodeNotFoundr   r   r   s    r   (test_group_betweenness_node_not_in_graphzGTestGroupBetweennessCentrality.test_group_betweenness_node_not_in_graphO   sF     ]]2??+ 	I++BMM!,<iH	I 	I 	I   ,AA"c                    t        j                         }|j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       ddg}t        j                  ||d	d
      }d}||k(  sJ yzO
        Group betweenness centrality in a directed and weighted graph
        r   r   )r
      r   r1   r#   r"   r
   Fr%   g      @N)r   DiGraphadd_edger   r   s        r   (test_group_betweenness_directed_weightedzGTestGroupBetweennessCentrality.test_group_betweenness_directed_weightedV   s     JJL	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"F++AqeTH}}r   N)__name__
__module____qualname__r   r   r   r)   r+   r.   r7   r>    r   r   r   r   
   s+    

	Ir   r   c                   ~    e Zd Z ej                  d      Z ej                  d      Zd Zd Zd Z	d Z
d Zd Zd	 Zy
)TestProminentGroupnumpypandasc                     t        j                  d      }d}t        j                  ||dd      \  }}ddg}}||k(  r||k(  sJ y)z1
        Prominent group for single node
        r   r   Fr   r         @r;   Nr   r   prominent_groupr   r   kr   gr   g_answers          r    test_prominent_group_single_nodez3TestProminentGroup.test_prominent_group_single_nodel   sQ     MM!!!!Q5EJ1 1#(H}h..r   c                     t        j                  d      }d}t        j                  ||ddg      \  }}ddg}}||k(  r||k(  sJ y)z4
        Prominent group without some nodes
        r   r   Fr;   )r   r   r   NrJ   rL   s          r   test_prominent_group_with_cz.TestProminentGroup.test_prominent_group_with_cv   sS     MM!!!!Q5QC@1 1#(H}h..r   c                     t        j                  d      }d}t        j                  ||dd      \  }}dddg}}||k(  r||k(  sJ y)zH
        Prominent group with normalized result, with endpoints
        r"   r;   TrH   333333?r   Nr   r(   rK   rL   s          r   )test_prominent_group_normalized_endpointsz<TestProminentGroup.test_prominent_group_normalized_endpoints   sS     NN1!!!Q44H1 1a&(H}h..r   c                     t        j                  d      }|j                  dd       d}t        j                  ||dd      \  }}ddg}}||k(  r||k(  sJ y)	z7
        Prominent group of disconnected graph
        r#   r   r   NFr%   rI   r   )r   r   r-   rK   rL   s          r   'test_prominent_group_disconnected_graphz:TestProminentGroup.test_prominent_group_disconnected_graph   s_     MM!	a!!!QtF1 1#(H}h..r   c                     t        j                  t        j                        5  t        j                  t        j
                  d      ddg       ddd       y# 1 sw Y   yxY w)r0   r   r   
   )r   N)r3   r4   r   r5   rK   r   r6   s    r   &test_prominent_group_node_not_in_graphz9TestProminentGroup.test_prominent_group_node_not_in_graph   sF     ]]2??+ 	<r}}Q/rd;	< 	< 	<s   -AA#c                    t        j                         }|j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       d}t        j                  ||d	d
      \  }}dddg}}||k(  r||k(  sJ yr:   )r   r<   r=   rK   rL   s          r   r>   z;TestProminentGroup.test_group_betweenness_directed_weighted   s     JJL	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"	

1a
"!!!QxEJ1 1a&(H}h..r   c                     t        j                  d      }d}t        j                  ||ddd      \  }}dddg}}||k(  r||k(  sJ y)	zD
        Group betweenness centrality in a greedy algorithm
        r"   r;   T)r   r   greedyrT   r#   r   NrU   rL   s          r   %test_prominent_group_greedy_algorithmz8TestProminentGroup.test_prominent_group_greedy_algorithm   sV     NN1!!!Q44PTU1 1a&(H}h..r   N)r?   r@   rA   r3   importorskipnppdrP   rR   rV   rX   r[   r>   r_   rB   r   r   rD   rD   h   sI    			W	%B			X	&B///	/</"/r   rD   c                   $    e Zd Zd Zd Zd Zd Zy)TestGroupClosenessCentralityc                     t        j                  d      }t        j                  |dg      }t        j                  |d      }||k(  sJ y)zD
        Group closeness centrality for a single node group
        r   r   N)r   r   group_closeness_centralitycloseness_centralityr   r   cc_answers       r    test_group_closeness_single_nodez=TestGroupClosenessCentrality.test_group_closeness_single_node   sD     MM!))!aS1**1a0H}}r   c                     t        j                         }|j                  g d       t        j                  |ddg      }d}||k(  sJ y)zE
        Group closeness centrality for a disconnected graph
        )r   r;   r   r1   r   r;   r   N)r   Graphadd_nodes_fromrf   rh   s       r   !test_group_closeness_disconnectedz>TestGroupClosenessCentrality.test_group_closeness_disconnected   sD     HHJ	&))!aV4H}}r   c                 p    t        j                  d      }t        j                  |ddg      }d}||k(  sJ y)zV
        Group closeness centrality for a group with more than
        1 node
        r1   r   r;   N)r   r   rf   rh   s       r   "test_group_closeness_multiple_nodez?TestGroupClosenessCentrality.test_group_closeness_multiple_node   s9    
 MM!))!aV4H}}r   c                     t        j                  t        j                        5  t        j                  t        j
                  d      g d       ddd       y# 1 sw Y   yxY w)zJ
        Node(s) in S not in graph, raises NodeNotFound exception
        r   r#   r"   r2   N)r3   r4   r   r5   rf   r   r6   s    r   &test_group_closeness_node_not_in_graphzCTestGroupClosenessCentrality.test_group_closeness_node_not_in_graph   sF     ]]2??+ 	G))"--*:IF	G 	G 	Gr8   N)r?   r@   rA   rk   ro   rq   rt   rB   r   r   rd   rd      s    Gr   rd   c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestGroupDegreeCentralityc                     t        j                  d      }t        j                  |dg      }t        j                  |      d   }||k(  sJ y)zA
        Group degree centrality for a single node group
        r1   r   N)r   r   group_degree_centralitydegree_centralityr   r   dd_answers       r   (test_group_degree_centrality_single_nodezBTestGroupDegreeCentrality.test_group_degree_centrality_single_node   sG     MM!&&q1#.''*1-H}}r   c                     t        j                         }|j                  g d       |j                  g d       t        j                  |ddg      }d}||k(  sJ y)zQ
        Group degree centrality for group with more than
        1 node
        r   r;   r   r1   r   r#   r"   r2   )r   r;   )r   r   )r   r#   )r   r"   )r   r2   )r;   r   )r;   r1   )r;   r   r   r;   N)r   rm   rn   add_edges_fromrx   rz   s       r   *test_group_degree_centrality_multiple_nodezDTestGroupDegreeCentrality.test_group_degree_centrality_multiple_node   sX    
 HHJ	12	L	
 &&q1a&1H}}r   c                     t        j                         }|j                  g d       |j                  g d       t        j                  |ddg      }d}||k(  sJ y)z9
        Group in-degree centrality in a DiGraph
        r   r   r   r;   r   N)r   r<   rn   r   group_in_degree_centralityrz   s       r   test_group_in_degree_centralityz9TestGroupDegreeCentrality.test_group_in_degree_centrality   sX     JJL	12	L	
 ))!aV4H}}r   c                     t        j                         }|j                  g d       |j                  g d       t        j                  |ddg      }d}||k(  sJ y)z:
        Group out-degree centrality in a DiGraph
        r   r   r   r;   N)r   r<   rn   r   group_out_degree_centralityrz   s       r    test_group_out_degree_centralityz:TestGroupDegreeCentrality.test_group_out_degree_centrality  sX     JJL	12	L	
 **1q!f5H}}r   c                     t        j                  t        j                        5  t        j                  t        j
                  d      g d       ddd       y# 1 sw Y   yxY w)zA
        Node(s) in S not in graph, raises NetworkXError
        r   rs   N)r3   r4   r   NetworkXErrorrx   r   r6   s    r   .test_group_degree_centrality_node_not_in_graphzHTestGroupDegreeCentrality.test_group_degree_centrality_node_not_in_graph  sH     ]]2++, 	D&&r}}Q'7C	D 	D 	Dr8   N)r?   r@   rA   r}   r   r   r   r   rB   r   r   rv   rv      s    Dr   rv   )__doc__r3   networkxr   r   rD   rd   rv   rB   r   r   <module>r      sE     [ [|M/ M/`#G #GL7D 7Dr   