
    fi\%                     T    d Z ddlZddlZddlmc mZ ej        Z	 G d d          Z
dS )z#
Threshold Graphs
================
    Nc                   z    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d Zd Zd Zd ZdS )TestGeneratorThresholdc                 H   t          j        d          }t          j        |          sJ t          j        d |                                D                       sJ t          j        d          }t          j        |          sJ t          j        d |                                D                       sJ g d}t          j        |          rJ g d}t          j        |          sJ t           j                            |          }t          j        |          sJ d S )N
   c                     g | ]\  }}|S  r   .0nds      /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/networkx/algorithms/tests/test_threshold.py
<listcomp>zMTestGeneratorThreshold.test_threshold_sequence_graph_test.<locals>.<listcomp>       )C)C)C1!)C)C)C    c                     g | ]\  }}|S r   r   r	   s      r   r   zMTestGeneratorThreshold.test_threshold_sequence_graph_test.<locals>.<listcomp>   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degs      r   "test_threshold_sequence_graph_testz9TestGeneratorThreshold.test_threshold_sequence_graph_test   s   M"%a(((((()C)C

)C)C)CDDDDDb!!%a(((((()C)C

)C)C)CDDDDD   ,S11111ll(-----M,,S11%a(((((((r   c                    g d}t           j                            |          }t          j        t
                    5  t          j        |dd           d d d            n# 1 swxY w Y   t          j        |          }t          j        |          }d	                    |          dk    sJ t          j        |d          }t          j        |          }|g dk    sJ t          j        |d          }t          j        |          }|g d	k    sJ d	                    t          j
        |                    dk    sJ t          j        ||          sJ t          j        ||          sJ t          j        ||          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	uncompactcould_be_isomorphic)	r   r!   r    cs0H0cs1H1cs2H2s	            r   test_creation_sequencesz.TestGeneratorThreshold.test_creation_sequences!   s   llM,,S11]:&& 	G 	G!#4FFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G #C(( %%wws||v%%%%#CT::: %%>>>>>>>#C666 %%iiiwws}S))**f4444%b!,,,,,%b"-----%b"-------s   A!!A%(A%c                     t          j        g d          g dk    sJ t          j        g d          g dk    sJ t          j        t          t           j        g d           d S )Nr   r   r   r-   r   r   r   r   r   g      @      ?g       @)r   make_compactr0   r1   	TypeErrorr   s    r   test_make_compactz(TestGeneratorThreshold.test_make_compact8   sn     > > >??999LLLL			**iii7777i!1???CCCCCr   c                 P   t          j        g d          g dk    sJ t          j        g d          g dk    sJ t          j        t          j        g d                    t          j        g d          k    sJ t          j        t          t           j        g d           d S )NrA   r@   )r   r   r-   r   r*   rB   )r   r6   r0   r1   rE   rF   s    r   test_uncompactz%TestGeneratorThreshold.test_uncompact=   s    }YYY''+I+I+IIIII}111226J6J6JJJJJ}MBBBCC
 
]CCCDDE E E E 	i@@@@@r   c                     t          j        g d          g dk    sJ t          j        t          t           j        g d           d S )NrA   )      ?rK   rK   g      ?      ?rL   rB   )r   creation_sequence_to_weightsr0   r1   rE   rF   s    r   !test_creation_sequence_to_weightsz8TestGeneratorThreshold.test_creation_sequence_to_weightsE   sZ    /			:: ?
 ?
 ?
 
 
 
 
 	i!A???SSSSSr   c                    g d}t          j        t                    5  t          j        |dd           d d d            n# 1 swxY w Y   t          j        |d          g dk    sJ t          j        |d          dgk    sJ d S )Nr   Tr$   r)   ))r   r   r+   r,   r.   r/      )r0   r1   r2   r   weights_to_creation_sequence)r   r!   s     r   !test_weights_to_creation_sequencez8TestGeneratorThreshold.test_weights_to_creation_sequenceP   s    ll]:&& 	R 	R,SdDQQQQ	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R/FFF K
 K
 K
 
 
 
 
 /TBBBqcIIIIIIs   AA	Ac                     t          j                    }|                    dd           t          j        |          rJ d S )Nr   r   )r   Graphadd_edger   find_alternating_4_cycle)r   r    s     r   test_find_alternating_4_cyclez4TestGeneratorThreshold.test_find_alternating_4_cycle\   s>    HJJ	

1a/2222222r   c                    g d}t           j                            |          }t          j        |d          }dD ]5\  }}t          j        |||          t          j        |||          k    sJ 6t          j        |d          }t          j        d |D             d          }||k    sJ i }t          |          D ]\  }	}
||	         d         }|
||<   |t          j        |d          k    sJ t          j        g d	d
d          d
dgk    sJ t          j        g dd
d          d
dgk    sJ t          j
        t          t          j        g dd
d           t          j
        t          t          j        g ddd           t          j
        t          t          j        g dd
