o
    ִi&                     @   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   [/home/kuhnn/.local/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||sJ 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sJ t	
ttjg dddsJ t	
ttjg dddsJ tg ddddgksJ 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 sJ 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 sJ t |g d
ksJ tt |d dk sJ t ddksJ t ddksJ t ddksJ t dg dksJ t dg dksJ 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   gHz>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    