o
    ]Zh#                     @   s0   d dl Z d dlZG dd dZG dd dZdS )    Nc                   @   sT   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d ZdS )TestImmediateDominatorsc                 C   l   t  }|d tt jt j|d t |}tt jt j|d t ddgg}tt j	t j|d d S Nr      )
nxGraphadd_nodepytestraisesNetworkXNotImplementedimmediate_dominators
MultiGraphDiGraphNetworkXErrorselfG r   W/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/tests/test_dominance.pytest_exceptions      

z'TestImmediateDominators.test_exceptionsc                 C   sR   t  }|d t |dddiksJ |dd t |dddiks'J d S Nr   )r   r   r   r   add_edger   r   r   r   test_singleton   s
   
z&TestImmediateDominators.test_singletonc                 C   <   d}t j|t  d}t |ddd t|D ksJ d S )N   Zcreate_usingr   c                 S      i | ]
}|t |d  dqS r   r   max.0ir   r   r   
<dictcomp>       z5TestImmediateDominators.test_path.<locals>.<dictcomp>r   
path_graphr   r   ranger   nr   r   r   r   	test_path      &z!TestImmediateDominators.test_pathc                 C   r   )Nr   r   r   c                 S   r   r   r   r!   r   r   r   r$      r%   z6TestImmediateDominators.test_cycle.<locals>.<dictcomp>)r   cycle_graphr   r   r(   r)   r   r   r   
test_cycle   r,   z"TestImmediateDominators.test_cyclec                    sV   d  dksJ t j t  d}t | d  fddt d  D ks)J d S )Nr   r   r      c                    s    i | ]}|t |d   d qS r   r/   r   r!   r*   r   r   r$   %   s    z<TestImmediateDominators.test_unreachable.<locals>.<dictcomp>r&   r   r   r1   r   test_unreachable!   s   z(TestImmediateDominators.test_unreachablec                 C   s:   g d}t |}t |ddd tddD ksJ dS )
        Graph taken from figure 2 of "A simple, fast dominance algorithm." (2006).
        https://hdl.handle.net/1911/96345
        r0   r/   r      r/   )   r   )r   r7   )r   r8   r   c                 S      i | ]}|d qS )r   r   r!   r   r   r   r$   0       z=TestImmediateDominators.test_irreducible1.<locals>.<dictcomp>r      Nr   r   r   r(   r   edgesr   r   r   r   test_irreducible1)   s   
(z)TestImmediateDominators.test_irreducible1c                 C   s>   g d}t |}t |d}|dd tddD ksJ dS )
        Graph taken from figure 4 of "A simple, fast dominance algorithm." (2006).
        https://hdl.handle.net/1911/96345
        	r0   r5   r/   r7   r6   )r8   r/   )r8   r7   )r   r   r;   r8   )r;   r   r;   c                 S   r9   )r;   r   r!   r   r   r   r$   ;   r:   z=TestImmediateDominators.test_irreducible2.<locals>.<dictcomp>r      Nr<   r   r>   r   resultr   r   r   test_irreducible22   s   
 z)TestImmediateDominators.test_irreducible2c                 C   sj   g d}t |}t |d}|dddddddksJ t |jddd}|dddddddks3J d S )	Nr0   rB   )r/   r8   )r/   r;   )r7   r   r8   r   )r   r/   r   r/   r   r/   r7   r8   r   r;   Fcopyr;   r   r   r   r   reverserE   r   r   r   test_domrel_png=   s   
z'TestImmediateDominators.test_domrel_pngc              
   C   sr   g d}t |}t |d}|dddddddddksJ t |jddd	}|dd	d	dd
d	dd	dks7J d S )N	)r   r   r0   )r   r7   )r/   rD   )r7   r8   rI   )r8   r;   )r   rD   rC   r   r   r7   r8   r   r   r/   r7   r8   r   r;   rD   FrK   rD   r   rM   rE   r   r   r   test_boost_exampleG   s   
"z*TestImmediateDominators.test_boost_exampleN)__name__
__module____qualname__r   r   r+   r.   r2   r?   rG   rO   rR   r   r   r   r   r      s    		
r   c                   @   st   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d Zdd Zdd Zdd Zdd ZdS )TestDominanceFrontiersc                 C   r   r   )
r   r   r   r	   r
   r   dominance_frontiersr   r   r   r   r   r   r   r   T   r   z&TestDominanceFrontiers.test_exceptionsc                 C   sV   t  }|d t |ddt iksJ |dd t |ddt iks)J d S r   )r   r   r   rW   setr   r   r   r   r   r   ]   s
   
