U
    ?h                     @   s:   d Z ddlZddlZddlZddlmZ G dd dZdS )zEUnit tests for the :mod:`networkx.algorithms.structuralholes` module.    N)dispatch_interfacec                   @   s   e Zd ZdZdd Zejddd ej	g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d Zdd Zdd Zdd ZdS ) TestStructuralHolesa  Unit tests for computing measures of structural holes.

    The expected values for these functions were originally computed using the
    proprietary software `UCINET`_ and the free software `IGraph`_ , and then
    computed by hand to make sure that the results are correct.

    .. _UCINET: https://sites.google.com/site/ucinetsoftware/home
    .. _IGraph: http://igraph.org/

    c                 C   sx   t  | _| jddddg ddddd| _t  | _| jdd	d
dddddddg
 ddddddddddd
| _d S )Nr      r      r   r   r   r   r   r   )r   r   r   r	   ABr   Fr   Gr   Er   r   r   r   r   r   r   Dr   r   r   C            
   )
r
   r   r   r   r   r   r   r   r   r   )nxZDiGraphr   Zadd_edges_from	D_weightsZGraphr   	G_weights)self r$   `/var/www/html/venv/lib/python3.8/site-packages/networkx/algorithms/tests/test_structuralholes.pysetup_method   s8    

z TestStructuralHoles.setup_methodwrapperc                 C   s   | S )Nr$   )xr$   r$   r%   <lambda>9       zTestStructuralHoles.<lambda>c                 C   sb   t || j}|d tjdddks*t|d tjdddksDt|d tjdddks^td S )Nr   g?5^I?MbP?absr   r   gMbX9?)r    
constraintr   pytestapproxAssertionError)r#   r'   r.   r$   r$   r%   test_constraint_directed9   s    z,TestStructuralHoles.test_constraint_directedc                 C   s^   t | j}|d tjdddks&t|d tjdddks@t|d tjdddksZtd S )Nr   gy&1?r+   r,   r   r   )r    effective_sizer   r/   r0   r1   r#   r3   r$   r$   r%   test_effective_size_directed@   s    z0TestStructuralHoles.test_effective_size_directedc                 C   sz   | j  }t|| jd tj|dd}|d tjdddksBt|d tjdddks\t|d	 tjd
ddksvtd S )Nweightr6   r   gzG?r+   r,   r   g}?5^I?r   g?5^I?)	r   copyr    set_edge_attributesr!   r.   r/   r0   r1   )r#   r   r.   r$   r$   r%   !test_constraint_weighted_directedF   s    
z5TestStructuralHoles.test_constraint_weighted_directedc                 C   sz   | j  }t|| jd tj|dd}|d tjdddksBt|d tjdddks\t|d	 tjdddksvtd S )
Nr6   r7   r   gOn?r+   r,   r   gS?r   )	r   r8   r    r9   r!   r3   r/   r0   r1   )r#   r   r3   r$   r$   r%   %test_effective_size_weighted_directedN   s    
z9TestStructuralHoles.test_effective_size_weighted_directedc                 C   s^   t | j}|d tjdddks&t|d tjdddks@t|d tjdddksZtd S )	Nr   g?r+   r,   r   g
ףp=
?r   r   )r    r.   r   r/   r0   r1   )r#   r.   r$   r$   r%   test_constraint_undirectedV   s    z.TestStructuralHoles.test_constraint_undirectedc                 C   s^   t | j}|d tjdddks&t|d tjdddks@t|d tjdddksZtd S )	Nr   Gz@{Gz?r,   r         @r   r   )r    r3   r   r/   r0   r1   r4   r$   r$   r%   'test_effective_size_undirected_borgatti\   s    z;TestStructuralHoles.test_effective_size_undirected_borgattic                 C   sx   | j  }t|dd tj|dd}|d tjdddks@t|d tjd	ddksZt|d
 tjdddksttd S )Nr   r6   r7   r   r=   r>   r,   r   r?   r   )r   r8   r    r9   r3   r/   r0   r1   r#   r   r3   r$   r$   r%   test_effective_size_undirectedb   s    
z2TestStructuralHoles.test_effective_size_undirectedc                 C   sz   | j  }t|| jd tj|dd}|d tjdddksBt|d tjdddks\t|d	 tjd
ddksvtd S )Nr6   r7   r   gA`"?r+   r,   r   gq=
ףp?r   r   )	r   r8   r    r9   r"   r.   r/   r0   r1   r#   r   r.   r$   r$   r%   #test_constraint_weighted_undirectedj   s    
z7TestStructuralHoles.test_constraint_weighted_undirectedc                 C   sz   | j  }t|| jd tj|dd}|d tjdddksBt|d tjdddks\t|d	 tjd
ddksvtd S )Nr6   r7   r   gzG@r>   r,   r   g(\@r   r   )	r   r8   r    r9   r"   r3   r/   r0   r1   rA   r$   r$   r%   'test_effective_size_weighted_undirectedr   s    
z;TestStructuralHoles.test_effective_size_weighted_undirectedc                 C   s4   | j  }|d t|}t|d s0td S Nr   )r   r8   add_noder    r.   mathisnanr1   rC   r$   r$   r%   test_constraint_isolatedz   s    


z,TestStructuralHoles.test_constraint_isolatedc                 C   sH   | j  }|d t|| jd tj|dd}t|d sDt	d S )Nr   r6   r7   )
r   r8   rG   r    r9   r"   r3   rH   rI   r1   rA   r$   r$   r%   test_effective_size_isolated   s
    

z0TestStructuralHoles.test_effective_size_isolatedc                 C   s4   | j  }|d t|}t|d s0td S rF   )r   r8   rG   r    r3   rH   rI   r1   rA   r$   r$   r%   %test_effective_size_borgatti_isolated   s    


z9TestStructuralHoles.test_effective_size_borgatti_isolatedN)__name__
__module____qualname____doc__r&   r/   markZparametrizer   convertr2   r5   r:   r;   r<   r@   rB   rD   rE   rJ   rK   rL   r$   r$   r$   r%   r   
   s   #
r   )rP   rH   r/   Znetworkxr    Znetworkx.classes.testsr   r   r$   r$   r$   r%   <module>   s
   