o
    ñh&  ã                   @   sJ   d Z ddlZddlZddlm  mZ ddlm	Z	 ej
ZG dd„ dƒZdS )z#
Threshold Graphs
================
é    N)Úgraph_could_be_isomorphicc                   @   sœ   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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 )&ÚTestGeneratorThresholdc                 C   s²   t  d¡}t |¡sJ ‚t dd„ | ¡ D ƒ¡sJ ‚t  d¡}t |¡s&J ‚t dd„ | ¡ D ƒ¡s4J ‚g d¢}t |¡r?J ‚g d¢}t |¡sJJ ‚t j |¡}t |¡sWJ ‚d S )Né
   c                 S   ó   g | ]\}}|‘qS © r   ©Ú.0ÚnÚdr   r   ú\/var/www/vscode/kcb/lib/python3.10/site-packages/networkx/algorithms/tests/test_threshold.pyÚ
<listcomp>   ó    zMTestGeneratorThreshold.test_threshold_sequence_graph_test.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r      r   )é   é   r   é   r   r   ©r   r   r   r   )	ÚnxÚ
star_graphÚnxtÚis_threshold_graphÚis_threshold_sequenceÚdegreeÚcomplete_graphÚ
generatorsÚhavel_hakimi_graph)ÚselfÚGÚdegr   r   r   Ú"test_threshold_sequence_graph_test   s   

z9TestGeneratorThreshold.test_threshold_sequence_graph_testc           	      C   s
  g d¢}t j |¡}t t¡ tj|ddd W d   ƒ n1 s"w   Y  t |¡}t |¡}d 	|¡dks:J ‚tj|dd}t |¡}|g d¢ksNJ ‚tj|dd}t |¡}|g d	¢ksbJ ‚d 	t 
|¡¡dksnJ ‚t||ƒsuJ ‚t||ƒs|J ‚t||ƒsƒJ ‚d S )
Nr   T©Úwith_labelsÚcompactÚ Úddid©r    ©©r   r
   ©r   r
   )r   Úi©r   r
   ©r!   )r   r   r   )r   r   r   ÚpytestÚraisesÚ
ValueErrorr   Úcreation_sequenceÚthreshold_graphÚjoinÚ	uncompactr   )	r   r   r   Úcs0ÚH0Úcs1ÚH1Úcs2ÚH2r   r   r   Útest_creation_sequences"   s$   ÿ



z.TestGeneratorThreshold.test_creation_sequencesc                 C   sP   t  g d¢¡g d¢ksJ ‚t  g d¢¡g d¢ksJ ‚t tt jg d¢¡s&J ‚d S )N©r
   r
   r
   r(   r
   r
   ©r   r   r   ©g      @ç      ð?g       @)r   Úmake_compactr+   r,   Ú	TypeError©r   r   r   r   Útest_make_compact9   s   z(TestGeneratorThreshold.test_make_compactc                 C   sv   t  g d¢¡g d¢ksJ ‚t  g d¢¡g d¢ksJ ‚t  t  g d¢¡¡t  g d¢¡ks-J ‚t tt jg d¢¡s9J ‚d S )Nr:   r9   )r
   r
   r(   r
   r%   r;   )r   r1   r+   r,   r>   r?   r   r   r   Útest_uncompact>   s   ÿþz%TestGeneratorThreshold.test_uncompactc                 C   s6   t  g d¢¡g d¢ksJ ‚t tt jg d¢¡sJ ‚d S )Nr:   )ç      à?rB   rB   g      Ð?ç      è?rC   r;   )r   Úcreation_sequence_to_weightsr+   r,   r>   r?   r   r   r   Ú!test_creation_sequence_to_weightsF   s   ÿz8TestGeneratorThreshold.test_creation_sequence_to_weightsc                 C   sx   g d¢}t  t¡ tj|ddd W d   ƒ n1 sw   Y  tj|ddg d¢ks.J ‚tj|dddgks:J ‚d S )Nr   Tr   r$   ))r   r
   r&   r'   r)   r*   é   )r+   r,   r-   r   Úweights_to_creation_sequence)r   r   r   r   r   Ú!test_weights_to_creation_sequenceS   s   ÿz8TestGeneratorThreshold.test_weights_to_creation_sequencec                 C   s&   t  ¡ }| dd¡ t |¡rJ ‚d S )Nr   r   )r   ÚGraphÚadd_edger   Úfind_alternating_4_cycle)r   r   r   r   r   Útest_find_alternating_4_cycle_   s   z4TestGeneratorThreshold.test_find_alternating_4_cyclec                 C   sl  g d¢}t j |¡}tj|dd}dD ]\}}t |||¡t  |||¡ks'J ‚qt |d¡}t dd„ |D ƒd¡}||ks?J ‚i }t|ƒD ]\}	}
