o
    ]Zh+                     @   s   d dl Z d dlZd dlZejdejejfdd ZG dd dZ	G dd dZ
G d	d
 d
ZG dd dZG dd dZG dd dZG dd dZdS )    Nfc                 C   sF   t  }tjt jdd | | W d    d S 1 sw   Y  d S )NzConnectivity is undefined)match)nxGraphpytestraisesNetworkXPointlessConcept)r   G r
   S/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/tests/test_euler.pytest_empty_graph_raises   s   
"r   c                   @   s   e Zd Zdd Zdd ZdS )TestIsEulerianc                 C   s   t t ds
J t t dsJ t t dsJ t t ds(J t t dr2J t t dr<J t t drFJ t t drPJ t t  rYJ t t drcJ d S )N               )r   is_euleriancomplete_graphhypercube_graphZpetersen_graph
path_graphselfr
   r
   r   test_is_eulerian   s   zTestIsEulerian.test_is_eulerianc                 C   s   t  }|g d t |rJ t  }|g d t |r$J t  }|dd |dd |dd |dd t |rGJ d S )N)      r   r   r   r   )r   r   Zadd_nodes_fromr   DiGraphMultiDiGraphadd_edger   r	   r
   r
   r   test_is_eulerian2   s   z TestIsEulerian.test_is_eulerian2N)__name__
__module____qualname__r   r    r
   r
   r
   r   r      s    r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestEulerianCircuitc                 C   s  t d}tt j|dd}dd |D }|g dksJ |g dks%J tt j|dd}d	d |D }|g d
ks=J |g dksEJ t d}tt j|dd}dd |D }|g dksbJ |g dksjJ tt j|dd}dd |D }|g dksJ |g dksJ d S )Nr   r   sourcec                 S      g | ]\}}|qS r
   r
   .0uvr
   r
   r   
<listcomp>4       zCTestEulerianCircuit.test_eulerian_circuit_cycle.<locals>.<listcomp>)r   r   r   r   )r   r   r   r   r   r   r   r   r   c                 S   r'   r
   r
   r(   r
   r
   r   r,   9   r-   r   r   r   r   r   r   r   r   r   r   r   r   r   c                 S   r'   r
   r
   r(   r
   r
   r   r,   @   r-   )r   r   r   )r   r   r0   r1   c                 S   r'   r
   r
   r(   r
   r
   r   r,   E   r-   )r   r   r   )r4   r   r   r7   )r   cycle_graphlisteulerian_circuitr   r   r	   edgesnodesr
   r
   r   test_eulerian_circuit_cycle0   s$   

z/TestEulerianCircuit.test_eulerian_circuit_cyclec                 C   s   t  }t |g d tt j|dd}dd |D }|g dks$J |g dks,J tt j|dd}dd |D }|g d	ksDJ |g d
ksLJ d S )Nr   r   r   r   r   r%   c                 S   r'   r
   r
   r(   r
   r
   r   r,   N   r-   zETestEulerianCircuit.test_eulerian_circuit_digraph.<locals>.<listcomp>)r7   r4   r5   r6   r   c                 S   r'   r
   r
   r(   r
   r
   r   r,   S   r-   r2   r3   )r   r   	add_cycler;   r<   r=   r
   r
   r   test_eulerian_circuit_digraphI   s   z1TestEulerianCircuit.test_eulerian_circuit_digraphc                 C   st   t  }t |g d |dd |dd tt j|dd}dd |D }|g dks0J |g d	ks8J d S )
NrA   r   r   r   r%   c                 S   r'   r
   r
   r(   r
   r
   r   r,   ]   r-   z7TestEulerianCircuit.test_multigraph.<locals>.<listcomp>r   r   r   r   r   r   )r.   r/   r0   r4   r0   r1   )r   
MultiGraphrB   r   r;   r<   r=   r
   r
   r   test_multigraphW   s   z#TestEulerianCircuit.test_multigraphc                 C   s   t  }t |g d |dd |dd tt j|ddd}dd |D }|g d	ks1J |d d d
dgks=J t|dd tg dksOJ |dd  dgksZJ d S )NrA   r   r   r   T)r&   keysc                 S   s   g | ]\}}}|qS r
   r
   )r)   r*   r+   kr
   r
   r   r,   g   s    zATestEulerianCircuit.test_multigraph_with_keys.<locals>.<listcomp>rD   )r   r   r   )r   r   r   r   ))r   r   r   )r   r   r   )r   r   r   r   r   r   )r   rE   rB   r   r;   r<   collectionsCounterr=   r
   r
   r   test_multigraph_with_keysa   s   
