o
    ]Zh                     @   sF   d Z ddlmZmZ ddlZddlZdd Zdd ZG dd	 d	Z	dS )
z1Unit tests for the chain decomposition functions.    )cycleisliceNc                 c   s8    t | }t| }| D ]}tt||V  t| qd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nZ
cycled_seqx r
   T/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/tests/test_chains.pycycles
   s   	
r   c                    s"   t   t fd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   s    | ]	}|t  kV  qd S )N)r   ).0r	   seq2r
   r   	<genexpr>'   s    z cyclic_equals.<locals>.<genexpr>)r   anyr   )Zseq1r   r
   r   r   cyclic_equals   s   r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestChainDecompositionz0Unit tests for the chain decomposition function.c                 C   sN   t tdd |D }|D ]}t||r d S t||r d S q| d d S )Nc                 S   s   g | ]}t t|qS r
   )r   reversed)r   er
   r
   r   
<listcomp>1   s    z>TestChainDecomposition.assertContainsChain.<locals>.<listcomp>zchain not found)listr   r   Zfail)selfchainexpectedZreversed_chain	candidater
   r
   r   assertContainsChain-   s   

z*TestChainDecomposition.assertContainsChainc                 C   s^   g d}t |}g dddgddgg dg dg}tt j|d	d
}t|t|ks-J d S )N)      )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    )r,   )r(   r'   )r'   r#   )r-   )r&   r%   )r%   r$   r   root)nxGraphr   chain_decompositionr   )r   edgesGr   chainsr
   r
   r   test_decomposition:   s   
z)TestChainDecomposition.test_decompositionc                 C   s\   t dd}tt j|dd}g dg dg}t|t|ks!J |D ]}| || q#d S )Nr    r   r/   )r   r   r   )r   r   r!   )r"   r#   r.   )r1   barbell_graphr   r3   r   r   )r   r5   r6   r   r   r
   r
   r   test_barbell_graph]   s   z)TestChainDecomposition.test_barbell_graphc                 C   s   t dd}t dd}tttdd}t j||dd t ||}tt |}g dg dg d	g d
g}t	|t	|ksBJ |D ]}| 
|| qDdS )z4Test for a graph with multiple connected components.r    r   r$   abcdefFcopyr8   r9   )ab)rA   c)rB   r@   )dr   )r   f)rE   rD   Nr1   r:   dictziprangeZrelabel_nodesunionr   r3   r   r   r   r5   Hmappingr6   r   r   r
   r
   r   test_disconnected_graphf   s   z.TestChainDecomposition.test_disconnected_graphc                 C   s   t dd}t dd}tttdd}t j||dd t ||}tt j|dd}g d	g d
g}t	|t	|ks>J |D ]}| 
|| q@dS )z4Test for a single component of a disconnected graph.r    r   r$   r<   Fr=   r@   r/   r?   rC   NrF   rK   r
   r
   r   !test_disconnected_graph_root_nodex   s   z8TestChainDecomposition.test_disconnected_graph_root_nodec                 C   sV   t  }|g d tt j t j|dd W d   dS 1 s$w   Y  dS )z2Test chain decomposition when root is not in graph)r   r   r    r$   r/   N)r1   r2   Zadd_nodes_frompytestZraisesZNodeNotFoundZhas_bridges)r   r5   r
   r
   r   &test_chain_decomposition_root_not_in_G   s
   "z=TestChainDecomposition.test_chain_decomposition_root_not_in_GN)
__name__
__module____qualname____doc__r   r7   r;   rN   rO   rQ   r
   r
   r
   r   r   *   s    #	r   )
rU   	itertoolsr   r   rP   Znetworkxr1   r   r   r   r
   r
   r
   r   <module>   s    