
    shE              	       F   S SK r S SKJr  S SKrS SKrS SKJr  \R                  R                  S\R                  \R                  \R                  45      \R                  R                  SS1S1SS1S	S145      S
 5       5       r\R                  R                  S\R                  \R                  \R                  45      \R                  R                  SSS1SS145      S 5       5       r\R                  R                  S\R                  \R                   \R"                  45      \R                  R                  S\R$                  \R&                  \R(                  45      S 5       5       r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      rg)    N)permutations)edges_equalfnedgeset)r      )r   r         )r   r   c                     [         R                  " S5      n[        R                  " [         R                  SS9   U " X!5        SSS5        g! , (       d  f       g= f)zOAll is_*matching functions have consistent exception message for node
not in G.   zmatching.*with node not in GmatchNnx
path_graphpytestraisesNetworkXErrorr   r   Gs      {/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/networkx/algorithms/tests/test_matching.pytest_is_matching_node_not_in_Gr   
   s;     	aA	r''/M	N
1 
O	N	N   	A
A)r      r	   )r   c                     [         R                  " S5      n[        R                  " [         R                  SS9   U " X!5        SSS5        g! , (       d  f       g= f)z[All is_*matching functions have consistent exception message for invalid
edges in matching.r   z.*non-2-tuple edge.*r   Nr   r   s      r   test_is_matching_invalid_edger      s;     	aA	r''/E	F
1 
G	F	Fr   
graph_typec                     U" 5       n[         R                  " [        R                  5         U " U5        S S S 5        g ! , (       d  f       g = fN)r   r   r   NetworkXNotImplemented)r   r   r   s      r   test_wrong_graph_typer!   0   s0    
 	A	r00	1
1 
2	1	1s	   	>
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S rS rS rSrg)TestMaxWeightMatching:   zXUnit tests for the
:func:`~networkx.algorithms.matching.max_weight_matching` function.

c                     [         R                  " 5       n[         R                  " U5      [        5       :X  d   e[         R                  " U5      [        5       :X  d   eg)zEmpty graphN)r   Graphmax_weight_matchingsetmin_weight_matchingselfr   s     r   test_trivial1#TestMaxWeightMatching.test_trivial1@   sC    HHJ%%a(CE111%%a(CE111    c                     [         R                  " 5       nUR                  SSSS9  [         R                  " U5      [	        5       :X  d   e[         R
                  " U5      [	        5       :X  d   eg )Nr   d   weight)r   r&   add_edger'   r(   r)   r*   s     r   test_selfloop#TestMaxWeightMatching.test_selfloopF   sU    HHJ	

1a
$%%a(CE111%%a(CE111r.   c                     [         R                  " 5       nUR                  SS5        [        [         R                  " U5      S15      (       d   e[        [         R
                  " U5      S15      (       d   eg )Nr   r   r   r   r   r&   r3   r   r'   r)   r*   s     r   test_single_edge&TestMaxWeightMatching.test_single_edgeL   s[    HHJ	

1a211!4vh????211!4vh????r.   c                    [         R                  " 5       nUR                  SSSS9  UR                  SSSS9  [        [         R                  " U5      S15      (       d   e[        [         R
                  " U5      S15      (       d   eg )	Nonetwo
   r1   three   r=   r?   r<   r=   r8   r*   s     r   test_two_path#TestMaxWeightMatching.test_two_pathR   st    HHJ	

5%
+	

5'"
-211!47G6HIIII211!4~6FGGGGr.   c                    [         R                  " 5       nUR                  SSSS9  UR                  SSSS9  UR                  SSSS9  [        [         R                  " U5      S15      (       d   e[        [         R                  " US5      S	S
15      (       d   e[        [         R
                  " U5      S	S
15      (       d   e[        [         R
                  " US5      S	S
15      (       d   eg )Nr   r	   r   r1   r
   r@   r   r   r   r	   r
   r   r8   r*   s     r   	test_pathTestMaxWeightMatching.test_pathY   s    HHJ	

1a
"	

1a
#	

1a
"211!4vh????211!Q7&&9IJJJJ211!4vv6FGGGG211!Q7&&9IJJJJr.   c                 Z   [         R                  " 5       nUR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  [        [         R                  " U5      SS15      (       d   e[        [         R
                  " U5      SS	15      (       d   eg )
Nr   r   r	   r1   r
   rF   rG   r   r   r   r8   r*   s     r   test_square!TestMaxWeightMatching.test_squarec   s    HHJ	

1a
"	

1a
"	

1a
"	

1a
"211!4vv6FGGGG211!4vv6FGGGGr.   c                    [         R                  " 5       nUR                  SSSSS9  UR                  SSSSS9  [        [         R                  " USS9S	15      (       d   e[        [         R
                  " USS9S
15      (       d   eg )Nr<   r=   r>   r@   )r2   abcdr?   rO   r1   rB   rA   r8   r*   s     r   test_edge_attribute_name.TestMaxWeightMatching.test_edge_attribute_namel   s|    HHJ	

5%
4	

5'"2
6211!FCnEUVVVV211!FCFVEWXXXXr.   c                    [         R                  " 5       nUR                  SS[        R                  S9  UR                  SS[        R
                  " S5      S9  UR                  SSSS9  UR                  SS[        R                  " S5      S9  [        [         R                  " U5      SS	15      (       d   e[        [         R                  " U5      SS	15      (       d   eg )
Nr   r	   r1   r
   g      @r   g       @rK   r   )
r   r&   r3   mathpiexpsqrtr   r'   r)   r*   s     r   test_floating_point_weights1TestMaxWeightMatching.test_floating_point_weightss   s    HHJ	

1a
(	

1a
,	

1a
$	

1a		#
/211!4vv6FGGGG211!4vv6FGGGGr.   c                    [         R                  " 5       nUR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  [        [         R                  " U5      S	15      (       d   e[        [         R                  " US
S9SS15      (       d   e[        [         R
                  " U5      S	S15      (       d   eg )Nr   r	   r1   r
   r   irF   T)maxcardinalityr   r
   r	   r   rG   r8   r*   s     r   test_negative_weights+TestMaxWeightMatching.test_negative_weights|   s    HHJ	

1a
"	

1a
#	

1a
"	

1a
#	

1a
#211!4vh????""1T:VV<L
 
 	
 
 211!4vv6FGGGGr.   c                    [         R                  " 5       nUR                  / SQ5        SS1n[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eUR                  SS/5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z-Create S-blossom and use it for augmentation:)r   r	      r   r
   	   r	   r
   r>   )r
   r      rF   rG   )r      r   )r   r   rh      r   rh   r   r   r   Nr   r&   add_weighted_edges_fromr   r'   r)   r+   r   answers      r   test_s_blossom$TestMaxWeightMatching.test_s_blossom   s    HHJ	!!"OP&!211!4f====211!4f====	!!9i"89)211!4f====211!4f====r.   c                    [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eUR                  SSSS9  UR                  SSSS9  [        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eUR                  SS5        UR                  SSSS9  1 S	kn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg
)z=Create S-blossom, relabel as T-blossom, use for augmentation:)r   r	   re   r   r
   rc   rf   )r   r   r   )r   r   r   )r   rh   r
   ri   r   r   r
   r1   r   rh   >   rF   r
   rh   rk   N)r   r&   rm   r   r'   r)   r3   remove_edgern   s      r   test_s_t_blossom&TestMaxWeightMatching.test_s_t_blossom   s"   HHJ	!!O	
 *211!4f====211!4f====	

1a
"	

1a
"211!4f====211!4f====	a	

1a
")211!4f====211!4f====r.   c                    [         R                  " 5       nUR                  / SQ5        1 SknU Vs1 s H  n[        U5      iM     nn[         R                  " U5       Vs1 s H  n[        U5      iM     nnXT:X  d   e[         R
                  " U5       Vs1 s H  n[        U5      iM     nnXT:X  d   egs  snf s  snf s  snf )z.Create nested S-blossom, use for augmentation:)rs   rd   rf   )r	   r   rc   )r
   r   rc   )r   r   r>   )r   rh   rh   >   r]   r^   r   rh   N)r   r&   rm   	frozensetr'   r)   )r+   r   expected_edgeseteexpectedro   s         r   test_nested_s_blossom+TestMaxWeightMatching.test_nested_s_blossom   s     HHJ	!!
	
 4*:;*:QIaL*:;(*(>(>q(AB(A1)A,(AB!!!(*(>(>q(AB(A1)A,(AB!!!	 <BBs   B5 B:B?c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z<Create S-blossom, relabel as S, include in nested S-blossom:)	)r   r	   r>   )r   rg   r>   )r	   r
      )r
   r      )r
   r   r   r   r      )r   rh   r>   )rh   rg   r>   )rg   rc   rc   >   rF   rG   rz   rg   rc   Nrl   rn   s      r   test_nested_s_blossom_relabel3TestMaxWeightMatching.test_nested_s_blossom_relabel   c    HHJ	!!
	
 2211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z5Create nested S-blossom, augment, expand recursively:)
rb   rt   rf   )r	   r   r   )r
   r   r   )r   r      )r   rh   r   )r   rg   r   )rh   rg   r   )rg   rc   r   >   rF   r
   r   r   rh   r   Nrl   rn   s      r   test_nested_s_blossom_expand2TestMaxWeightMatching.test_nested_s_blossom_expand   sc    HHJ	!!	
 2211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z'Create S-blossom, relabel as T, expand:))r   r	      )r   r      )r   rh      r	   r
   r   )r
   r   r   r   )r   rc   r   )r   rg      >   rj   r   r   rc   r   rg   Nrl   rn   s      r   test_s_blossom_relabel_expand3TestMaxWeightMatching.test_s_blossom_relabel_expand   sc    HHJ	!!		
 2211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z.Create nested S-blossom, relabel as T, expand:)	)r   r	      )r   r
   r   )r   rc   rc   r   )r	   r      )r
   r   r   )r   r   r   )r   rg   rg   )r   rh   rg   >   r   rc   r   r   rg   rz   Nrl   rn   s      r   $test_nested_s_blossom_relabel_expand:TestMaxWeightMatching.test_nested_s_blossom_relabel_expand   r   r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)zDCreate blossom, relabel as T in more than one way, expand,
augment:
)
r   r	   -   r   r   r   r	   r
   2   r
   r   r   r   r   r   r   rh      r
   re   #   )r   rc   r   r   rg      re   r>   r      rj   r   r   r   re   r>   Nrl   rn   s      r   test_nasty_blossom1)TestMaxWeightMatching.test_nasty_blossom1  e     HHJ	!!	
 ;211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)zAgain but slightly different:)
r   r   r   r   r   r   r   )r   rc   r   )r   rg   (   r   r   Nrl   rn   s      r   test_nasty_blossom2)TestMaxWeightMatching.test_nasty_blossom2(  sc    HHJ	!!	
 ;211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)zeCreate blossom, relabel as T, expand such that a new
least-slack S-to-free dge is produced, augment:
)
r   r   r   r   r   r   r   )r   rc      r   r   r   Nrl   rn   s      r   test_nasty_blossom_least_slack4TestMaxWeightMatching.test_nasty_blossom_least_slack=  r   r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z8Create nested blossom, relabel as T in more than one way)r   )r   rg   r   r   r   )r   r   _   )r   rh   ^   )r   rh   r   )rh   rg   r   )r   rc   r   )r
   r@   r   )r   re   $   )rg   r>   r   )r@   r   r   >   r   r   r   r   re   rg   r>   r@   r   Nrl   rn   s      r   test_nasty_blossom_augmenting3TestMaxWeightMatching.test_nasty_blossom_augmentingT  sf     HHJ	!!	