d           t          j        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                     g | ]\  }}|S r   r   )r
   vts      r   r   z=TestGeneratorThreshold.test_shortest_path.<locals>.<listcomp>i   s    (;(;(;tq!(;(;(;r   r   r   r@   r   rA   rB   ab)r   r   r   r   r3   shortest_pathshortest_path_length	enumerate"single_source_shortest_path_lengthr0   r1   rE   r2   )r   r!   r    r:   r   msplspl2spldjpls              r   test_shortest_pathz)TestGeneratorThreshold.test_shortest_patha   s   llM,,S11#CT:::T 	M 	MDAq$S!Q//23CAq!3L3LLLLLL&sA..'(;(;s(;(;(;Q??d{{{{s^^ 	 	EArAq	ADGGr<QBBBBBB !?!?!?AFF1a&PPPP Aq11aV;;;;i!2OOOQJJJj#"3YYYQGGGj#"3YYY3GGG Aq11aS888888r   c                    t          j        g dd          g dk    sJ t          j        g dd          g dk    sJ t          j        dd          g dk    sJ t          j        t          t           j        g dd           d S )NrA   r   )r   r   r   r   r   r   r@   rB   )r   r_   r0   r1   rE   r^   rF   s    r   test_shortest_path_lengthz0TestGeneratorThreshold.test_shortest_path_lengthy   s    '			1559K9K9KKKKK'(F(F(FJJ O
 O
 O
 
 
 
 
 '(FJJ O
 O
 O
 
 
 
 
 	i!2OOOQGGGGGr   c                     t          t          j        dd                    dk    sJ t          j        ddd          g dk    sJ t          j        t
          t          j        dd           d S )Nr   rK   *   seed)
r   r-   r   r   r   r-   r-   r-   r   r   g      ?)lenr   random_threshold_sequencer0   r1   r2   rF   s    r   test_random_threshold_sequencez5TestGeneratorThreshold.test_random_threshold_sequence   s    30S99::b@@@@,R2>>> C
 C
 C
 
 
 
 
 	j#"?SIIIIIr   c                     t          j        dd          g dk    sJ t          j        t          t           j        dd           d S Nr   r   )r   r-   r   )r   right_d_threshold_sequencer0   r1   r2   rF   s    r   test_right_d_threshold_sequencez6TestGeneratorThreshold.test_right_d_threshold_sequence   sC    -a33FFFFj#"@!QGGGGGr   c                     t          j        dd          g dk    sJ t          j        t          t           j        dd           d S rs   )r   left_d_threshold_sequencer0   r1   r2   rF   s    r   test_left_d_threshold_sequencez5TestGeneratorThreshold.test_left_d_threshold_sequence   sC    ,Q22oooEEEEj#"?AFFFFFr   c                    g d}t          j        |d          }t          j        |          }t          j        |          }||k    sJ t          j        t          j        g d                    }|d dD             k    sJ t          j        g d          }|d dD             k    sJ t          j        t	          t          d                              }|d	 d
D             k    sJ t          j        d          }|d d
D             k    sJ t          j        d          }d dD             }t          d t          ||          D                       dk     sJ d S )N)
r   rP   r   r         rz   rP   rz   r{   r   )	threshold)r   r   r   r   r   r   r   c                     g | ]}|d z  S g      ?r   r
   ss     r   r   zBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>   )     
 
 
