o
    ]ZŽ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   úW/var/www/auris/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   )	ÚnxZ
star_graphÚnxtÚis_threshold_graphZis_threshold_sequenceÚdegreeZ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Ú Z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   Zcs0ZH0Úcs1ZH1Úcs2Z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   Z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 )Nr2   r1   )r
   r
   r$   r
   r!   r3   )r   r-   r'   r(   r5   r6   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 )Nr2   )ç      à?r9   r9   g      Ð?ç      è?r:   r3   )r   Úcreation_sequence_to_weightsr'   r(   r5   r6   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   r1   r   r2   r3   ÚaÚb)r   r   r   r   r*   Úshortest_pathÚshortest_path_lengthÚ	enumerateZ"single_source_shortest_path_lengthr'   r(   r5   r)   )r   r   r   r.   r	   ÚmZsplZspl2Z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 )Nr2   r   )r   r   r   r   r   r   r1   r3   )r   rI   r'   r(   r5   rH   r6   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   r9   é*   ©Úseed)
r
   r$   r
   r
   r
   r$   r$   r$   r
   r
   g      ø?)Úlenr   Zrandom_threshold_sequencer'   r(   r)   r6   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)   r6   r   r   r   Útest_right_d_threshold_sequence    ó   z6TestGeneratorThreshold.test_right_d_threshold_sequencec                 C   rU   rV   )r   Úleft_d_threshold_sequencer'   r(   r)   r6   r   r   r   Útest_left_d_threshold_sequence¤   rY   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   r=   r   r   é   é   r\   r=   r\   r]   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>)r=   r=   r=   r   r\   r\   r   r   r   r]   r]   r]   r   r   é   rd   rd   c                 S   r_   r`   r   ra   r   r   r   r   µ   rc   Zddidiiidididic                 S   r_   ©gš™™™™™¹?r   ra   r   r   r   r   º   r   )r\   r\   r=   r]   r   r   r   rd   r   é   r   é	   r   c                 S   r_   re   r   ra   r   r   r   r   ½   r   Zddidiiididididc                 S   s   g | ]}|d  ‘qS )é   r   ra   r   r   r   r   À   r   )r]   r]   r\   rd   r=   r=   r=   rf   r   rg   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   r>   r;   r-   ÚlistrJ   ÚsumÚzip)r   ZwseqÚcsr/   Ú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   r=   r\   r]   )r   r   r   r=   r\   rd   )r   r   r   r]   )r   r   r   r=   r\   rd   Tr    )r   r@   rA   r   rB   Zfind_threshold_graphr   ÚsortedÚnodesr*   Údictr   Zfind_creation_sequence)r   r   ZTGru   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 rk   r   r   r   r   r   rp   Ú   s   € zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>r   c                 s   rj   rk   rl   rn   r   r   r   rp   â   rq   r   gH¯¼šò×z>rl   c                 s   rj   rk   rl   rn   r   r   r   rp   æ   rq   )r   r   r   r   r\   rd   rd   rf   g! 1,úâ?gê-™—q=Zdiiiddigš™™™™™é¿Zdidg      ð¿Zdddr4   Zdddiii)r   r   r   r   r   r   Zdddiiid)r   r   r   r   r=   r=   rd   )r   r+   Zdensityr   rx   Zdegree_sequencer   Ztriangle_sequencerr   Z	trianglesÚvaluesrs   Zcluster_sequenceZ
clusteringrt   r'   ZapproxZbetweenness_centralityZbetweenness_sequenceZeigenvaluesrm   Zdegree_correlation)r   ru   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 )Nr\   rd   r4   r   rQ   )r   rZ   rW   Zswap_d)r   rb   Ú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ÚnumpyZscipyr|   c                    s   g | ]}ˆ   ||¡‘qS r   )Údot)r   Úlv©Únpr   r   r      s    z<TestGeneratorThreshold.test_eigenvectors.<locals>.<listcomp>r4   g•Ö&è.>)Zrtol)r'   ZimportorskipZlinalgZeigvalsr   r+   ZeigenvectorsÚtestingZassert_allcloser   Zlaplacian_matrix)r   Zeigenvalru   r   ZtgevalZtgevecZ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|   )Zcreate_using)r   r+   r'   r(   r   Ú	exceptionZNetworkXErrorZDiGraphZ
MultiGraphrx   Úedges)r   ru   r   ZMGr   r   r   Útest_create_using  s   

ü z(TestGeneratorThreshold.test_create_usingN)Ú__name__Ú
__module__Ú__qualname__r   r0   r7   r8   r<   r?   rC   rN   rO   rT   rX   r[   rw   r{   rƒ   r…   rŒ   r   r   r   r   r   r      s&    r   )Ú__doc__r'   Znetworkxr   Znetworkx.algorithms.thresholdZ
algorithmsr^   r   Z(networkx.algorithms.isomorphism.isomorphr   Zconvert_node_labels_to_integersZcnltir   r   r   r   r   Ú<module>   s    