o
    3ήcK                     @   s   d dl Z d dlmZ d dlZd dlZdd ZG dd dZG dd dZG d	d
 d
Z	G dd dZ
G dd dZG dd dZG dd dZG dd dZdS )    N)partialc           	      K   sn   || |fi |}dd |D }dd |D }t |t |ks!J |D ]}|| tj|| ddks4J q#d S )Nc                 S   $   i | ]\}}}t t||g|qS  tuplesorted.0uvscorer   r   U/tmp/pip-target-vg8gfxp4/lib/python/networkx/algorithms/tests/test_link_prediction.py
<dictcomp>      $ z_test_func.<locals>.<dictcomp>c                 S   r   r   r   r   r   r   r   r      r   gHz>)abs)lenpytestapprox)	Gebunchexpectedpredict_funckwargsresultexp_dictres_dictpr   r   r   
_test_func	   s    r   c                   @   P   e Zd Ze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 )TestResourceAllocationIndexc                 C       t tj| _tt| jd| _d S N)r   )staticmethodnxresource_allocation_indexfuncr   r   testclsr   r   r   setup_class      z'TestResourceAllocationIndex.setup_classc                 C       t d}| |dgdg d S )N   r      )r   r.   g      ?r#   complete_graphr&   selfr   r   r   r   test_K5      
z#TestResourceAllocationIndex.test_K5c                 C   r+   )N   r      r   r7         ?r#   
path_graphr&   r1   r   r   r   test_P3   r4   z#TestResourceAllocationIndex.test_P3c                 C   r+   )N   r.   r7   r.   r7   g      ?r#   
star_graphr&   r1   r   r   r   test_S4!   r4   z#TestResourceAllocationIndex.test_S4c                 C   p   t tj| jtddgdgsJ t tj| jtddgdgs$J t tj| jtddgdgs6J d S Nr-   r>   r6   r   raisesr#   NetworkXNotImplementedr%   DiGraph
MultiGraphMultiDiGraphr2   r   r   r   test_notimplemented%      z/TestResourceAllocationIndex.test_notimplementedc                 C   ,   t  }|ddg | |dgdg d S Nr   r.   r-   r   r.   r   r#   Graphadd_nodes_fromr&   r1   r   r   r   test_no_common_neighbor6      z3TestResourceAllocationIndex.test_no_common_neighborc                 C   r+   )Nr=   r   r   r   r   r.   r/   r1   r   r   r   test_equal_nodes;   r4   z,TestResourceAllocationIndex.test_equal_nodesc                 C   ,   t  }|g d | |d g d d S Nr-   r6   r7   r5   )r   r5   r9   )r.   r7   r9   r.   r5   r   r#   rR   add_edges_fromr&   r1   r   r   r   test_all_nonexistent_edges?   rU   z6TestResourceAllocationIndex.test_all_nonexistent_edgesN__name__
__module____qualname__classmethodr)   r3   r<   rB   rL   rT   rX   ra   r   r   r   r   r          
r   c                   @   H   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )TestJaccardCoefficientc                 C   r    r!   )r"   r#   jaccard_coefficientr%   r   r   r&   r'   r   r   r   r)   F   r*   z"TestJaccardCoefficient.setup_classc                 C   r+   )Nr,   r-   )r   r.   g333333?r/   r1   r   r   r   r3   K   r4   zTestJaccardCoefficient.test_K5c                 C   r+   )Nr=   r6   r8   r:   r1   r   r   r   test_P4O   r4   zTestJaccardCoefficient.test_P4c                 C   rC   rD   rE   rK   r   r   r   rL   S   rM   z*TestJaccardCoefficient.test_notimplementedc                 C   rN   )Nr-   r\   r6   r   r7   r   r_   r1   r   r   r   rT   d   rU   z.TestJaccardCoefficient.test_no_common_neighborc                 C   rN   rO   rQ   r1   r   r   r   test_isolated_nodesi   rU   z*TestJaccardCoefficient.test_isolated_nodesc                 C   rY   rZ   r_   r1   r   r   r   ra   n   rU   z1TestJaccardCoefficient.test_all_nonexistent_edgesN)rc   rd   re   rf   r)   r3   rk   rL   rT   rm   ra   r   r   r   r   ri   E   s    
ri   c                   @   r   )TestAdamicAdarIndexc                 C   r    r!   )r"   r#   adamic_adar_indexr%   r   r   r&   r'   r   r   r   r)   u   r*   zTestAdamicAdarIndex.setup_classc              
   C   s0   t d}| |dgdddtd fg d S )Nr,   r-   r   r.   r5   r=   r#   r0   r&   mathlogr1   r   r   r   r3   z      