z%TestDominanceFrontiers.test_singletonc                 C   r   )Nr   r   r   c                 S      i | ]}|t  qS r   rX   r!   r   r   r   r$   g       z4TestDominanceFrontiers.test_path.<locals>.<dictcomp>r   r'   r   rW   r(   r)   r   r   r   r+   d   r,   z TestDominanceFrontiers.test_pathc                 C   r   )Nr   r   r   c                 S   rY   r   rZ   r!   r   r   r   r$   l   r[   z5TestDominanceFrontiers.test_cycle.<locals>.<dictcomp>)r   r-   r   rW   r(   r)   r   r   r   r.   i   r,   z!TestDominanceFrontiers.test_cyclec                 C   sR   d}|dksJ t j|t  d}t ||d dd t|d |D ks'J d S )Nr   r   r   r/   c                 S   rY   r   rZ   r!   r   r   r   r$   r   r[   z;TestDominanceFrontiers.test_unreachable.<locals>.<dictcomp>r\   r)   r   r   r   r2   n   s   0z'TestDominanceFrontiers.test_unreachablec                 C   sH   g d}t |}tt |d dhdhdhdht dks"J dS )r3   r4   r   r/   r   )r   r/   r7   r8   r   N)r   r   dictrW   itemsrX   r=   r   r   r   r?   t   s   
z(TestDominanceFrontiers.test_irreducible1c                 C   sH   g d}t |}t |ddhddhdhddhdht dks"J dS )r@   rA   r;   r/   r   r7   rJ   N)r   r   rW   rX   r=   r   r   r   rG      s   

z(TestDominanceFrontiers.test_irreducible2c                 C   s~   g d}t |}t |dt dhdhdhdht dks J t |jddd}|t dhdhdhdht dks=J d S )	NrH   r   r/   r   rJ   FrK   r;   r   r   rW   rX   rN   rE   r   r   r   rO      s   

	*z&TestDominanceFrontiers.test_domrel_pngc              
   C   s   g d}t |}t |dt t dhdhddhdhdht dks%J t |jddd}t t dhdhddhdhdht d}||ksIJ d S )	NrP   r   rD   r8   rQ   FrK   r   r_   )r   r>   r   rF   expectedr   r   r   rR      s.   


z)TestDominanceFrontiers.test_boost_examplec                 C   sX   t  }|g d t |d}|t dhdhdht dhdhdhdhd	ks*J d S )N))b0b1rb   b2rd   b3)rf   rb   )rb   b5)rg   b6)rg   b8)rh   b7)ri   rj   )rj   rf   )rf   b4ra   rf   rj   rb   )	rk   rg   rh   rj   ra   rb   rd   rf   ri   r   r   add_edges_fromrW   rX   r   gdfr   r   r   test_discard_issue   s    z)TestDominanceFrontiers.test_discard_issuec                 C   s@   t  }|g d t |d}|t t t dksJ d S )N))ab)rs   c)rs   rr   rr   )rr   rs   rt   rl   rn   r   r   r   	test_loop   s   z TestDominanceFrontiers.test_loopc                 C   s*   t  }g d}|| t |d d S )N))entry_1rb   rc   re   )rf   exit)Zentry_2rf   rv   )r   r   rm   rW   )r   ro   r>   r   r   r   test_missing_immediate_doms   s   
z2TestDominanceFrontiers.test_missing_immediate_domsc              	   C   s   t  }g d}|| t |d}t dhddhh dh dh dddht d}|D ]}t|| t|| ks=J q-d S )N))entryrw   )ry   1)rz   2)r{   3)r|   4)r}   5)r~   6)r   rw   )r   r{   )r~   r|   )r}   r}   ry   rw   r{   >   r|   r{   rw   >   r|   r{   r}   rw   )ry   rz   r{   r|   r}   r~   r   rw   rl   )r   ro   r>   rp   Zanswerr*   r   r   r   test_loops_larger   s    

z(TestDominanceFrontiers.test_loops_largerN)rS   rT   rU   r   r   r+   r.   r2   r?   rG   rO   rR   rq   ru   rx   r   r   r   r   r   rV   S   s    	rV   )r	   Znetworkxr   r   rV   r   r   r   r   <module>   s    M