
    wg                     H    d Z ddlmZmZ ddlZddlZd Zd Z G d d      Z	y)z1Unit tests for the chain decomposition functions.    )cycleisliceNc              #      K   t        |       }t        |       }| D ]$  }t        t        ||             t	        |       & yw)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       j/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_chains.pycyclesr   
   sC      	CAsJ F:q)**Zs   AAc                 T    t              t        fdt        |       D              S )zDecide whether two sequences are equal up to cyclic permutations.

    For example::

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

    c              3   :   K   | ]  }|t              k(    y w)N)r   ).0r   seq2s     r   	<genexpr>z cyclic_equals.<locals>.<genexpr>'   s     6AqE$K6s   )r   anyr   )seq1r   s    `r   cyclic_equalsr      s#     ;D6666    c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestChainDecompositionz0Unit tests for the chain decomposition function.c                     t        t        |D cg c]  }t        t        |             c}            }|D ]  }t        ||      r y t        ||      s y  | j	                  d       y c c}w )Nzchain not found)listreversedr   r   fail)selfchainexpectedereversed_chain	candidates         r   assertContainsChainz*TestChainDecomposition.assertContainsChain-   se     hE'Jqhqk(:'JKL! 	)IUI.^Y7		) II'( (Ks   A*c                     g d}t        j                  |      }g dddgddgg dg dg}t        t        j                  |d	
            }t	        |      t	        |      k(  sJ y )N)      )r(      r)      )r)      )r,      )r-      )r.      )r,   	   )r0   
   r'   r)   r'   r+   r(   r,   r,   r1   r-   r/   )r2   )r)   r(   )r(   r'   r3   )r+   r)   r4   r,   r)   )r5   )r1   r0   )r0   r,   )r6   )r/   r.   )r.   r-   r'   root)nxGraphr   chain_decompositionr   )r   edgesGr    chainss        r   test_decompositionz)TestChainDecomposition.test_decomposition:   sg    
$ HHUO$VV&$
 b,,QQ786{c(m+++r   c                     t        j                  dd      }t        t        j                  |d            }g dg dg}t	        |      t	        |      k(  sJ |D ]  }| j                  ||        y )Nr)   r   r8   )r   r'   r&   )r(   r   r*   )r+   r,   r7   )r:   barbell_graphr   r<   r   r$   )r   r>   r?   r    r   s        r   test_barbell_graphz)TestChainDecomposition.test_barbell_graph]   sk    Q"b,,QQ78,.FG6{c(m+++ 	6E$$UH5	6r   c                    t        j                  dd      }t        j                  dd      }t        t        t	        d      d            }t        j
                  ||d       t        j                  ||      }t        t        j                  |            }g dg dg d	g d
g}t        |      t        |      k(  sJ |D ]  }| j                  ||        y)z4Test for a graph with multiple connected components.r)   r   r-   abcdefFcopyrB   rC   )ab)rL   c)rM   rK   )dr!   )r!   f)rP   rO   Nr:   rD   dictziprangerelabel_nodesunionr   r<   r   r$   r   r>   Hmappingr?   r    r   s          r   test_disconnected_graphz.TestChainDecomposition.test_disconnected_graphf   s    Q"Q"s58X./
G%0HHQNb,,Q/0$$00	
 6{c(m+++ 	6E$$UH5	6r   c                    t        j                  dd      }t        j                  dd      }t        t        t	        d      d            }t        j
                  ||d       t        j                  ||      }t        t        j                  |d            }g d	g d
g}t        |      t        |      k(  sJ |D ]  }| j                  ||        y)z4Test for a single component of a disconnected graph.r)   r   r-   rG   FrH   rK   r8   rJ   rN   NrQ   rW   s          r   !test_disconnected_graph_root_nodez8TestChainDecomposition.test_disconnected_graph_root_nodex   s    Q"Q"s58X./
G%0HHQNb,,QS9:00
 6{c(m+++ 	6E$$UH5	6r   c                     t        j                         }|j                  g d       t        j                  t         j
                        5  t        j                  |d       ddd       y# 1 sw Y   yxY w)z2Test chain decomposition when root is not in graph)r'   r(   r)   r-   r8   N)r:   r;   add_nodes_frompytestraisesNodeNotFoundhas_bridges)r   r>   s     r   &test_chain_decomposition_root_not_in_Gz=TestChainDecomposition.test_chain_decomposition_root_not_in_G   sN    HHJ	#]]2??+ 	&NN11%	& 	& 	&s   A,,A5N)
__name__
__module____qualname____doc__r$   r@   rE   rZ   r\   rc    r   r   r   r   *   s$    :),F66$6 &r   r   )
rg   	itertoolsr   r   r_   networkxr:   r   r   r   rh   r   r   <module>rk      s'    7 #   7 c& c&r   