&zTestAdamicAdarIndex.test_K5c              
   C   s0   t d}| |dgdddtd fg d S )Nr5   r6   r   r7   r.   )r#   r;   r&   rq   rr   r1   r   r   r   r<   ~   rs   zTestAdamicAdarIndex.test_P3c              
   C   s0   t d}| |dgdddtd fg d S )Nr=   r>   r.   r7   )r#   rA   r&   rq   rr   r1   r   r   r   rB      rs   zTestAdamicAdarIndex.test_S4c                 C   rC   rD   rE   rK   r   r   r   rL      rM   z'TestAdamicAdarIndex.test_notimplementedc                 C   rN   rO   rQ   r1   r   r   r   rT      rU   z+TestAdamicAdarIndex.test_no_common_neighborc              
   C   s0   t d}| |dgdddtd fg d S )Nr=   rV   r   r5   rp   r1   r   r   r   rX      rs   z$TestAdamicAdarIndex.test_equal_nodesc                 C   sN   t  }|g d | |d dddtd fdddtd fdg d S )Nr[   r   r5   r.   r7   r^   )r#   rR   r`   r&   rq   rr   r1   r   r   r   ra      s
   ,z.TestAdamicAdarIndex.test_all_nonexistent_edgesNrb   r   r   r   r   rn   t   rg   rn   c                   @   sj   e Zd Zedd Zdd Zdd Zdd Zej	
d	ejejejfd
d Zdd Zdd Zdd ZdS )TestCommonNeighborCentralityc                 C   r    r!   )r"   r#   common_neighbor_centralityr%   r   r   r&   r'   r   r   r   r)      r*   z(TestCommonNeighborCentrality.setup_classc                 C   s:   t d}| j|dgdgdd | j|dgdgdd d S )Nr,   r-   )r   r.   g      @r.   alpha)r   r.   g      @r   r/   r1   r   r   r   r3      s   
z$TestCommonNeighborCentrality.test_K5c                 C   $   t d}| j|dgdgdd d S )Nr5   r6   )r   r7   g      ?r9   rv   r:   r1   r   r   r   r<         
z$TestCommonNeighborCentrality.test_P3c                 C   rx   )Nr=   r>   )r.   r7   g      ?r9   rv   r@   r1   r   r   r   rB      ry   z$TestCommonNeighborCentrality.test_S4
graph_typec                 C   s&   t tj| j|ddgdgsJ d S rD   )r   rF   r#   rG   r%   )r2   rz   r   r   r   rL      s   z0TestCommonNeighborCentrality.test_notimplementedc                 C   rN   rO   rQ   r1   r   r   r   rT      rU   z4TestCommonNeighborCentrality.test_no_common_neighborc                 C   s*   t d}tt j| j|dgg sJ d S )Nr=   rV   )r#   r0   r   rF   NetworkXAlgorithmErrorr&   r1   r   r   r   rX      s   
 z-TestCommonNeighborCentrality.test_equal_nodesc                 C   s0   t  }|g d | j|d g ddd d S )Nr[   ))r   r5         ?)r.   r7   r|   )r.   r5   gUUUUUU?r9   rv   r_   r1   r   r   r   ra      s   z7TestCommonNeighborCentrality.test_all_nonexistent_edgesN)rc   rd   re   rf   r)   r3   r<   rB   r   markparametrizer#   rH   rI   rJ   rL   rT   rX   ra   r   r   r   r   rt      s    

