
    fid                     P    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	dS )z1Unit tests for the chain decomposition functions.    )cycleisliceNc              #      K   t          |           }t          |           }| D ]0}t          t          ||                    V  t	          |           1dS )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       }/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/networkx/algorithms/tests/test_chains.pycyclesr   
   sf       	CAsJ  F:q))*****Z     c                 r    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    V  d S )N)r   ).0r   seq2s     r   	<genexpr>z cyclic_equals.<locals>.<genexpr>'   s.      66AqE$KK666666r   )r   anyr   )seq1r   s    `r   cyclic_equalsr      s9     ;;D6666666666r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	TestChainDecompositionz0Unit tests for the chain decomposition function.c                     t          t          d |D                                 }|D ](}t          ||          r d S t          ||          r d S )|                     d           d S )Nc                 F    g | ]}t          t          |                    S  )r   reversed)r   es     r   
<listcomp>z>TestChainDecomposition.assertContainsChain.<locals>.<listcomp>1   s&    'J'J'Jqhqkk(:(:'J'J'Jr   zchain not found)listr   r   fail)selfchainexpectedreversed_chain	candidates        r   assertContainsChainz*TestChainDecomposition.assertContainsChain-   s     h'J'JE'J'J'JKKLL! 	) 	)IUI.. ^Y77  II'(((((r   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 d S )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_decompositionz)TestChainDecomposition.test_decomposition:   s    
 
 
$ HUOO$$$VV&&&$$$
 b,QQ777886{{c(mm++++++r   c                     t          j        dd          }t          t          j        |d                    }g dg dg}t	          |          t	          |          k    sJ |D ]}|                     ||           d S )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_graphz)TestChainDecomposition.test_barbell_graphX   s    Q""b,QQ77788,,,.F.F.FG6{{c(mm++++ 	6 	6E$$UH5555	6 	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 ]}| 
                    ||           dS )z4Test for a graph with multiple connected components.r,   r   r0   abcdefFcopyrE   rF   )ab)rO   c)rP   rN   )dr   )r   f)rS   rR   Nr=   rG   dictziprangerelabel_nodesunionr    r?   r   r'   r"   rA   HmappingrB   r$   r#   s          r   test_disconnected_graphz.TestChainDecomposition.test_disconnected_grapha   s    Q""Q""s588X..//
G%0000HQNNb,Q//00$$$$$$000000	
 6{{c(mm++++ 	6 	6E$$UH5555	6 	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 ]}| 
                    ||           dS )z4Test for a single component of a disconnected graph.r,   r   r0   rJ   FrK   rN   r;   rM   rQ   NrT   rZ   s          r   !test_disconnected_graph_root_nodez8TestChainDecomposition.test_disconnected_graph_root_nodes   s    Q""Q""s588X..//
G%0000HQNNb,QS999::000000
 6{{c(mm++++ 	6 	6E$$UH5555	6 	6r   c                     t          j                    }|                    g d           t          j        t           j                  5  t          j        |d           ddd           dS # 1 swxY w Y   dS )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_Gz=TestChainDecomposition.test_chain_decomposition_root_not_in_G   s    HJJ	###]2?++ 	& 	&N11%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   	A--A14A1N)
__name__
__module____qualname____doc__r'   rC   rH   r]   r_   rf   r   r   r   r   r   *   st        ::) ) ), , ,<6 6 66 6 6$6 6 6 & & & & &r   r   )
rj   	itertoolsr   r   rb   networkxr=   r   r   r   r   r   r   <module>rm      s    7 7 # # # # # # # #        7 7 7 ^& ^& ^& ^& ^& ^& ^& ^& ^& ^&r   