
    hS                     d    S r SSKJr  SSKrSSKrSSKJr  SSKJ	r	   " S S5      r
 " S S	5      rg)
z>Unit tests for the :mod:`networkx.algorithms.boundary` module.    )combinationsN)convert_node_labels_to_integers)edges_equalc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)TestNodeBoundary   z<Unit tests for the :func:`~networkx.node_boundary` function.c                    [         R                  " 5       n[         R                  " U/ 5      [        5       :X  d   e[         R                  " U/ / 5      [        5       :X  d   e[         R                  " U/ SQ5      [        5       :X  d   e[         R                  " U/ SQ/ SQ5      [        5       :X  d   e[         R                  " U/ SQ/ SQ5      [        5       :X  d   eg)z4Tests that the null graph has empty node boundaries.                  r   r   r   N)nx
null_graphnode_boundarysetselfnulls     Y/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/tests/test_boundary.pytest_null_graph TestNodeBoundary.test_null_graph   s    }}b)SU222b"-666i0CE999i;suDDDi;suDDD    c                 .   [        [        R                  " S5      SS9n[        R                  " U/ 5      [	        5       :X  d   e[        R                  " U/ / 5      [	        5       :X  d   e[        R                  " U/ SQ5      S1:X  d   e[        R                  " U/ SQ5      SS1:X  d   e[        R                  " U/ S	Q5      S
S1:X  d   e[        R                  " U/ SQ5      S1:X  d   e[        R                  " U/ SQSS/5      [	        5       :X  d   eg )N
   r   first_labelr
   r   r   r      r   r   r   r   r"   r      r$   	   r   r&   )cnltir   
path_graphr   r   r   P10s     r   test_path_graph TestNodeBoundary.test_path_graph   s    BMM"%15R(CE111R,555Y/A3666Y/Aq6999_5!Q???Z0QC777YB8CEAAAr   c                 |   [        [        R                  " S5      SS9n[        R                  " U/ 5      [	        5       :X  d   e[        R                  " U/ / 5      [	        5       :X  d   e[        R                  " U/ SQ5      1 Sk:X  d   e[        R                  " U/ SQ5      1 Sk:X  d   e[        R                  " U/ SQ5      1 S	k:X  d   e[        R                  " U/ SQ/ 5      [	        5       :X  d   e[        R                  " X5      [	        5       :X  d   e[        R                  " U/ SQ/ S
Q5      SS1:X  d   eg )Nr   r   r    r
   >   r   r   r   r"   r$   r&   r   r   >   r   r   r   r"   r$   r&   r   r#   >   r   r   r$   r&   r   r   r   r   )r'   r   complete_graphr   r   )r   K10s     r   test_complete_graph$TestNodeBoundary.test_complete_graph"   s   B%%b)q9R(CE111R,555Y/3IIIIY/3IIII_59IIIIY3su<<<)SU222Y	:q!fDDDr   c                    S n[         R                  " 5       nU" US5      [        R                  " SSS9:X  d   eU" US5      [        R                  " SSS9:X  d   eU" US5      [        R                  " S	SS9:X  d   eU" US
5      [        R                  " SSS9:X  d   eU" US5      [        R                  " SSS9:X  d   eg)zaCheck boundaries in the petersen graph

cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)

c                 F   ^ ^ [        U U4S j[        T T5       5       5      $ )Nc              3   j   >#    U  H(  n[        [        R                  " TU5      5      T-  v   M*     g 7f)N)lenr   r   ).0nnGks     r   	<genexpr>BTestNodeBoundary.test_petersen.<locals>.cheeger.<locals>.<genexpr>5   s*     UBTBs2++Ar23a7BTs   03)minr   )r8   r9   s   ``r   cheeger/TestNodeBoundary.test_petersen.<locals>.cheeger4   s    U,qRSBTUUUr   r   g      @g{Gz?)absr   g       @r   gQ?r   g      ?r   g?N)r   petersen_graphpytestapprox)r   r=   Ps      r   test_petersenTestNodeBoundary.test_petersen-   s    	V q!}d ====q!}d ====q!}d ====q!}d ====q!}d ====r   c                 |    [         R                  " / SQ5      nSS1n[         R                  " X5      nS1nX4:X  d   eg)z,Tests the node boundary of a directed graph.)r   r   r   r   r   r   r   r   )r   r   r   r   r   N)r   DiGraphr   r   r8   Sboundaryexpecteds        r   test_directedTestNodeBoundary.test_directed>   s=    JJ?@F##A)3###r   c                     [         R                  " [        [         R                  " S5      R	                  5       5      S-  5      nSS1n[         R
                  " X5      nSS1nX4:X  d   eg)z(Tests the node boundary of a multigraph.r   r   r   r   r   N)r   
MultiGraphlistcycle_graphedgesr   rL   s        r   test_multigraph TestNodeBoundary.test_multigraphF   sZ    MM$r~~a06689A=>F##A)q6###r   c                     / SQn[         R                  " US-  5      nSS1n[         R                  " X#5      nS1nXE:X  d   eg)*Tests the edge boundary of a multidigraph.rG   r   r   r   N)r   MultiDiGraphr   r   rV   r8   rM   rN   rO   s         r   test_multidigraph"TestNodeBoundary.test_multidigraphN   sE    8OOEAI&F##A)3###r    N)__name__
__module____qualname____firstlineno____doc__r   r+   r0   rD   rP   rW   r]   __static_attributes__r_   r   r   r   r      s+    FEB	E>"$$$r   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestEdgeBoundaryX   z<Unit tests for the :func:`~networkx.edge_boundary` function.c                    [         R                  " 5       n[        [         R                  " U/ 5      5      / :X  d   e[        [         R                  " U/ / 5      5      / :X  d   e[        [         R                  " U/ SQ5      5      / :X  d   e[        [         R                  " U/ SQ/ SQ5      5      / :X  d   e[        [         R                  " U/ SQ/ SQ5      5      / :X  d   eg )Nr
   r   r   )r   r   rT   edge_boundaryr   s     r   r    TestEdgeBoundary.test_null_graph[   s    }}B$$T2./2555B$$T2r23r999B$$T956"<<<B$$T9i@ARGGGB$$T9i@ARGGGr   c                    [        [        R                  " S5      SS9n[        [        R                  " U/ 5      5      / :X  d   e[        [        R                  " U/ / 5      5      / :X  d   e[        [        R                  " U/ SQ5      5      S/:X  d   e[        [        R                  " U/ SQ5      5      SS/:X  d   e[        [        R                  " U/ S	Q5      5      S
S/:X  d   e[        [        R                  " U/ SQ5      5      S/:X  d   e[        [        R                  " U/ SQSS/5      5      / :X  d   e[        [        R                  " U/ SQ/ SQ5      5      SS/:X  d   eg )Nr   r   r    r
   rJ   r   )r   r   )r   r"   r#   )r   r   )r"   r$   r%   )r$   r"   r&   r   rI   )r'   r   r(   rT   rj   sortedr)   s     r   r+    TestEdgeBoundary.test_path_graphc   s4   BMM"%15B$$S"-."444B$$S"b12b888B$$S)45&AAAb&&sI67FF;KKKKb&&sO<=&&AQQQQB$$S*566(BBBb&&sI2w?@BFFFB$$S)Y?@VVDTTTTr   c                    [        [        R                  " S5      SS9nS n[        [        R                  " U/ 5      5      / :X  d   e[        [        R                  " U/ / 5      5      / :X  d   eU" [        R                  " U/ SQ5      5      S:X  d   eU" [        R                  " U/ SQ5      5      S:X  d   eU" [        R                  " U/ S	Q5      5      S
:X  d   eU" [        R                  " U/ SQ5      5      S:X  d   e[        [        R                  " U/ SQSS/5      / SQ5      (       d   e[        [        R                  " U/ SQ/ SQ5      / SQ5      (       d   eg )Nr   r   r    c                 &    [        S U  5       5      $ )Nc              3   &   #    U  H  nS v   M	     g7f)r   Nr_   )r6   is     r   r:   ETestEdgeBoundary.test_complete_graph.<locals>.ilen.<locals>.<genexpr>r   s     +(Qq(s   )sum)iterables    r   ilen2TestEdgeBoundary.test_complete_graph.<locals>.ilenq   s    +(+++r   r
      )r   r   r   r"      r#      r%   r   r&   ))r   r&   )r   r   )r   r&   )r   r   )r   r&   )r   r   r   ))r   r   )r   r   )r   r   rI   )r   r   )r   r   rJ   )r   r   )r'   r   r.   rT   rj   r   )r   r/   rv   s      r   r0   $TestEdgeBoundary.test_complete_graphn   s@   B%%b)q9	, B$$S"-."444B$$S"b12b888B$$S)45;;;B$$S,78B>>>B$$S/:;rAAAB$$S*56"<<<S)aW5?
 
 	
 
 S)Y7L
 
 	
 
r   c                     [         R                  " / SQ5      nSS1n[        [         R                  " X5      5      nS/nX4:X  d   eg)z,Tests the edge boundary of a directed graph.rG   r   r   rH   N)r   rK   rT   rj   rL   s        r   rP   TestEdgeBoundary.test_directed   sB    JJ?@F((./8###r   c                     [         R                  " [        [         R                  " S5      R	                  5       5      S-  5      nSS1n[        [         R
                  " X5      5      n/ SQnX4:X  d   eg)z(Tests the edge boundary of a multigraph.r   r   r   r   )r   r   r   rH   rH   N)r   rS   rT   rU   rV   rj   rL   s        r   rW    TestEdgeBoundary.test_multigraph   s[    MM$r~~a06689A=>F((./3###r   c                     / SQn[         R                  " US-  5      nSS1n[        [         R                  " X#5      5      nSS/nXE:X  d   eg)rZ   rG   r   r   r   rH   N)r   r[   rT   rj   r\   s         r   r]   "TestEdgeBoundary.test_multidigraph   sM    8OOEAI&F((./F####r   r_   N)r`   ra   rb   rc   rd   r   r+   r0   rP   rW   r]   re   r_   r   r   rg   rg   X   s%    FH	U
*$$$r   rg   )rd   	itertoolsr   rA   networkxr   r   r'   networkx.utilsr   r   rg   r_   r   r   <module>r      s0    D "   = &I$ I$XB$ B$r   