||	 d	 }|
||< qE|t  |d¡ks^J ‚t g d
¢dd¡ddgksmJ ‚t g d¢dd¡ddgks|J ‚t	 
ttjg d¢dd¡sŠJ ‚t	 
ttjg d¢dd¡s˜J ‚t	 
ttjg d¢dd¡s¦J ‚t g d¢dd¡dgks´J ‚d S )Nr   Tr$   ))r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   c                 S   r   r   r   )r   ÚvÚtr   r   r   r   l   r   z=TestGeneratorThreshold.test_shortest_path.<locals>.<listcomp>r   r   r9   r   r:   r;   ÚaÚb)r   r   r   r   r.   Úshortest_pathÚshortest_path_lengthÚ	enumerateÚ"single_source_shortest_path_lengthr+   r,   r>   r-   )r   r   r   r4   r	   ÚmÚsplÚspl2ÚspldÚjÚplr   r   r   Útest_shortest_pathd   s&   "
 z)TestGeneratorThreshold.test_shortest_pathc                 C   sn   t  g d¢d¡g d¢ksJ ‚t  g d¢d¡g d¢ksJ ‚t  dd¡g d¢ks(J ‚t tt jg d¢d¡s5J ‚d S )Nr:   r   )r   r   r   r   r   r   r9   r;   )r   rR   r+   r,   r>   rQ   r?   r   r   r   Útest_shortest_path_length|   s   z0TestGeneratorThreshold.test_shortest_path_lengthc                 C   sN   t t dd¡ƒdksJ ‚tjddddg d¢ksJ ‚t ttjdd¡s%J ‚d S )Nr   rB   é*   ©Úseed)
r
   r(   r
   r
   r
   r(   r(   r(   r
   r
   g      ø?)Úlenr   Úrandom_threshold_sequencer+   r,   r-   r?   r   r   r   Útest_random_threshold_sequence   s   z5TestGeneratorThreshold.test_random_threshold_sequencec                 C   ó2   t  dd¡g d¢ksJ ‚t tt jdd¡sJ ‚d S ©Nr   r   )r
   r(   r
   )r   Úright_d_threshold_sequencer+   r,   r-   r?   r   r   r   Útest_right_d_threshold_sequence    ó   z6TestGeneratorThreshold.test_right_d_threshold_sequencec                 C   rc   rd   )r   Úleft_d_threshold_sequencer+   r,   r-   r?   r   r   r   Útest_left_d_threshold_sequence¤   rg   z5TestGeneratorThreshold.test_left_d_threshold_sequencec                 C   s  g d¢}t j|dd}t  |¡}t  |¡}||ksJ ‚t  t  g d¢¡¡}|dd„ dD ƒks0J ‚t  g d¢¡}|dd„ dD ƒksBJ ‚t  ttd	ƒƒ¡}|d