rt   c                   @   rh   )TestPreferentialAttachmentc                 C   r    r!   )r"   r#   preferential_attachmentr%   r   r   r&   r'   r   r   r   r)      r*   z&TestPreferentialAttachment.setup_classc                 C   r+   )Nr,   r-   )r   r.      r/   r1   r   r   r   r3      r4   z"TestPreferentialAttachment.test_K5c                 C   r+   )Nr5   r-   r   r.   r7   r:   r1   r   r   r   r<      r4   z"TestPreferentialAttachment.test_P3c                 C   r+   )Nr=   r6   )r   r7   r=   r@   r1   r   r   r   rB      r4   z"TestPreferentialAttachment.test_S4c                 C   rC   rD   rE   rK   r   r   r   rL      rM   z.TestPreferentialAttachment.test_notimplementedc                 C   rN   rO   rQ   r1   r   r   r   test_zero_degrees   rU   z,TestPreferentialAttachment.test_zero_degreesc                 C   rY   )Nr[   )r   r5   r7   r.   r7   r7   )r.   r5   r.   r_   r1   r   r   r   ra      rU   z5TestPreferentialAttachment.test_all_nonexistent_edgesN)rc   rd   re   rf   r)   r3   r<   rB   rL   r   ra   r   r   r   r   r      s    
r   c                   @   x   e Zd Ze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d ZdS )TestCNSoundarajanHopcroftc                 C   "   t tj| _tt| jdd| _d S N	community)r   r   )r"   r#   cn_soundarajan_hopcroftr%   r   r   r&   r'   r   r   r   r)         z%TestCNSoundarajanHopcroft.setup_classc                 C   f   t d}d|jd d< d|jd d< d|jd d< d|jd d< d|jd d< | |dgd	g d S )
Nr,   r   r   r.   r7   r5   r=   r-   )r   r.   r,   r#   r0   nodesr&   r1   r   r   r   r3        
z!TestCNSoundarajanHopcroft.test_K5c                 C   J   t d}d|jd d< d|jd d< d|jd d< | |dgdg d S )Nr5   r   r   r.   r7   r6   )r   r7   r.   r#   r;   r   r&   r1   r   r   r   r<     
   
z!TestCNSoundarajanHopcroft.test_P3c                 C   f   t d}d|jd d< d|jd d< d|jd d< d|jd d< d|jd d< | |dgdg d S )	Nr=   r.   r   r   r7   r5   r>   r   r#   rA   r   r&   r1   r   r   r   rB     r   z!TestCNSoundarajanHopcroft.test_S4c                 C      t ddg}|jg ddd tt j| j|dgsJ t ddg}|jg ddd tt j| j|dgs:J t ddg}|jg ddd tt j| j|dgsWJ d S Nr-   r>   r   r   r   r6   	r#   rH   rS   r   rF   rG   r%   rI   rJ   r1   r   r   r   rL        z-TestCNSoundarajanHopcroft.test_notimplementedc                 C   H   t  }|ddg d|jd d< d|jd d< | |dgdg d S Nr   r.   r   r-   rP   r#   rR   rS   r   r&   r1   r   r   r   rT   (  
   z1TestCNSoundarajanHopcroft.test_no_common_neighborc                 C   J   t d}d|jd d< d|jd d< d|jd d< | |dgdg d S )Nr5   r   r   r.   r7   rV   )r   r   r=   r   r1   r   r   r   rX   /  r   z*TestCNSoundarajanHopcroft.test_equal_nodesc                 C   d   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | |dgdg d S )	Nr-   r6   r.   r5   r\   r   r   r.   r7   r5   r   r5   r   r#   rR   r`   r   r&   r1   r   r   r   test_different_community6     z2TestCNSoundarajanHopcroft.test_different_communityc                 C   ,   t d}tt jt| |dgsJ d S Nr,   r-   r#   r0   r   rF   r{   listr%   r1   r   r   r   test_no_community_information?     
