
    h                     H    S r SSKJrJr  SSKrSSKrS rS r " S S5      r	g)z1Unit tests for the chain decomposition functions.    )cycleisliceNc              #      #    [        U 5      n[        U 5      nU  H$  n[        [        X!5      5      v   [	        U5        M&     g7f)zYields cyclic permutations of the given sequence.

For example::

    >>> list(cycles("abc"))
    [('a', 'b', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b')]

N)lenr   tupler   next)seqn
cycled_seqxs       W/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/tests/test_chains.pycyclesr   
   s;      	CAsJF:)**Z s   AAc                 V   ^ [        T5      m[        U4S j[        U 5       5       5      $ )zDecide whether two sequences are equal up to cyclic permutations.

For example::

    >>> cyclic_equals("xyz", "zxy")
    True
    >>> cyclic_equals("xyz", "zyx")
    False

c              3   >   >#    U  H  o[        T5      :H  v   M     g 7f)N)r   ).0r   seq2s     r   	<genexpr> cyclic_equals.<locals>.<genexpr>'   s     6AE$Ks   )r   anyr   )seq1r   s    `r   cyclic_equalsr      s#     ;D6666    c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestChainDecomposition*   z0Unit tests for the chain decomposition function.c                     [        [        U Vs/ s H  n[        [        U5      5      PM     sn5      5      nU H'  n[        X5      (       a    g [        XE5      (       d  M'    g    U R	                  S5        g s  snf )Nzchain not found)listreversedr   r   fail)selfchainexpectedereversed_chain	candidates         r   assertContainsChain*TestChainDecomposition.assertContainsChain-   sf     hE'JEqhqk(:E'JKL!IU..^77	 " II'( (Ks   A7c                     / SQn[         R                  " U5      n/ SQSS/SS// SQ/ SQ/n[        [         R                  " US	S
95      n[	        U5      [	        U5      :X  d   eg )N)      )r+      r,      )r,      )r/      )r0      )r1      )r/   	   )r3   
   r*   r,   r*   r.   r+   r/   r/   r4   r0   r2   )r5   )r,   r+   )r+   r*   r6   )r.   r,   r7   r/   r,   )r8   )r4   r3   )r3   r/   )r9   )r2   r1   )r1   r0   r*   root)nxGraphr   chain_decompositionr   )r    edgesGr"   chainss        r   test_decomposition)TestChainDecomposition.test_decomposition:   sg    
$ HHUO$VV&$
 b,,QQ786{c(m+++r   c                     [         R                  " SS5      n[        [         R                  " USS95      n/ SQ/ SQ/n[	        U5      [	        U5      :X  d   eU H  nU R                  XC5        M     g )Nr,   r   r;   )r   r*   r)   )r+   r   r-   )r.   r/   r:   )r=   barbell_graphr   r?   r   r&   )r    rA   rB   r"   r!   s        r   test_barbell_graph)TestChainDecomposition.test_barbell_graph]   sd    Q"b,,QQ78,.FG6{c(m+++E$$U5 r   c                    [         R                  " SS5      n[         R                  " SS5      n[        [        [	        S5      S5      5      n[         R
                  " X#SS9  [         R                  " X5      n[        [         R                  " U5      5      n/ SQ/ SQ/ S	Q/ S
Q/n[        U5      [        U5      :X  d   eU H  nU R                  Xe5        M     g)z4Test for a graph with multiple connected components.r,   r   r0   abcdefFcopyrF   rG   )ab)rQ   c)rR   rP   )dr#   )r#   f)rU   rT   Nr=   rH   dictziprangerelabel_nodesunionr   r?   r   r&   r    rA   HmappingrB   r"   r!   s          r   test_disconnected_graph.TestChainDecomposition.test_disconnected_graphf   s    Q"Q"s58X./
%0HHQNb,,Q/0$$00	
 6{c(m+++E$$U5 r   c                    [         R                  " SS5      n[         R                  " SS5      n[        [        [	        S5      S5      5      n[         R
                  " X#SS9  [         R                  " X5      n[        [         R                  " USS95      n/ S	Q/ S
Q/n[        U5      [        U5      :X  d   eU H  nU R                  Xe5        M     g)z4Test for a single component of a disconnected graph.r,   r   r0   rL   FrM   rP   r;   rO   rS   NrV   r\   s          r   !test_disconnected_graph_root_node8TestChainDecomposition.test_disconnected_graph_root_nodex   s    Q"Q"s58X./
%0HHQNb,,QS9:00
 6{c(m+++E$$U5 r   c                     [         R                  " 5       nUR                  / SQ5        [        R                  " [         R
                  5         [         R                  " USS9  SSS5        g! , (       d  f       g= f)z2Test chain decomposition when root is not in graph)r*   r+   r,   r0   r;   N)r=   r>   add_nodes_frompytestraisesNodeNotFoundhas_bridges)r    rA   s     r   &test_chain_decomposition_root_not_in_G=TestChainDecomposition.test_chain_decomposition_root_not_in_G   sE    HHJ	#]]2??+NN11% ,++s   A,,
A: N)__name__
__module____qualname____firstlineno____doc__r&   rC   rI   r_   rb   rj   __static_attributes__rl   r   r   r   r   *   s$    :),F66$6 &r   r   )
rq   	itertoolsr   r   rf   networkxr=   r   r   r   rl   r   r   <module>ru      s'    7 #   7 c& c&r   