U
    ?hS                     @   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tt |g g t ks6tt |dddgt ksRtt |dddgdddgt ksvtt |dddgdddgt kstdS )z4Tests that the null graph has empty node boundaries.                  N)nx
null_graphnode_boundarysetAssertionErrorselfnull r   Y/var/www/html/venv/lib/python3.8/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(tt|g g t ks@tt|dddgdhks\tt|dddgdd	hksztt|ddddd	gdd
hkstt|d
ddgd	hkstt|dddgddgt kstd S N
   r   Zfirst_labelr   r   r	   r
   r         	   )cnltir   
path_graphr   r   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(tt|g g t ks@tt|dddgdddd	d
ddhkshtt|dddgdddd	d
ddhkstt|ddddd	gddd
ddhkstt|dddgg t kstt||t kstt|dddgdddgddhkstd S r   )r   r   complete_graphr   r   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,t||dtjdddksHt||d	tjd
ddksdt||dtjdddkst||dtjdddkst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approxr   )r   r,   Pr   r   r   test_petersen-   s    zTestNodeBoundary.test_petersenc                 C   s>   t dddddg}ddh}t ||}dh}||ks:t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   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sDtdS )z(Tests the node boundary of a multigraph.r
   r   r   r   r	   N)r   
MultiGraphlistcycle_graphedgesr   r   r7   r   r   r   test_multigraphF   s
    z TestNodeBoundary.test_multigraphc                 C   sF   dddddg}t |d }ddh}t ||}dh}||ksBtd	S 
z*Tests the edge boundary of a multdiigraph.r1   r2   r3   r4   r5   r   r   r   N)r   MultiDiGraphr   r   r   r?   r(   r8   r9   r:   r   r   r   test_multidigraphN   s    z"TestNodeBoundary.test_multidigraphN)__name__
__module____qualname____doc__r   r    r#   r0   r;   r@   rD   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 ttt |g g g ks:ttt |dddgg ksXttt |dddgdddgg ks~ttt |dddgdddgg kstd S )Nr   r   r   r	   r
   r   )r   r   r=   edge_boundaryr   r   r   r   r   r   [   s    &z TestEdgeBoundary.test_null_graphc              	   C   s   t tddd}tt|g g ks*ttt|g g g ksDttt|dddgdgksdttt|ddd	gd
dgksttt|dddd	dgddgksttt|dddgdgksttt|ddd	gddgg ksttt|dddgdddgddgkstd S )Nr   r   r   r   r   r4   r	   r
   r   )r	   r   )r   r   r   )r   r   )r   r   r   r   )r   r   r3   )r   r   r   r=   rJ   r   sortedr   r   r   r   r    c   s     "& $z TestEdgeBoundary.test_path_graphc              
   C   s2  t tddd}dd }tt|g g ks2ttt|g g g ksLt|t|dddgdksjt|t|d	d
ddgdkst|t|dd	d
ddgdkst|t|dddgdksttt|d	d
dgddgddddddgsttt|dddgdd	d
gddddddddgs.t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
   r3   )r   r	   )r   r
   r4   )r   r
   )r   r   r!   r=   rJ   r   r   )r   r"   rO   r   r   r   r#   n   s      "z$TestEdgeBoundary.test_complete_graphc                 C   sB   t dddddg}ddh}tt ||}dg}||ks>tdS )	z,Tests the edge boundary of a directed graph.r1   r2   r3   r4   r5   r   r   N)r   r6   r=   rJ   r   r7   r   r   r   r;      s
    zTestEdgeBoundary.test_directedc                 C   sP   t tt d d }ddh}tt ||}ddddg}||ksLtdS )z(Tests the edge boundary of a multigraph.r
   r   r   r   )r   r	   r2   N)r   r<   r=   r>   r?   rJ   r   r7   r   r   r   r@      s
    z TestEdgeBoundary.test_multigraphc                 C   sL   dddddg}t |d }ddh}tt ||}ddg}||ksHtd	S rA   )r   rB   r=   rJ   r   rC   r   r   r   rD      s    z"TestEdgeBoundary.test_multidigraphN)
rE   rF   rG   rH   r   r    r#   r;   r@   rD   r   r   r   r   rI   X   s   rI   )rH   	itertoolsr   r.   Znetworkxr   r   r   Znetworkx.utilsr   r   rI   r   r   r   r   <module>   s   L