
    ިsg                     @    d Z ddlZddlZddlZddlmZ  G d d      Zy)zEUnit tests for the :mod:`networkx.algorithms.structuralholes` module.    N)dispatch_interfacec                   ^    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zy)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                    t        j                         | _        | j                  j                  g d       ddddd| _        t        j
                         | _        | j                  j                  g d       dddddddddd	d
| _        y )
N))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            
   )nxDiGraphr   add_edges_from	D_weightsGraphr   	G_weights)selfs    a/var/www/html/venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_structuralholes.pysetup_methodz TestStructuralHoles.setup_method   s    >?"#Q1E	
 
    c                     t        j                  | j                        }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ y )Nr   g?5^I?MbP?absr   r   gMbX9?)r   
constraintr   pytestapproxr   r#   s     r   test_constraint_directedz,TestStructuralHoles.test_constraint_directed8   sk    ]]466*
!}e >>>>!}e >>>>!}e >>>>r   c                     t        j                  | j                        }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ y )Nr   gy&1?r    r!   r   r   )r   effective_sizer   r$   r%   r   r)   s     r   test_effective_size_directedz0TestStructuralHoles.test_effective_size_directed>   sp    **4662a FMM%T$BBBBa FMM%T$BBBBa FMM!$>>>>r   c                 b   | j                   j                         }t        j                  || j                  d       t        j
                  |d      }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d	   t        j                  d
d      k(  sJ y )Nweightr-   r   gzG?r    r!   r   g}?5^I?r   g?5^I?)r   copyr   set_edge_attributesr   r#   r$   r%   )r   r   r#   s      r   !test_constraint_weighted_directedz5TestStructuralHoles.test_constraint_weighted_directedD   s    FFKKM
q$..(;]]1X6
!}e >>>>!}e >>>>!}e >>>>r   c                 b   | j                   j                         }t        j                  || j                  d       t        j
                  |d      }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d	   t        j                  dd      k(  sJ y )
Nr-   r.   r   gOn?r    r!   r   gS?r   )r   r/   r   r0   r   r)   r$   r%   )r   r   r)   s      r   %test_effective_size_weighted_directedz9TestStructuralHoles.test_effective_size_weighted_directedL   s    FFKKM
q$..(;**1X>a FMM%T$BBBBa FMM%T$BBBBa FMM!$>>>>r   c                     t        j                  | j                        }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ y )	Nr   g?r    r!   r	   g
ףp=
?r   r   )r   r#   r   r$   r%   r&   s     r   test_constraint_undirectedz.TestStructuralHoles.test_constraint_undirectedT   sk    ]]466*
#&--4"@@@@#&--4"@@@@#&--t"<<<<r   c                     t        j                  | j                        }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ y )	Nr   Gz@{Gz?r!   r	         @r   r   )r   r)   r   r$   r%   r*   s     r   'test_effective_size_undirected_borgattiz;TestStructuralHoles.test_effective_size_undirected_borgattiZ   sp    **4662c"fmmDd&CCCCc"fmmDd&CCCCc"fmmA4&@@@@r   c                 N   | j                   j                         }t        j                  |dd       t        j                  |d      }|d   t        j                  dd      k(  sJ |d   t        j                  d	d      k(  sJ |d
   t        j                  dd      k(  sJ y )Nr   r-   r.   r   r7   r8   r!   r	   r9   r   )r   r/   r   r0   r)   r$   r%   r   r   r)   s      r   test_effective_size_undirectedz2TestStructuralHoles.test_effective_size_undirected`   s    FFKKM
q!X.**1X>c"fmmDd&CCCCc"fmmDd&CCCCc"fmmA4&@@@@r   c                 b   | j                   j                         }t        j                  || j                  d       t        j
                  |d      }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d	   t        j                  d
d      k(  sJ y )Nr-   r.   r   gA`"?r    r!   r	   gq=
ףp?r   r   )r   r/   r   r0   r   r#   r$   r%   r   r   r#   s      r   #test_constraint_weighted_undirectedz7TestStructuralHoles.test_constraint_weighted_undirectedh   s    FFKKM
q$..(;]]1X6
#&--4"@@@@#&--4"@@@@#&--t"<<<<r   c                 b   | j                   j                         }t        j                  || j                  d       t        j
                  |d      }|d   t        j                  dd      k(  sJ |d   t        j                  dd      k(  sJ |d	   t        j                  d
d      k(  sJ y )Nr-   r.   r   gzG@r8   r!   r	   g(\@r   r   )r   r/   r   r0   r   r)   r$   r%   r<   s      r   'test_effective_size_weighted_undirectedz;TestStructuralHoles.test_effective_size_weighted_undirectedp   s    FFKKM
q$..(;**1X>c"fmmDd&CCCCc"fmmDd&CCCCc"fmmA4&@@@@r   c                     | j                   j                         }|j                  d       t        j                  |      }t        j                  |d         sJ y Nr   )r   r/   add_noder   r#   mathisnanr?   s      r   test_constraint_isolatedz,TestStructuralHoles.test_constraint_isolatedx   s@    FFKKM	

1]]1%
zz*Q-(((r   c                     | j                   j                         }|j                  d       t        j                  || j
                  d       t        j                  |d      }t        j                  |d         sJ y )Nr   r-   r.   )	r   r/   rE   r   r0   r   r)   rF   rG   r<   s      r   test_effective_size_isolatedz0TestStructuralHoles.test_effective_size_isolated~   s[    FFKKM	

1
q$..(;**1X>zz.+,,,r   c                     | j                   j                         }|j                  d       t        j                  |      }t        j                  |d         sJ y rD   )r   r/   rE   r   r)   rF   rG   r<   s      r   %test_effective_size_borgatti_isolatedz9TestStructuralHoles.test_effective_size_borgatti_isolated   sC    FFKKM	

1**1-zz.+,,,r   N)__name__
__module____qualname____doc__r   r'   r+   r1   r3   r5   r:   r=   r@   rB   rH   rJ   rL    r   r   r   r      sL    	
B????=AA=A)--r   r   )rP   rF   r$   networkxr   networkx.classes.testsr   r   rQ   r   r   <module>rT      s     K    5~- ~-r   