o
    ]ZhS                     @   sX   d Z ddlmZ ddlZddlZddlmZ ddlm	Z	 G dd dZ
G dd	 d	ZdS )
z>Unit tests for the :mod:`networkx.algorithms.boundary` module.    )combinationsN)convert_node_labels_to_integers)edges_equalc                   @   sH   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d Z
dS )TestNodeBoundaryz<Unit tests for the :func:`~networkx.node_boundary` function.c                 C   s   t  }t |g t ksJ t |g g t ksJ t |g dt ks(J t |g dg dt ks8J t |g dg dt ksHJ dS )z4Tests that the null graph has empty node boundaries.                  r	   r   r   N)nx
null_graphnode_boundarysetselfnull r   V/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/tests/test_boundary.pytest_null_graph   s    $z TestNodeBoundary.test_null_graphc                 C   s   t tddd}t|g t ksJ t|g g t ks J t|g ddhks-J t|g dddhks;J t|g d	d
dhksIJ t|g ddhksVJ t|g dddgt ksfJ d S )N
   r   Zfirst_labelr   r   r
   r	      r	   r   r   r   r   r      r   	   r   r   )cnltir   
path_graphr   r   r   ZP10r   r   r   test_path_graph   s   $z TestNodeBoundary.test_path_graphc                 C   s   t tddd}t|g t ksJ t|g g t ks J t|g dh dks.J t|g dh dks<J t|g dh d	ksJJ t|g dg t ksXJ t||t kscJ t|g dg d
ddhkstJ d S )Nr   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   complete_graphr   r   )r   K10r   r   r   test_complete_graph"   s   &z$TestNodeBoundary.test_complete_graphc                 C   s   dd }t  }||dtjdddksJ ||dtjdddks$J ||d	tjd
ddks2J ||dtjdddks@J ||dtjdddksNJ dS )zqCheck boundaries in the petersen graph

        cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)

        c                    s   t  fddt D S )Nc                 3   s$    | ]}t t | V  qd S )N)lenr   r   ).0nnGkr   r   	<genexpr>5   s   " zBTestNodeBoundary.test_petersen.<locals>.cheeger.<locals>.<genexpr>)minr   r*   r   r*   r   cheeger4   s   z/TestNodeBoundary.test_petersen.<locals>.cheegerr   g      @g{Gz?)absr   g       @r	   gQ?r   g      ?r   g?N)r   Zpetersen_graphpytestZapprox)r   r/   Pr   r   r   test_petersen-   s    zTestNodeBoundary.test_petersenc                 C   s8   t g d}ddh}t ||}dh}||ksJ dS )z,Tests the node boundary of a directed graph.)r   r   r   r   r   r	   r	   r   )r   r   r   r   r   N)r   DiGraphr   r   r+   Sboundaryexpectedr   r   r   test_directed>   s
   zTestNodeBoundary.test_directedc                 C   sH   t tt d d }ddh}t ||}ddh}||ks"J dS )z(Tests the node boundary of a multigraph.r   r   r   r   r   N)r   
MultiGraphlistcycle_graphedgesr   r9   r   r   r   test_multigraphF   s
   z TestNodeBoundary.test_multigraphc                 C   s@   g d}t |d }ddh}t ||}dh}||ksJ dS )*Tests the edge boundary of a multidigraph.r4   r   r   r   N)r   MultiDiGraphr   r   rA   r+   r:   r;   r<   r   r   r   test_multidigraphN   s   z"TestNodeBoundary.test_multidigraphN)__name__
__module____qualname____doc__r   r#   r&   r3   r=   rB   rF   r   r   r   r   r      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 )TestEdgeBoundaryz<Unit tests for the :func:`~networkx.edge_boundary` function.c                 C   s   t  }tt |g g ksJ tt |g g g ksJ tt |g dg ks+J tt |g dg dg ks<J tt |g dg dg ksMJ d S )Nr   r
   r   )r   r   r?   edge_boundaryr   r   r   r   r   [   s   "&z TestEdgeBoundary.test_null_graphc                 C   s  t tddd}tt|g g ksJ tt|g g g ks"J tt|g ddgks1J tt|g dddgksAJ tt|g d	d
dgksQJ tt|g ddgks`J tt|g dddgg ksqJ tt|g dg dddgksJ d S )Nr   r   r   r   r7   r
   )r   r	   )r   r   r   )r	   r   )r   r   r   )r   r   r   r   r6   )r    r   r!   r?   rL   sortedr"   r   r   r   r#   c   s     "*z TestEdgeBoundary.test_path_graphc                 C   s  t tddd}dd }tt|g g ksJ tt|g g g ks&J |t|g ddks4J |t|g dd	ksBJ |t|g d
dksPJ |t|g ddks^J tt|g dddgg dspJ tt|g dg dg dsJ d S )Nr   r   r   c                 S   s   t dd | D S )Nc                 s   s    | ]}d V  qdS )r   Nr   )r(   ir   r   r   r-   r   s    zETestEdgeBoundary.test_complete_graph.<locals>.ilen.<locals>.<genexpr>)sum)iterabler   r   r   ilenq   s   z2TestEdgeBoundary.test_complete_graph.<locals>.ilenr      )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   r6   )r   r   )r   r   r7   )r	   r   )r    r   r$   r?   rL   r   )r   r%   rQ   r   r   r   r&   n   s    z$TestEdgeBoundary.test_complete_graphc                 C   s<   t g d}ddh}tt ||}dg}||ksJ dS )z,Tests the edge boundary of a directed graph.r4   r   r   r5   N)r   r8   r?   rL   r9   r   r   r   r=      s
   zTestEdgeBoundary.test_directedc                 C   sL   t tt d d }ddh}tt ||}g d}||ks$J dS )z(Tests the edge boundary of a multigraph.r   r   r   r   )r   r   rU   r5   r5   N)r   r>   r?   r@   rA   rL   r9   r   r   r   rB      s
   z TestEdgeBoundary.test_multigraphc                 C   sF   g d}t |d }ddh}tt ||}ddg}||ks!J dS )rC   r4   r   r   r   r5   N)r   rD   r?   rL   rE   r   r   r   rF      s   z"TestEdgeBoundary.test_multidigraphN)
rG   rH   rI   rJ   r   r#   r&   r=   rB   rF   r   r   r   r   rK   X   s    rK   )rJ   	itertoolsr   r1   Znetworkxr   r   r    Znetworkx.utilsr   r   rK   r   r   r   r   <module>   s    L