"z7TestCNSoundarajanHopcroft.test_no_community_informationc                 C   b   t  }|g d d|jd d< d|jd d< d|jd d< tt jt| |dgs/J d S Nr   r   r   r.   r5   r   	r#   rR   r`   r   r   rF   r{   r   r%   r1   r   r   r   'test_insufficient_community_informationC     "zATestCNSoundarajanHopcroft.test_insufficient_community_informationc                 C   d   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | |dgd	g d S )
Nr-   r>   r   )r7   r=   )r5   r=   )r=   r,   r   r.   r   r7   r5   r=   r.   r=   )r.   r=   r=   r   r1   r   r   r   %test_sufficient_community_informationK  r   z?TestCNSoundarajanHopcroft.test_sufficient_community_informationc                 C   h   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | j|dgdgdd	 d S )
Nr   r   cmtyr.   r7   r5   r   r   r   r   r1   r   r   r   $test_custom_community_attribute_nameT     z>TestCNSoundarajanHopcroft.test_custom_community_attribute_namec                 C   d   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | |d g d d S )Nr[   r   r   r.   r7   r5   )r   )r.   r7   r.   r^   r   r1   r   r   r   ra   ]  r   z4TestCNSoundarajanHopcroft.test_all_nonexistent_edgesNrc   rd   re   rf   r)   r3   r<   rB   rL   rT   rX   r   r   r   r   r   ra   r   r   r   r   r          
					r   c                   @   r   )TestRAIndexSoundarajanHopcroftc                 C   r   r   )r"   r#   ra_index_soundarajan_hopcroftr%   r   r   r&   r'   r   r   r   r)   h  r   z*TestRAIndexSoundarajanHopcroft.setup_classc                 C   r   )
Nr,   r   r   r.   r7   r5   r=   r-   )r   r.   r9   r   r1   r   r   r   r3   m  r   z&TestRAIndexSoundarajanHopcroft.test_K5c                 C   r   Nr5   r   r   r.   r7   r6   rl   r   r1   r   r   r   r<   v  r   z&TestRAIndexSoundarajanHopcroft.test_P3c                 C   r   )	Nr=   r.   r   r   r7   r5   r>   r?   r   r1   r   r   r   rB   }  r   z&TestRAIndexSoundarajanHopcroft.test_S4c                 C   r   r   r   r1   r   r   r   rL     r   z2TestRAIndexSoundarajanHopcroft.test_notimplementedc                 C   r   r   r   r1   r   r   r   rT     r   z6TestRAIndexSoundarajanHopcroft.test_no_common_neighborc                 C   r   )Nr5   r   r   r.   r7   rV   rW   r   r1   r   r   r   rX     r   z/TestRAIndexSoundarajanHopcroft.test_equal_nodesc                 C   r   	Nr   r   r   r.   r7   r5   r   r   r5   r   r   r1   r   r   r   r     r   z7TestRAIndexSoundarajanHopcroft.test_different_communityc                 C   r   r   r   r1   r   r   r   r     r   z<TestRAIndexSoundarajanHopcroft.test_no_community_informationc                 C   r   r   r   r1   r   r   r   r     r   zFTestRAIndexSoundarajanHopcroft.test_insufficient_community_informationc                 C   r   )
Nr   r   r.   r   r7   r5   r=   r   )r.   r=   r.   r   r1   r   r   r   r     r   zDTestRAIndexSoundarajanHopcroft.test_sufficient_community_informationc                 C   r   )
Nr   r   r   r.   r7   r5   r   r   r   r   r1   r   r   r   r     r   zCTestRAIndexSoundarajanHopcroft.test_custom_community_attribute_namec                 C   r   )Nr[   r   r   r.   r7   r5   )r]   r.   r7   r   r^   r   r1   r   r   r   ra     r   z9TestRAIndexSoundarajanHopcroft.test_all_nonexistent_edgesNr   r   r   r   r   r   g  r   r   c                   @   s   e Zd Ze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d Zdd Zdd ZdS ) TestWithinInterClusterc                 C   s,   d| _ ttj| _tt| j| j dd| _d S )NgMbP?r   )r   deltar   )r   r"   r#   within_inter_clusterr%   r   r   r&   r'   r   r   r   r)     s
   z"TestWithinInterCluster.setup_classc              	   C   sv   t d}d|jd d< d|jd d< d|jd d< d|jd d< d|jd d< | |dgdddd| j  fg d S )	Nr,   r   r   r.   r7   r5   r=   r-   r#   r0   r   r&   r   r1   r   r   r   r3     s   