z-TestEulerianCircuit.test_multigraph_with_keysc                 C   sF   t tj tttd}W d    d S 1 sw   Y  d S Nr   )r   r   r   NetworkXErrorr;   r<   r   )r   r   r
   r
   r   test_not_euleriano   s   "z%TestEulerianCircuit.test_not_eulerianN)r!   r"   r#   r@   rC   rF   rL   rO   r
   r
   r
   r   r$   /   s    
r$   c                   @      e Zd Zdd ZdS )TestIsSemiEulerianc                 C   s   t t ds
J t jdt jd}t |sJ t t dr#J t t dr-J t t dr7J t t drAJ d S )Nr   r   Zcreate_usingr   r   )r   is_semieulerianr   r   r   r   r   r
   r
   r   test_is_semieulerianu   s   z'TestIsSemiEulerian.test_is_semieulerianN)r!   r"   r#   rT   r
   r
   r
   r   rQ   t       rQ   c                   @   sh   e Zd Zdd Zdd Zdd Zejde	
 e	 fdd	 Zejde	
 e	 fd
d ZdS )TestHasEulerianPathc                 C   sT   t t ds
J t t dsJ t t dsJ t t ds(J d S )Nr   r   r   r   )r   has_eulerian_pathr   r   r   r
   r
   r   test_has_eulerian_path_cyclic   s   z1TestHasEulerianPath.test_has_eulerian_path_cyclicc                 C   s6   t t ds
J t jdt jd}t |sJ d S )Nr   r   rR   )r   rW   r   r   r   r
   r
   r   !test_has_eulerian_path_non_cyclic   s   z5TestHasEulerianPath.test_has_eulerian_path_non_cyclicc                 C   sd   t  }|g d t |rJ t  }|g d t |s$J |d t |r0J d S )N)r7   r4   r8   )r7   r4   r9   r   )r   r   add_edges_fromrW   add_noder   r
   r
   r   %test_has_eulerian_path_directed_graph   s   
z9TestHasEulerianPath.test_has_eulerian_path_directed_graphr	   c                 C   s    | g d t|rJ d S )N)r7   r5   r/   rZ   r   rW   r   r
   r
   r   +test_has_eulerian_path_not_weakly_connected      z?TestHasEulerianPath.test_has_eulerian_path_not_weakly_connectedc                 C   s    | ddg t|rJ d S Nr7   r5   r]   r   r
   r
   r   2test_has_eulerian_path_unbalancedins_more_than_one   r_   zFTestHasEulerianPath.test_has_eulerian_path_unbalancedins_more_than_oneN)r!   r"   r#   rX   rY   r\   r   markparametrizer   r   r   r^   ra   r
   r
   r
   r   rV      s    
rV   c                   @   rP   )TestFindPathStartc                 C   sj   t jjj}t jdt jd}||dksJ g d}|t |dks$J g d}|t |d u s3J d S )Nr   rR   r   )r7   r4   r9   r   r   r   )r7   r4   r5   )r   r   )r   Z
algorithmsZeulerZ_find_path_startr   r   )r   Zfind_path_startr	   r>   r
   r
   r   testfind_path_start   s   
z%TestFindPathStart.testfind_path_startN)r!   r"   r#   rf   r
   r
   r
   r   rd      rU   rd   c                   @   sj   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	j
dejddgfejddgffdd ZdS )TestEulerianPathc                 C   s8   g d}t |tt|D ]
\}}||ksJ qd S )N)re   r7   r4   r9   )zipr   eulerian_pathr   )r   xe1e2r
   r
   r   test_eulerian_path   s   z#TestEulerianPath.test_eulerian_pathc                 C   s
  t  }g d}|| |tt |ksJ |tt j|ddks%J tt j tt j|dd W d    n1 s?w   Y  tt j tt j|dd W d    n1 s^w   Y  tt j tt j|dd W d    d S 1 s~w   Y  d S )Nr4   r5   r   r   )r   r   r   r%   r   r   r   )r   r   rZ   r;   ri   r   r   rN   r   r	   resultr
   r
   r    test_eulerian_path_straight_link   s   