AI
 
 
r   )rP   rP   rP   r   rz   rz   r   r   r   r{   r{   r{   r   r      r   r   c                     g | ]}|d z  S r~   r   r   s     r   r   zBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>   r   r   ddidiiidididic                     g | ]}|d z  S g?r   r   s     r   r   zBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>       QQQACQQQr   )rz   rz   rP   r{   r   r   r   r   r      r   	   r   c                     g | ]}|d z  S r   r   r   s     r   r   zBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>   r   r   ddidiiididididc                     g | ]}|d z  S )   r   r   s     r   r   zBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>   s    KKKa"fKKKr   )r{   r{   rz   r   rP   rP   rP   r   r   r   r   r   r      c              3   @   K   | ]\  }}t          ||z
            V  d S Nabsr
   cr   s      r   	<genexpr>zATestGeneratorThreshold.test_weights_thresholds.<locals>.<genexpr>   s0      88$!Q3q1u::888888r   g+=)r   rQ   rM   r6   listr`   sumzip)r   wseqcsr<   wss        r   test_weights_thresholdsz.TestGeneratorThreshold.test_weights_thresholds   s   ----dbAAA/33.t44Syyyy/>S>S>S0T0TUU 
 
R
 
 
 
 
 
 
 /0E0E0EFF 
 
R
 
 
 
 
 
 
 /Y5O5O0P0PQQQQ)PQQQQQQQ/@@QQ)PQQQQQQQ/0@AAKKJKKK88#dB--888885@@@@@@r   c                    t          j        dgdgdgdgdgd          }|                    dd           |                    dd           |                    dd           |                    dd           |                    dd           t          j        |          g dk    sJ t          j        |          }t          j        |          sJ t          |                                          g d	k    sJ t          j	        t          |                                          d
          }t          j        |          |k    sJ d S )Nr   r   rP   rz   r{   )r   r   r   rP   rz   r   )r   r   r   r{   )r   r   r   rP   rz   r   Tr)   )r   rT   rU   r   rV   find_threshold_graphr   sortednodesr3   dictr   find_creation_sequence)r   r    TGr   s       r   test_finding_routinesz,TestGeneratorThreshold.test_finding_routines   sG   H!!!!!==>>	

1a	

1a	

1a	

1a	

1a +A..,,,>>>> %a((%b)))))bhhjj!!%7%7%77777"4		#4#4$GGG)!,,222222r   c                    d}t          j        |          }t          j        d          t          j        |          k    sJ t	          t          j        |                    t	          d |                                D                       k    sJ t          j        |          }|t          t          j	        |          
                                          k    sJ t          |          dz  t          j	        |          k    sJ t          j        |          }t          t          j        |          
                                          }t          d t          ||          D                       t          j        dd          k    sJ t          j        |          
                                }t          j        |          }t          d t          ||          D                       dk     sJ t          j        |          g d	k    sJ t)          t          j        |          d
z             dk     sJ t          j        d          dk    sJ t          j        d          dk    sJ t          j        d          dk    sJ t          j        d          g dk    sJ t          j        d          g dk    sJ d S )Nddiiddidc              3       K   | ]	\  }}|V  
d S r   r   r	   s      r   r   zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>   s&      8R8Rtq!8R8R8R8R8R8Rr   r   c              3   @   K   | ]\  }}t          ||z
            V  d S r   r   r   s      r   r   zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>   0      66$!Q3q1u::666666r   r   gHz>r   c              3   @   K   | ]\  }}t          ||z
            V  d S r   r   r   s      r   r   zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>   r   r   )r   r   r   r   rz   r   r   r   g!1,?g-q=diiiddigdidg      dddrC   dddiii)r   r   r   r   r   r   dddiiid)r   r   r   r   rP   rP   r   )r   r4   densityr   r   degree_sequencer   triangle_sequencer   	trianglesvaluesr   cluster_sequence
clusteringr   r0   approxbetweenness_centralitybetweenness_sequenceeigenvaluesr   degree_correlation)r   r   r    tsc1c2b1b2s           r   .test_fast_versions_properties_threshold_graphszETestGeneratorThreshold.test_fast_versions_properties_threshold_graphs   s   ##{:&&"*Q--7777c)"--..&8R8Rqxxzz8R8R8R2R2RRRRR"2&&T",q//00223333332ww!|s}R000000!"%%"-""))++,,66#b"++66666&-t:T:T:TTTTT&q))0022%b))66#b"++66666====r""&>&>&>>>>> 3)"-->??%GGGG%i00D8888%e,,4444%e,,3333x((,>,>,>>>>>y))-B-B-BBBBBBBr   c                     t          j        dd          }t          j        dd          }t          j        |dd          }t          j        |ddd          }d S )Nrz   r   rC   r   rm   )r   rw   rt   swap_d)r   r   s1s      r   test_tg_creation_routinesz0TestGeneratorThreshold.test_tg_creation_routines   sU    )!Q//*1a00Z3$$Z3!,,,r   c                 D   t          j        d          j        j        }t          j        d           d}t	          j        |          }t	          j        |          \  }}j                            fd|D             dd           t          j
        |          }d S )Nnumpyscipyr   c                 <    g | ]}                     ||          S r   )dot)r
   lvnps     r   r   z<TestGeneratorThreshold.test_eigenvectors.<locals>.<listcomp>   s%    #D#D#DrBFF2rNN#D#D#Dr   rC   g&.>)rtol)r0   importorskiplinalgeigvalsr   r4   eigenvectorstestingassert_allcloser   laplacian_matrix)r   eigenvalr   r    tgevaltgeveclaplr   s          @r   test_eigenvectorsz(TestGeneratorThreshold.test_eigenvectors   s     ))9$G$$$##+B//

""#D#D#D#DV#D#D#DcPT"UUU"1%%r   c                    d}t          j        |          }t          j        t          j        j        t           j        |t	          j                               t          j        |t	          j                              }t          |
                                          t          |
                                          k    sJ d S )Nr   )create_using)r   r4   r0   r1   r   	exceptionNetworkXErrorDiGraph
MultiGraphr   edges)r   r   r    MGs       r   test_create_usingz(TestGeneratorThreshold.test_create_using   s    ##L&		
 	
 	
 	
  "-//BBBbhhjj!!VAGGII%6%6666666r   N)__name__
__module____qualname__r"   r>   rG   rI   rN   rR   rW   rh   rj   rq   ru   rx   r   r   r   r   r   r   r   r   r   r   r      s@       ) ) )$. . ..D D D
A A A	T 	T 	T
J 
J 
J3 3 3
9 9 90H H H(J J J H H HG G GA A A63 3 3&C C C8- - -	& 	& 	&
7 
7 
7 
7 
7r   r   )__doc__r0   networkxr   networkx.algorithms.threshold
algorithmsr|   r   convert_node_labels_to_integerscnltir   r   r   r   <module>r      s    
      + + + + + + + + +
*|7 |7 |7 |7 |7 |7 |7 |7 |7 |7r   