&zTestWithinInterCluster.test_K5c                 C   r   r   r   r1   r   r   r   r<     r   zTestWithinInterCluster.test_P3c                 C   sr   t d}d|jd d< d|jd d< d|jd d< d|jd d< d|jd d< | |dgddd| j fg d S )Nr=   r.   r   r   r7   r5   r>   )r#   rA   r   r&   r   r1   r   r   r   rB     s   
"zTestWithinInterCluster.test_S4c                 C   r   r   r   r1   r   r   r   rL     r   z*TestWithinInterCluster.test_notimplementedc                 C   r   r   r   r1   r   r   r   rT     r   z.TestWithinInterCluster.test_no_common_neighborc                 C   sV   t d}d|jd d< d|jd d< d|jd d< | |dgddd| j fg d S )Nr5   r   r   r.   r7   rV   r   r1   r   r   r   rX     s
   
"z'TestWithinInterCluster.test_equal_nodesc                 C   r   r   r   r1   r   r   r   r     r   z/TestWithinInterCluster.test_different_communityc                 C   sd   t d}d|jd d< d|jd d< d|jd d< d|jd d< | |dgddd| j fg d S )Nr=   r   r   r.   r7   r5   r   r   r1   r   r   r   %test_no_inter_cluster_common_neighbor  s   
"z<TestWithinInterCluster.test_no_inter_cluster_common_neighborc                 C   r   r   r   r1   r   r   r   r     r   z4TestWithinInterCluster.test_no_community_informationc                 C   r   r   r   r1   r   r   r   r      r   z>TestWithinInterCluster.test_insufficient_community_informationc                 C   sp   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | |dgddd| j fg d S )	Nr   r   r.   r   r7   r5   r=   r   r#   rR   r`   r   r&   r   r1   r   r   r   r   (  s   "z<TestWithinInterCluster.test_sufficient_community_informationc                 C   sX   t d}|jg ddd tt j| j|dgdsJ tt j| j|dgds*J d S )Nr5   r   r   r   r-   g      )r#   r0   rS   r   rF   r{   r%   r1   r   r   r   test_invalid_delta1  s   
 z)TestWithinInterCluster.test_invalid_deltac                 C   sh   t d}d|jd d< d|jd d< d|jd d< d|jd d< | j|dgddd| j fgdd d S )	Nr=   r   r   r.   r7   r5   r   r   r   r1   r   r   r   r   7  s   
&z;TestWithinInterCluster.test_custom_community_attribute_namec                 C   sr   t  }|g d d|jd d< d|jd d< d|jd d< d|jd d< | |d ddd| j fddg d S )	Nr[   r   r   r.   r7   r5   r   r^   r   r1   r   r   r   ra   ?  s   $z1TestWithinInterCluster.test_all_nonexistent_edgesN)rc   rd   re   rf   r)   r3   r<   rB   rL   rT   rX   r   r   r   r   r   r   r   ra   r   r   r   r   r     s"    
				r   )rq   	functoolsr   r   networkxr#   r   r   ri   rn   rt   r   r   r   r   r   r   r   r   <module>   s    
2/4(.ii