" E211!4f====211!4f====r.   c                     [         R                  " 5       nUR                  / SQ5        1 Skn[        [         R                  " U5      U5      (       d   e[        [         R
                  " U5      U5      (       d   eg)z:Create nested S-blossom, relabel as S, expand recursively:))r   r	   r   )r   r
   r   )r	   r
   <   )r	   r   7   )r
   r   r   r   )r   rc   r   )r   rg   r   )rg   rh   r>   )rc   r>   r>   )r   re   r   >   rF   r   r   re   rh   rg   rc   r>   Nrl   rn   s      r   %test_nasty_blossom_expand_recursively;TestMaxWeightMatching.test_nasty_blossom_expand_recursivelyn  sc    HHJ	!!	
 ;211!4f====211!4f====r.    N)__name__
__module____qualname____firstlineno____doc__r,   r4   r9   rC   rH   rL   rP   rW   r_   rp   rw   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r.   r   r#   r#   :   sw    
22@HKHYHH>>*",>(>*>&>(>.>*>.>4>r.   r#   c                   H    \ 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)TestIsMatchingi  zPUnit tests for the
:func:`~networkx.algorithms.matching.is_matching` function.

c                 v    [         R                  " S5      n[         R                  " USSSSS.5      (       d   eg Nr   r   r   r
   r	   )r   r   r	   r
   r   r   is_matchingr*   s     r   	test_dictTestIsMatching.test_dict  s0    MM!~~aQ1q!9::::r.   c                 |    [         R                  " S5      n[         R                  " U[        5       5      (       d   eg )Nr   )r   r   r   r(   r*   s     r   test_empty_matching"TestIsMatching.test_empty_matching  s)    MM!~~a''''r.   c                 n    [         R                  " S5      n[         R                  " US15      (       d   eg )Nr   rF   r   r*   s     r   r9   TestIsMatching.test_single_edge  s)    MM!~~a&****r.   c                 0   [         R                  " S5      n[         R                  " USS15      (       d   e[         R                  " USS15      (       d   e[         R                  " USS15      (       d   e[         R                  " USS15      (       d   eg )Nr   r7   r   r   r   )r
   r	   r   r*   s     r   test_edge_orderTestIsMatching.test_edge_order  s    MM!~~a&&!12222~~a&&!12222~~a&&!12222~~a&&!12222r.   c                 p    [         R                  " S5      n[         R                  " USS15      (       d   eg Nr   r7   r   r   r*   s     r   test_valid_matching"TestIsMatching.test_valid_matching  s,    MM!~~a&&!12222r.   c                     [         R                  " S5      n[         R                  " U1 Sk5      (       a   eUR                  SS5        [         R                  " USS15      (       a   eg Nr   >   r   r   rF   r   r   r   rF   )r   r   r   r3   r*   s     r   test_selfloopsTestIsMatching.test_selfloops  sU    MM!>>!%=>>>>	

1a>>!ff%566666r.   c                 p    [         R                  " S5      n[         R                  " U1 Sk5      (       a   eg )Nr      r7   rF   r   r   r*   s     r   test_invalid_matching$TestIsMatching.test_invalid_matching  s+    MM!>>!%=>>>>>r.   c                 ,   [         R                  " S5      n[         R                  " USS15      (       a   e[         R                  " UR                  5      n[         R                  " US15      (       d   e[         R                  " US15      (       a   eg )Nr   r   r
   rF   r7   r   )r   r   r   DiGraphedgesr*   s     r   test_invalid_edge TestIsMatching.test_invalid_edge  ss    MM!>>!ff%56666JJqww~~a&****>>!fX.....r.   r   N)r   r   r   r   r   r   r   r9   r   r   r   r   r   r   r   r.   r   r   r     s/    
;(+337?/r.   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	TestIsMaximalMatchingi  zXUnit tests for the
:func:`~networkx.algorithms.matching.is_maximal_matching` function.

c                 v    [         R                  " S5      n[         R                  " USSSSS.5      (       d   eg r   r   r   is_maximal_matchingr*   s     r   r   TestIsMaximalMatching.test_dict  2    MM!%%aQ1q)ABBBBr.   c                 p    [         R                  " S5      n[         R                  " USS15      (       d   eg r   r   r*   s     r   
test_valid TestIsMaximalMatching.test_valid  .    MM!%%a&&)9::::r.   c                    [         R                  " S5      n[         R                  " U1 Sk5      (       a   e[         R                  " US15      (       a   eUR                  SS5        [         R                  " US15      (       a   eg )Nr   r   r   r   r   )r   r   r   r3   r*   s     r   test_not_matching'TestIsMaximalMatching.test_not_matching  sq    MM!))!-EFFFF))!fX6666	

1a))!fX66666r.   c                 n    [         R                  " S5      n[         R                  " US15      (       a   eg )Nr   r7   r   r*   s     r   test_not_maximal&TestIsMaximalMatching.test_not_maximal  s.    MM!))!fX66666r.   r   N)
r   r   r   r   r   r   r  r  r  r   r   r.   r   r   r     s    
C;77r.   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestIsPerfectMatchingi  zXUnit tests for the
:func:`~networkx.algorithms.matching.is_perfect_matching` function.

c                 v    [         R                  " S5      n[         R                  " USSSSS.5      (       d   eg r   r   r   is_perfect_matchingr*   s     r   r   TestIsPerfectMatching.test_dict  r   r.   c                 p    [         R                  " S5      n[         R                  " USS15      (       d   eg r   r  r*   s     r   r   TestIsPerfectMatching.test_valid  r  r.   c                     [         R                  " S5      nUR                  SS5        UR                  SS5        UR                  SS5        [         R                  " U1 Sk5      (       d   eg )Nr   r   r   r   r	   >   r   rK   r   r	   r   cycle_graphr3   r  r*   s     r   test_valid_not_path)TestIsPerfectMatching.test_valid_not_path  sT    NN1	

1a	

1a	

1a%%a)ABBBBr.   c                     [         R                  " S5      n[         R                  " U1 Sk5      (       a   eUR                  SS5        [         R                  " USS15      (       a   eg r   )r   r   r  r3   r*   s     r   r   $TestIsPerfectMatching.test_selfloops  sY    MM!))!-EFFFF	

1a))!ff-=>>>>>r.   c                     [         R                  " S5      n[         R                  " US15      (       a   e[         R                  " U1 Sk5      (       a   eg )Nr   r   r   r  r*   s     r   r  'TestIsPerfectMatching.test_not_matching  sH    MM!))!fX6666))!-EFFFFFr.   c                     [         R                  " S5      nUR                  SS5        UR                  SS5        [         R                  " USS15      (       a   eg )Nr   r   r   rK   r   r  r*   s     r   test_maximal_but_not_perfect2TestIsPerfectMatching.test_maximal_but_not_perfect  sM    NN1	

1a	

1a))!ff-=>>>>>r.   r   N)r   r   r   r   r   r   r  r  r   r  r  r   r   r.   r   r  r    s(    
C;C?G
?r.   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	TestMaximalMatchingi  zLUnit tests for the
:func:`~networkx.algorithms.matching.maximal_matching`.

c                     / SQn[         R                  " U5      n[         R                  " U5      n[         R                  " X#5      (       d   eg )N)rF   )r   r   r   )r	   r   rG   ru   rz   )r   r&   maximal_matchingr   )r+   r   r   matchings       r   r   'TestMaximalMatching.test_valid_matching  s;    HHHUO&&q)%%a2222r.   c                     [         R                  " S5      n[         R                  " U5      nS[        U5      :X  d   e[         R                  " X5      (       d   eg )Nr   r   )r   
star_graphr"  lenr   r+   r   r#  s      r   test_single_edge_matching-TestMaximalMatching.test_single_edge_matching  sI    MM!&&q)CM!!!%%a2222r.   c                    [         R                  " S5      nUR                  SS/5        [         R                  " U5      n[	        U5      S:X  d   e[        S U 5       5      (       a   e[         R                  " X5      (       d   eg )Nr
   r   )r   r   r   c              3   .   #    U  H  u  pX:H  v   M     g 7fr   r   ).0uvs      r   	<genexpr>6TestMaximalMatching.test_self_loops.<locals>.<genexpr>  s     3($!qv(s   )r   r   add_edges_fromr"  r'  anyr   r(  s      r   test_self_loops#TestMaximalMatching.test_self_loops  ss    MM!	&&)*&&q)8}!!!3(33333%%a2222r.   c                 4   [        [        S5      5       H  n[        R                  " 5       nUR	                  U5        UR                  SS/5        [        R                  " U5      n[        U5      S:X  d   e[        R                  " X#5      (       a  M   e   g)ztTests that a maximal matching is computed correctly
regardless of the order in which nodes are added to the graph.

r
   r7   )r   r	   r   N)	r   ranger   r&   add_nodes_fromr2  r"  r'  r   )r+   nodesr   r#  s       r   test_ordering!TestMaximalMatching.test_ordering  s|    
 "%(+E
AU#ff-.**1-Hx=A%%%))!6666 ,r.   r   N)
r   r   r   r   r   r   r)  r4  r:  r   r   r.   r   r   r     s    
3337r.   r   )rS   	itertoolsr   r   networkxr   networkx.utilsr   markparametrizer   r   r  r   r   
MultiGraphr   MultiDiGraphr'   r)   r"  r!   r#   r   r   r  r   r   r.   r   <module>rC     s    "   & 2>>21123I3I
J 					 2>>21123I3I
J 	F	v rzz2??'ST2!!2#9#92;N;N
O UH> H>V
// //d7 74(? (?V(7 (7r.   