"z1TestEulerianPath.test_eulerian_path_straight_linkc                 C      t  }g d}|| |tt |ksJ |tt j|ddks%J tt j tt j|dd W d    n1 s?w   Y  tt j tt j|dd W d    d S 1 s_w   Y  d S )N)r0   r4   r0   r4   r5   ro   r   r   r   r%   r   r   )r   r   rZ   r;   ri   r   r   rN   rp   r
   r
   r   test_eulerian_path_multigraph      
"z.TestEulerianPath.test_eulerian_path_multigraphc                 C   s   t  }g d}g d}g d}|| |tt |ks J |tt j|ddks-J |tt j|ddks:J |tt j|ddksGJ d S )N)r4   r5   ro   r   r   )r5   ro   rw   r4   )ro   rw   r4   r5   r   r%   r   r   )r   r   rZ   r;   ri   )r   r	   rq   result2Zresult3r
   r
   r   #test_eulerian_path_eulerian_circuit   s   
z4TestEulerianPath.test_eulerian_path_eulerian_circuitc                 C   s   t  }g d}g d}|| tt |||fv sJ |tt j|ddks+J |tt j|ddks8J tt j tt j|dd W d    n1 sRw   Y  tt j tt j|dd W d    d S 1 srw   Y  d S )Nrn   ))r   r   rt   r/   r0   r   r%   r   r   r   )r   r   rZ   r;   ri   r   r   rN   )r   r	   rq   rx   r
   r
   r   test_eulerian_path_undirected   s   
"z.TestEulerianPath.test_eulerian_path_undirectedc                 C   rs   )N)r0   r4   r0   r4   r5   ro   r   r%   r   r   )r   rE   rZ   r;   ri   r   r   rN   rp   r
   r
   r   (test_eulerian_path_multigraph_undirected   rv   z9TestEulerianPath.test_eulerian_path_multigraph_undirected)
graph_typerq   )r   r   r   )r   r   r   rI   c                 C   s.   |ddg}t j|dd}t||ksJ d S )Nr7   r1   T)rG   )r   ri   r;   )r   r|   rq   r	   Zanswerr
   r
   r   test_eulerian_with_keys   s   z(TestEulerianPath.test_eulerian_with_keysN)r!   r"   r#   rm   rr   ru   ry   rz   r{   r   rb   rc   r   rE   r   r}   r
   r
   r
   r   rg      s    rg   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )TestEulerizec                 C   sJ   t tj tddg}t| W d    d S 1 sw   Y  d S r`   )r   r   r   rN   Zfrom_edgelisteulerizer   r
   r
   r   test_disconnected  s   "zTestEulerize.test_disconnectedc                 C   @   t tj tt  W d    d S 1 sw   Y  d S N)r   r   r   r   r   r   r   r
   r
   r   test_null_graph     "zTestEulerize.test_null_graphc                 C   r   r   )r   r   r   r   r   rE   r   r
   r
   r   test_null_multigraph  r   z!TestEulerize.test_null_multigraphc                 C   sB   t tj ttd W d    d S 1 sw   Y  d S Nr   )r   r   r   rN   r   Zempty_graphr   r
   r
   r   test_on_empty_graph  s   "z TestEulerize.test_on_empty_graphc                 C   s(   t d}t |}t ||sJ d S r   )r   r:   r   Zis_isomorphicr   r	   Hr
   r
   r   test_on_eulerian  s   

zTestEulerize.test_on_eulerianc                 C   s8   t t d}|dd t |}t |sJ d S )Nr   r   r   )r   rE   r:   r   r   r   r   r
   r
   r   test_on_eulerian_multigraph  s   
z(TestEulerize.test_on_eulerian_multigraphc                 C   s<   t d}t t |sJ t t t |sJ d S rM   )r   r   r   r   rE   r   r
   r
   r   test_on_complete_graph#  s   
z#TestEulerize.test_on_complete_graphc                 C   s   t d}|dd |dd |dd |dd |dd |dd |dd	 |d	d
 |d
d |dd |dd |dd |dd t |rZJ t |}t |sfJ t |dksoJ d S )N   r         r                                 '   )r   r:   r   r   r   Znumber_of_edgesr   r
   r
   r   test_on_non_eulerian_graph(  s$   

z'TestEulerize.test_on_non_eulerian_graphN)r!   r"   r#   r   r   r   r   r   r   r   r   r
   r
   r
   r   r~     s    r~   )rJ   r   Znetworkxr   rb   rc   r   rS   r   r   r$   rQ   rV   rd   rg   r~   r
   r
   r
   r   <module>   s    
 E(N