
    9 j&                     \    S r SSKrSSKrSSKJs  Jr  \R                  r	S r
 " S S5      rg)z#
Threshold Graphs
================
    Nc                      / SQn [         R                  " [        SS9   [        R                  " U 5        S S S 5        g ! , (       d  f       g = f)N)       @      r   znot a valid creation sequence)match)pytestraises
ValueErrornxtthreshold_graph)bad_creation_sequences    y/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/networkx/algorithms/tests/test_threshold.py.test_threshold_graph_invalid_creation_sequencer      s3    *	z)H	I12 
J	I	Is	   >
Ac                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rSrg)TestGeneratorThreshold   c                    [         R                  " S5      n[        R                  " U5      (       d   e[        R                  " UR                  5        VVs/ s H  u  p#UPM	     snn5      (       d   e[         R                  " S5      n[        R                  " U5      (       d   e[        R                  " UR                  5        VVs/ s H  u  p#UPM	     snn5      (       d   e/ SQn[        R                  " U5      (       a   e/ SQn[        R                  " U5      (       d   e[         R                  R                  U5      n[        R                  " U5      (       d   eg s  snnf s  snnf )N
   )   r   r   r   r   r   r   r   r   r   )	nx
star_graphr   is_threshold_graphis_threshold_sequencedegreecomplete_graph
generatorshavel_hakimi_graph)selfGnddegs        r   "test_threshold_sequence_graph_test9TestGeneratorThreshold.test_threshold_sequence_graph_test   s   MM"%%a((((((
)C
!
)CDDDDb!%%a((((((
)C
!
)CDDDD ,,S1111((----MM,,S1%%a(((( *D *Ds   E&

E,
c                 >   / SQn[         R                  R                  U5      n[        R                  " [
        5         [        R                  " USSS9  S S S 5        [        R                  " U5      n[        R                  " U5      nSR                  U5      S:X  d   e[        R                  " USS9n[        R                  " U5      nU/ SQ:X  d   e[        R                  " USS9n[        R                  " U5      nU/ S	Q:X  d   eSR                  [        R                  " U5      5      S:X  d   e[         R                  " XB5      (       d   e[         R                  " XF5      (       d   e[         R                  " XH5      (       d   eg ! , (       d  f       GN?= f)
Nr   Twith_labelscompact ddidr(   r   r"   r   r"   )r   ir   r"   r)   )r   r   r   )r   r   r   r   r	   r
   r   creation_sequencer   join	uncompactcould_be_isomorphic)	r   r#   r    cs0H0cs1H1cs2H2s	            r   test_creation_sequences.TestGeneratorThreshold.test_creation_sequences'   sE   MM,,S1]]:&!!#4F ' ##C(  %wws|v%%%##CT:  %>>>>##C6  %iwws}}S)*f444%%b,,,,%%b----%%b----# '&s   F
Fc                     [         R                  " / SQ5      / SQ:X  d   e[         R                  " / SQ5      / SQ:X  d   e[        R                  " [        [         R                  / SQ5        g )Nr"   r"   r"   r0   r"   r"   r   r   r   g      @      ?r   )r   make_compactr   r	   	TypeErrorr   s    r   test_make_compact(TestGeneratorThreshold.test_make_compact>   sK     >?9LLL	*i777i!1!1?C    c                 l   [         R                  " / SQ5      / SQ:X  d   e[         R                  " / SQ5      / SQ:X  d   e[         R                  " [         R                  " / SQ5      5      [         R                  " / SQ5      :X  d   e[        R                  " [        [         R                  / SQ5        g )NrA   r@   )r"   r"   r0   r"   r-   rB   )r   r5   r   r	   rE   rF   s    r   test_uncompact%TestGeneratorThreshold.test_uncompactC   s    }}Y'+IIII}}126JJJJ}}MMBC
]]CDE 	E E 	i@rI   c                     [         R                  " / SQ5      / SQ:X  d   e[        R                  " [        [         R                  / SQ5        g )NrA   )      ?rN   rN   g      ?      ?rO   rB   )r   creation_sequence_to_weightsr   r	   rE   rF   s    r   !test_creation_sequence_to_weights8TestGeneratorThreshold.test_creation_sequence_to_weightsK   s<    //	: ?
 
 	
 
 	i!A!A?SrI   c                    / SQn[         R                  " [        5         [        R                  " USSS9  S S S 5        [        R                  " USS9/ SQ:X  d   e[        R                  " USS9S/:X  d   eg ! , (       d  f       NH= f)Nr   Tr'   r,   ))r   r"   r.   r/   r1   r2      )r   r	   r
   r   weights_to_creation_sequence)r   r#   s     r   !test_weights_to_creation_sequence8TestGeneratorThreshold.test_weights_to_creation_sequenceV   sw    ]]:&,,SdDQ '//F K
 
 	
 
 //TBqcIII '&s   A88
Bc                     [         R                  " 5       nUR                  SS5        [        R                  " U5      (       a   eg )Nr   r   )r   Graphadd_edger   find_alternating_4_cycle)r   r    s     r   test_find_alternating_4_cycle4TestGeneratorThreshold.test_find_alternating_4_cycleb   s5    HHJ	

1a//22222rI   c                    / SQn[         R                  R                  U5      n[        R                  " USS9nS H7  u  pE[        R
                  " X4U5      [         R
                  " X$U5      :X  a  M7   e   [        R                  " US5      n[        R                  " U VVs/ s H  u  pxUPM	     snnS5      n	Xi:X  d   e0 n
[        U5       H  u  pX;   S   nXU'   M     U
[         R                  " US5      :X  d   e[        R
                  " / SQS	S5      S	S/:X  d   e[        R
                  " / S
QS	S5      S	S/:X  d   e[        R                  " [        [        R
                  / SQS	S5        [        R                  " [        [        R
                  / S
QSS5        [        R                  " [        [        R
                  / S
QS	S5        [        R
                  " / S
QS	S	5      S	/:X  d   eg s  snnf )Nr   Tr,   ))r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   r   r   r@   r   rA   rB   ab)r   r   r   r   r3   shortest_pathshortest_path_length	enumerate"single_source_shortest_path_lengthr   r	   rE   r
   )r   r#   r    r9   r!   msplvtspl2spldjpls                r   test_shortest_path)TestGeneratorThreshold.test_shortest_pathg   s   MM,,S1##CT:TDA$$SQ/23C3CA!3LLLL U &&sA.''s(;stqs(;Q?{{s^EAq	AG $ r<<QBBBB  !?AF1a&PPP  Aq1aV;;;i!2!2OQJj#"3"3YQGj#"3"3Y3G  Aq1aS888 )<s   "G.
c                     [         R                  " / SQS5      / SQ:X  d   e[         R                  " / SQS5      / SQ:X  d   e[         R                  " SS5      / SQ:X  d   e[        R                  " [        [         R
                  / SQS5        g )NrA   r   )r   r   r   r   r   r   r@   rB   )r   rb   r   r	   rE   ra   rF   s    r   test_shortest_path_length0TestGeneratorThreshold.test_shortest_path_length   s    ''	159KKKK''(FJ O
 
 	
 
 ''(FJ O
 
 	
 
 	i!2!2OQGrI   c                     [        [        R                  " SS5      5      S:X  d   e[        R                  " SSSS9/ SQ:X  d   e[        R                  " [
        [        R                  SS5        g )Nr   rN   *   )seed)
r"   r0   r"   r"   r"   r0   r0   r0   r"   r"   g      ?)lenr   random_threshold_sequencer   r	   r
   rF   s    r   test_random_threshold_sequence5TestGeneratorThreshold.test_random_threshold_sequence   sc    300S9:b@@@,,R2> C
 
 	
 
 	j#"?"?SIrI   c                     [         R                  " SS5      / SQ:X  d   e[        R                  " [        [         R                  SS5        g Nr   r   )r"   r0   r"   )r   right_d_threshold_sequencer   r	   r
   rF   s    r   test_right_d_threshold_sequence6TestGeneratorThreshold.test_right_d_threshold_sequence   s5    --a3FFFj#"@"@!QGrI   c                     [         R                  " SS5      / SQ:X  d   e[        R                  " [        [         R                  SS5        g rz   )r   left_d_threshold_sequencer   r	   r
   rF   s    r   test_left_d_threshold_sequence5TestGeneratorThreshold.test_left_d_threshold_sequence   s5    ,,Q2oEEEj#"?"?AFrI   c                 @   / SQn[         R                  " USS9n[         R                  " U5      n[         R                  " U5      nX#:X  d   e[         R                  " [         R                  " / SQ5      5      nUS Vs/ s H  oDS-  PM	     sn:X  d   e[         R                  " / SQ5      nUS Vs/ s H  oDS-  PM	     sn:X  d   e[         R                  " [	        [        S5      5      5      nUS Vs/ s H  oDS	-  PM	     sn:X  d   e[         R                  " S5      nUS Vs/ s H  oDS	-  PM	     sn:X  d   e[         R                  " S
5      nS Vs/ s H  oDS-  PM	     nn[        S [        X5       5       5      S:  d   eg s  snf s  snf s  snf s  snf s  snf )N)
r   rT   r   r         r   rT   r   r   r   )	threshold)r   r   r   r   r   r   r   )rT   rT   rT   r   r   r   r   r   r   r   r   r   r   r      r   r   g      ?ddidiiidididi)r   r   rT   r   r   r   r   r   r      r   	   r   g?ddidiiidididid)r   r   r   r   rT   rT   rT   r   r   r   r   r   r         c              3   @   #    U  H  u  p[        X-
  5      v   M     g 7fNabs.0cr"   s      r   	<genexpr>ATestGeneratorThreshold.test_weights_thresholds.<locals>.<genexpr>   s     8-$!3qu::-   g+=)r   rU   rP   r5   listrc   sumzip)r   wseqcsr;   swss         r   test_weights_thresholds.TestGeneratorThreshold.test_weights_thresholds   s   ---dbA//3..t4yy//>S0TUR
R!IR
 
 	
 
 //0EFR
R!IR
 
 	
 
 //Y5O0PQ)PQ)PAC)PQQQQ//@)PQ)PAC)PQQQQ//0@AJKJ"fJK8#d-885@@@#



 R R Ls   >F1F4F%FFc                 n   [         R                  " S/S/S/S/S/S.5      nUR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        [        R                  " U5      / SQ:X  d   e[        R
                  " U5      n[        R                  " U5      (       d   e[        UR                  5       5      / S	Q:X  d   e[        R                  " [        UR                  5       5      S
S9n[        R                  " U5      U:X  d   eg )Nr   r   rT   r   r   )r   r   r   rT   r   r   )r   r   r   r   )r   r   r   rT   r   r   Tr,   )r   rY   rZ   r   r[   find_threshold_graphr   sortednodesr3   dictr   find_creation_sequence)r   r    TGr   s       r   test_finding_routines,TestGeneratorThreshold.test_finding_routines   s    HH!!!!!=>	

1a	

1a	

1a	

1a	

1a ++A.,>>> %%a(%%b))))bhhj!%7777""4		#4$G))!,222rI   c                 L   Sn[         R                  " U5      n[         R                  " S5      [        R                  " U5      :X  d   e[	        [         R
                  " U5      5      [	        S UR                  5        5       5      :X  d   e[         R                  " U5      nU[        [        R                  " U5      R                  5       5      :X  d   e[        U5      S-  [         R                  " U5      :X  d   e[         R                  " U5      n[        [        R                  " U5      R                  5       5      n[        S [        XE5       5       5      [        R                   " SSS9:X  d   e[        R"                  " U5      R                  5       n[         R$                  " U5      n[        S [        Xg5       5       5      S:  d   e[         R&                  " U5      / S	Q:X  d   e[)        [         R*                  " U5      S
-   5      S:  d   e[         R*                  " S5      S:X  d   e[         R*                  " S5      S:X  d   e[         R*                  " S5      S:X  d   e[         R&                  " S5      / SQ:X  d   e[         R&                  " S5      / SQ:X  d   eg )Nddiiddidc              3   *   #    U  H	  u  pUv   M     g 7fr    )r   r!   r"   s      r   r   XTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>   s     8Rztqzs   r   c              3   @   #    U  H  u  p[        X-
  5      v   M     g 7fr   r   r   s      r   r   r           6+$!3qu::+r   r   gHz>r   c              3   @   #    U  H  u  p[        X-
  5      v   M     g 7fr   r   r   s      r   r   r      r   r   )r   r   r   r   r   r   r   r   g!1,?g-q=diiiddigdidg      dddrC   dddiii)r   r   r   r   r   r   dddiiid)r   r   r   r   rT   rT   r   )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b2s           r   .test_fast_versions_properties_threshold_graphsETestGeneratorThreshold.test_fast_versions_properties_threshold_graphs   s
   #{{:&"**Q-777c))"-.&8Rqxxz8R2RRRR""2&T",,q/00233332w!|s}}R0000!!"%"--"))+,6#b+66&--t:TTTT&&q)002%%b)6#b+66===r"&>>>> 3))"->?%GGG%%i0D888%%e,444%%e,333x(,>>>>y)-BBBBrI   c                 `    [         R                  " SS5      n[         R                  " SS5      ng )Nr   r   )r   r   r{   )r   r   s     r   test_tg_creation_routines0TestGeneratorThreshold.test_tg_creation_routines   s&    ))!Q/**1a0rI   c           	         [         R                  " S5      nUR                  R                  n[         R                  " S5        Sn[        R
                  " U5      n[        R                  " U5      u  pVUR                  R                  U Vs/ s H  oqR                  Xw5      PM     snSSS9  [        R                  " U5      ng s  snf )Nnumpyscipyr   rC   g&.>)rtol)r   importorskiplinalgeigvalsr   r   eigenvectorstestingassert_allclosedotr   laplacian_matrix)	r   npeigenvalr   r    tgevaltgeveclvlapls	            r   test_eigenvectors(TestGeneratorThreshold.test_eigenvectors   s      )99$$G$#++B/


""V#DVrFF2NV#DcPT"U""1% $Es   Cc                    Sn[         R                  " U5      n[        R                  " [        R
                  R                  [         R                  U[        R                  " 5       S9  [         R                  " U[        R                  " 5       S9n[        UR                  5       5      [        UR                  5       5      :X  d   eg )Nr   )create_using)r   r   r   r	   r   	exceptionNetworkXErrorDiGraph
MultiGraphr   edges)r   r   r    MGs       r   test_create_using(TestGeneratorThreshold.test_create_using  s    #LL&&		
   "--/Bbhhj!VAGGI%6666rI   r   N)__name__
__module____qualname____firstlineno__r$   r=   rG   rK   rQ   rV   r\   rm   rp   rw   r|   r   r   r   r   r   r   r   __static_attributes__r   rI   r   r   r      sf    )$..D
A	T
J3
90H(J HGA63&C81	&
7rI   r   )__doc__r   networkxr   networkx.algorithms.threshold
algorithmsr   r   convert_node_labels_to_integerscnltir   r   r   rI   r   <module>r      s4   
   + +
**3z7 z7rI   