d„ dD ƒksVJ ‚t  d	¡}|dd„ dD ƒksfJ ‚t  d¡}dd„ dD ƒ}tdd„ t||ƒD ƒƒdk s‚J ‚d S )N)
r   rF   r   r   é   é   rj   rF   rj   rk   r   )Ú	threshold)r   r   r   r   r   r   r   c                 S   ó   g | ]}|d  ‘qS ©g      À?r   ©r   Úsr   r   r   r   °   ó    ÿzBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>)rF   rF   rF   r   rj   rj   r   r   r   rk   rk   rk   r   r   é   rr   rr   c                 S   rm   rn   r   ro   r   r   r   r   µ   rq   Úddidiiidididic                 S   rm   ©gš™™™™™¹?r   ro   r   r   r   r   º   r   )rj   rj   rF   rk   r   r   r   rr   r   é   r   é	   r   c                 S   rm   rt   r   ro   r   r   r   r   ½   r   Úddidiiididididc                 S   s   g | ]}|d  ‘qS )é   r   ro   r   r   r   r   À   r   )rk   rk   rj   rr   rF   rF   rF   ru   r   rv   r   r   r   é   c                 s   ó     | ]\}}t || ƒV  qd S ©N©Úabs©r   Úcr
   r   r   r   Ú	<genexpr>Á   ó   € zATestGeneratorThreshold.test_weights_thresholds.<locals>.<genexpr>g›+¡†›„=)r   rG   rD   r1   ÚlistrS   ÚsumÚzip)r   ÚwseqÚcsr6   Úwsr   r   r   Útest_weights_thresholds¨   s(   

ÿÿ

$z.TestGeneratorThreshold.test_weights_thresholdsc                 C   sÎ   t  dgdgdgdgdgdœ¡}| dd¡ | dd¡ | dd¡ | dd¡ | dd¡ t |¡g d¢ks9J ‚t |¡}t |¡sEJ ‚t| ¡ ƒg d	¢ksQJ ‚tj	t
| ¡ ƒd
d}t |¡|kseJ ‚d S )Nr   r   rF   rj   rk   )r   r   r   rF   rj   rr   )r   r   r   rk   )r   r   r   rF   rj   rr   Tr$   )r   rI   rJ   r   rK   Úfind_threshold_graphr   ÚsortedÚnodesr.   Údictr   Úfind_creation_sequence)r   r   ÚTGr†   r   r   r   Útest_finding_routinesÃ   s    
z,TestGeneratorThreshold.test_finding_routinesc                 C   s   d}t  |¡}t  d¡t |¡ksJ ‚tt  |¡ƒtdd„ | ¡ D ƒƒks'J ‚t  |¡}|tt 	|¡ 
¡ ƒks9J ‚t|ƒd t  	|¡ksFJ ‚t  |¡}tt |¡ 
¡ ƒ}tdd„ t||ƒD ƒƒtjdddksiJ ‚t |¡ 
¡ }t  |¡}td	d„ t||ƒD ƒƒdk s…J ‚t  |¡g d
¢ksJ ‚tt  |¡d ƒdk sJ ‚t  d¡dks¦J ‚t  d¡dks¯J ‚t  d¡dks¸J ‚t  d¡g d¢ksÃJ ‚t  d¡g d¢ksÎJ ‚d S )NÚddiiddidc                 s   s    | ]\}}|V  qd S r{   r   r   r   r   r   r€   Ú   s   € zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>r   c                 s   rz   r{   r|   r~   r   r   r   r€   â   r   r   gH¯¼šò×z>r|   c                 s   rz   r{   r|   r~   r   r   r   r€   æ   r   )r   r   r   r   rj   rr   rr   ru   g! 1,úâ?gê-™—q=Údiiiddigš™™™™™é¿Údidg      ð¿Údddr<   Údddiii)r   r   r   r   r   r   Údddiiid)r   r   r   r   rF   rF   rr   )r   r/   Údensityr   rŠ   Údegree_sequencer   Útriangle_sequencer‚   Ú	trianglesÚvaluesrƒ   Úcluster_sequenceÚ
clusteringr„   r+   ÚapproxÚbetweenness_centralityÚbetweenness_sequenceÚeigenvaluesr}   Údegree_correlation)r   r†   r   ÚtsÚc1Úc2Úb1Úb2r   r   r   Ú.test_fast_versions_properties_threshold_graphsÖ   s(   
(

*
 zETestGeneratorThreshold.test_fast_versions_properties_threshold_graphsc                 C   s<   t  dd¡}t  dd¡}t  |dd¡}t j|dddd}d S )Nrj   rr   r<   r   r^   )r   rh   re   Úswap_d)r   rp   Ús1r   r   r   Útest_tg_creation_routinesò   s   z0TestGeneratorThreshold.test_tg_creation_routinesc                    sf   t  d¡‰ ˆ jj}t  d¡ d}t |¡}t |¡\}}ˆ jj‡ fdd„|D ƒddd t	 
|¡}d S )	NÚnumpyÚscipyr   c                    s   g | ]}ˆ   ||¡‘qS r   )Údot)r   Úlv©Únpr   r   r      s    z<TestGeneratorThreshold.test_eigenvectors.<locals>.<listcomp>r<   g•Ö&è.>)Úrtol)r+   ÚimportorskipÚlinalgÚeigvalsr   r/   ÚeigenvectorsÚtestingÚassert_allcloser   Úlaplacian_matrix)r   Úeigenvalr†   r   ÚtgevalÚtgevecÚlaplr   r¯   r   Útest_eigenvectorsø   s   


 z(TestGeneratorThreshold.test_eigenvectorsc                 C   s`   d}t  |¡}tjtjjt j|t ¡ dsJ ‚t j|t ¡ d}t	| 
¡ ƒt	| 
¡ ƒks.J ‚d S )Nr   )Úcreate_using)r   r/   r+   r,   r   Ú	exceptionÚNetworkXErrorÚDiGraphÚ
MultiGraphrŠ   Úedges)r   r†   r   ÚMGr   r   r   Útest_create_using  s   

ü z(TestGeneratorThreshold.test_create_usingN)Ú__name__Ú
__module__Ú__qualname__r   r8   r@   rA   rE   rH   rL   r[   r\   rb   rf   ri   rˆ   r   r§   rª   r½   rÅ   r   r   r   r   r      s&    r   )Ú__doc__r+   Únetworkxr   Únetworkx.algorithms.thresholdÚ
algorithmsrl   r   Ú(networkx.algorithms.isomorphism.isomorphr   Úconvert_node_labels_to_integersÚcnltir   r   r   r   r   Ú<module>   s    