o
    3ήc
                     @   s&   d Z ddlZddlZG dd dZdS )z'
    Unit tests for degree centrality.
    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 )TestDegreeCentralityc                 C   s  t  | _t d| _t d| _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 || _	t 
 }|dd |dd |dd |dd |dd |dd |dd |dd || _d S )N      
AcciaiuoliMedici
CastellaniPeruzziStrozzi	BarbadoriRidolfi
TornabuoniAlbizziSalviatiPazziBischeriGuadagniGinoriLamberteschir                     )nxkrackhardt_kite_graphK
path_graphP3complete_graphK5Graphadd_edgeFDiGraphG)selfr#   r%    r'   b/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/centrality/tests/test_degree_centrality.pysetup_method   sF   

z!TestDegreeCentrality.setup_methodc                 C   sT   t | j}tttddgd }| D ]\}}|| tj|ddks'J qd S )Nr   r   Hz>abs)	r   degree_centralityr    dictziprangeitemspytestapproxr&   dexactndcr'   r'   r(   test_degree_centrality_13   s
   z-TestDegreeCentrality.test_degree_centrality_1c                 C   sH   t | j}dddd}| D ]\}}|| tj|ddks!J qd S )Ng      ?r   )r   r   r   r*   r+   )r   r-   r   r1   r2   r3   r4   r'   r'   r(   test_degree_centrality_29   s
   z-TestDegreeCentrality.test_degree_centrality_2c                 C   s^   t | j}ddddddddddd
}| D ]\}}|| tjt|dd	d
ks,J qd S )Ng"~j?gZd;O?gMbX?gn?g"~j?g"~j?)
r   r   r   r   r   r   r   r   r   	   .3fr*   r+   )r   r-   r   r1   r2   r3   floatr4   r'   r'   r(   test_degree_centrality_3?   s   $z-TestDegreeCentrality.test_degree_centrality_3c                 C   sh   t | j}t| j }g d}tt||}| D ]\}}|| tj	t
|dddks1J qd S )N)V-?1Zd?M?r@   r@   r?   M?r?   g~jt?r?   r@   r@   rA   rB   r@   r<   r*   r+   )r   r-   r#   sortednodesr.   r/   r1   r2   r3   r=   )r&   r5   namesdcsr6   r7   r8   r'   r'   r(   test_degree_centrality_4P   s   $z-TestDegreeCentrality.test_degree_centrality_4c              
   C   T   t | j}dddddddddd	}| D ]\}}|| tj|ddks'J qd S )N        g      ?      ?	r   r   r   r   r   r   r   r   r   r*   r+   )r   in_degree_centralityr%   r1   r2   r3   r4   r'   r'   r(   test_indegree_centralityh      z-TestDegreeCentrality.test_indegree_centralityc              
   C   rH   )NrJ   g      ?rI   rK   r*   r+   )r   out_degree_centralityr%   r1   r2   r3   r4   r'   r'   r(   test_outdegree_centralityx   rN   z.TestDegreeCentrality.test_outdegree_centralityc                 C   s   t jt jd}i t |ksJ i t |ksJ i t |ks"J t jdt jd}ddit |ks5J ddit |ks@J ddit |ksKJ d S )N)create_usingr   r   )r   empty_graphr$   r-   rO   rL   )r&   r%   r'   r'   r(   test_small_graph_centrality   s   z0TestDegreeCentrality.test_small_graph_centralityN)__name__
__module____qualname__r)   r9   r:   r>   rG   rM   rP   rS   r'   r'   r'   r(   r   
   s    (r   )__doc__r2   networkxr   r   r'   r'   r'   r(   <module>   s    