U
    ?h+                     @   s   d dl Z d dlZd dlmZ d dlZd dlZdd ZG dd dZG dd dZ	d	d
 Z
G dd dZG dd dZG dd dZG dd dZdd ZdS )    N)combinationsc                 C   s   t dd t| |D S )Nc                 s   s   | ]\}}t || V  qd S Nabs.0ab r
   Z/var/www/html/venv/lib/python3.8/site-packages/networkx/generators/tests/test_geometric.py	<genexpr>   s     zl1dist.<locals>.<genexpr>sumzipxyr
   r
   r   l1dist
   s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestRandomGeometricGraphzOUnit tests for the :func:`~networkx.random_geometric_graph`
    function.

    c                 C   sH   t jdddd}t|dks tt jtdddd}t|dksDtd S N2         ?*   seed)nxrandom_geometric_graphlenAssertionErrorrangeselfGr
   r
   r   test_number_of_nodes   s    z-TestRandomGeometricGraph.test_number_of_nodesc                 C   s   t dd}t|dD ]f\}}||| krTt|j| d |j| d dks|tqt|j| d |j| d dkrtqdS mTests that pairs of vertices adjacent if and only if they are
        within the prescribed radius.

        r   r      posN)r   r   r   mathdistnodesr   r!   r"   uvr
   r
   r   test_distances   s
    *z'TestRandomGeometricGraph.test_distancesc                 C   s   t jdddd}t|dD ]b\}}||| krVt|j| d |j| d dks|tqt|j| d |j| d dkrtqdS )TTests for providing an alternate distance metric to the
        generator.

        r   r      pr&   r'   N)r   r   r   r   r*   r   r+   r
   r
   r   test_p*   s
    (zTestRandomGeometricGraph.test_pc                 C   s   ddl }t|j}t|d}t|t|ks2tt|dD ]f\}}||| krzt	|j
| d |j
| d dkstq<t	|j
| d |j
| d dkr<tq<dS =Tests using values other than sequential numbers as node IDs.r   Nr   r&   r'   )stringlistascii_lowercaser   r   r   r   r   r(   r)   r*   r!   r6   r*   r"   r,   r-   r
   r
   r   test_node_names9   s    
*z(TestRandomGeometricGraph.test_node_namesN)__name__
__module____qualname____doc__r#   r.   r3   r:   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 )TestSoftRandomGeometricGraphzTUnit tests for the :func:`~networkx.soft_random_geometric_graph`
    function.

    c                 C   sH   t jdddd}t|dks tt jtdddd}t|dksDtd S r   )r   soft_random_geometric_graphr   r   r   r    r
   r
   r   r#   P   s    z1TestSoftRandomGeometricGraph.test_number_of_nodesc                 C   sX   t dd}t|dD ]<\}}||| krt|j| d |j| d dkstqdS r$   )r   r@   r   r(   r)   r*   r   r+   r
   r
   r   r.   V   s    z+TestSoftRandomGeometricGraph.test_distancesc                 C   sb   dd }t jdddd}t|dD ]:\}}||| kr"||j| d |j| d dks"tq"d	S )
r/   c                 S   s   t dd t| |D S )Nc                 s   s   | ]\}}t || V  qd S r   r   r   r
   r
   r   r   k   s     zDTestSoftRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r
   r
   r   r)   j   s    z1TestSoftRandomGeometricGraph.test_p.<locals>.distr   r   r0   r1   r&   r'   N)r   r@   r   r*   r   r!   r)   r"   r,   r-   r
   r
   r   r3   c   s
    z#TestSoftRandomGeometricGraph.test_pc                 C   s~   ddl }t|j}t|d}t|t|ks2tt|dD ]<\}}||| kr<t	|j
| d |j
| d dks<tq<dS r4   )r6   r7   r8   r   r@   r   r   r   r(   r)   r*   r9   r
   r
   r   r:   s   s    
z,TestSoftRandomGeometricGraph.test_node_namesc                    s^   d}d  fddt |D }tjdd|d}tjdd|d}t| t| ksZtdS )zxTests default p_dict = 0.5 returns graph with edge count <= RGG with
        same n, radius, dim and positions

        r   r&   c                    s    i | ]}|d d t  D qS )c                 S   s   g | ]}t   qS r
   )random)r   ir
   r
   r   
<listcomp>   s     zOTestSoftRandomGeometricGraph.test_p_dist_default.<locals>.<dictcomp>.<listcomp>)r   )r   r-   dimr
   r   
<dictcomp>   s      zDTestSoftRandomGeometricGraph.test_p_dist_default.<locals>.<dictcomp>r   )r'   N)r   r   r   r@   r   edgesr   )r!   r*   r'   ZRGGZSRGGr
   rE   r   test_p_dist_default   s    z0TestSoftRandomGeometricGraph.test_p_dist_defaultc                 C   s.   dd }t jdd|d}t|jdks*tdS );Tests if p_dict = 0 returns disconnected graph with 0 edgesc                 S   s   dS Nr   r
   r)   r
   r
   r   p_dist   s    z=TestSoftRandomGeometricGraph.test_p_dist_zero.<locals>.p_distr   r   rM   r   N)r   r@   r   rH   r   r!   rM   r"   r
   r
   r   test_p_dist_zero   s    z-TestSoftRandomGeometricGraph.test_p_dist_zeroN)
r;   r<   r=   r>   r#   r.   r3   r:   rI   rP   r
   r
   r
   r   r?   J   s   r?   c                 C   sT   | j | | j |  }}|d |d  }}	|d |d  }
}|
| |||	|  |kS )a  Returns ``True`` if and only if the nodes whose attributes are
    ``du`` and ``dv`` should be joined, according to the threshold
    condition for geographical threshold graphs.

    ``G`` is an undirected NetworkX graph, and ``u`` and ``v`` are nodes
    in that graph. The nodes must have node attributes ``'pos'`` and
    ``'weight'``.

    ``metric`` is a distance metric.

    r'   weight)r*   )r"   r,   r-   thetaalphametricZduZdvZu_posZv_posZu_weightZv_weightr
   r
   r   join   s    rU   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestGeographicalThresholdGraphzUUnit tests for the :func:`~networkx.geographical_threshold_graph`
    function.

    c                 C   sH   t jdddd}t|dks tt jtdddd}t|dksDtd S )Nr   d   r   r   )r   geographical_threshold_graphr   r   r   r    r
   r
   r   r#      s    z3TestGeographicalThresholdGraph.test_number_of_nodesc                 C   sb   t dd}t|dD ]F\}}||| krDt|||ddtjs\tqt|||ddtjrtqdS )zpTests that pairs of vertices adjacent if and only if their
        distances meet the given threshold.

        r   
   r&   N)r   rX   r   rU   r(   r)   r   r+   r
   r
   r   r.      s
    z-TestGeographicalThresholdGraph.test_distancesc                 C   sb   t jddtd}t|dD ]B\}}||| krFt|||ddts\tqt|||ddtrtqdS )r/   r   rY   rT   r&   rZ   N)r   rX   r   r   rU   r   r+   r
   r
   r   test_metric   s
    z*TestGeographicalThresholdGraph.test_metricc                 C   s.   dd }t jdd|d}t|jdks*tdS )rJ   c                 S   s   dS rK   r
   rL   r
   r
   r   rM      s    z?TestGeographicalThresholdGraph.test_p_dist_zero.<locals>.p_distr   r0   rN   r   N)r   rX   r   rH   r   rO   r
   r
   r   rP      s    z/TestGeographicalThresholdGraph.test_p_dist_zeroN)r;   r<   r=   r>   r#   r.   r\   rP   r
   r
   r
   r   rV      s
   rV   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestWaxmanGraphz;Unit tests for the :func:`~networkx.waxman_graph` function.c                 C   sL   t jddddd}t|dks"tt jtddddd}t|dksHtd S )Nr         ?皙?r   r   r   waxman_graphr   r   r   r    r
   r
   r   test_number_of_nodes_1   s    z&TestWaxmanGraph.test_number_of_nodes_1c                 C   sL   t jddddd}t|dks"tt jtddddd}t|dksHtd S )Nr   r^   r_   r0   )Lr`   r    r
   r
   r   test_number_of_nodes_2   s    z&TestWaxmanGraph.test_number_of_nodes_2c                 C   s&   t jdddtd}t|dks"tdS )r/   r   r^   r_   r[   N)r   ra   r   r   r   r    r
   r
   r   r\      s    zTestWaxmanGraph.test_metricN)r;   r<   r=   r>   rb   rd   r\   r
   r
   r
   r   r]      s   r]   c                   @   s   e Zd Zdd ZdS )TestNavigableSmallWorldGraphc                 C   s   t jddddd}t dd }t ||s2tt jddddd}t dddg }t ||shtt jddddd}t dg }t ||std S )N   r0   r   r   )r2   qr      )r2   rg   rF   )r   Znavigable_small_world_graphZgrid_2d_graphZto_directedZis_isomorphicr   Z
grid_graph)r!   r"   Zggr
   r
   r   test_navigable_small_world   s    z7TestNavigableSmallWorldGraph.test_navigable_small_worldN)r;   r<   r=   ri   r
   r
   r
   r   re      s   re   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )#TestThresholdedRandomGeometricGraphz[Unit tests for the :func:`~networkx.thresholded_random_geometric_graph`
    function.

    c                 C   sH   t jddddd}t|dks"tt tddd}t|dksDtd S )Nr   g?r_   r   r   )r   "thresholded_random_geometric_graphr   r   r   r    r
   r
   r   r#     s    z8TestThresholdedRandomGeometricGraph.test_number_of_nodesc                 C   sZ   t ddd}t|dD ]<\}}||| krt|j| d |j| d dkstqdS )r%   r   r   r_   r&   r'   N)r   rk   r   r(   r)   r*   r   r+   r
   r
   r   r.     s    z2TestThresholdedRandomGeometricGraph.test_distancesc                 C   sd   dd }t jddddd}t|dD ]:\}}||| kr$||j| d	 |j| d	 dks$tq$d
S )r/   c                 S   s   t dd t| |D S )Nc                 s   s   | ]\}}t || V  qd S r   r   r   r
   r
   r   r   &  s     zKTestThresholdedRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r
   r
   r   r)   %  s    z8TestThresholdedRandomGeometricGraph.test_p.<locals>.distr   r   r_   r0   r1   r&   r'   Nr   rk   r   r*   r   rA   r
   r
   r   r3     s
    z*TestThresholdedRandomGeometricGraph.test_pc                 C   s   ddl }t|j}t|dd}t|t|ks4tt|dD ]<\}}||| kr>t	|j
| d |j
| d dks>tq>dS )r5   r   Nr   r_   r&   r'   )r6   r7   r8   r   rk   r   r   r   r(   r)   r*   r9   r
   r
   r   r:   .  s    
z3TestThresholdedRandomGeometricGraph.test_node_namesc                 C   sV   t ddd}t|dD ]8\}}||| kr|j| d |j| d  dkstqdS )z~Tests that pairs of vertices adjacent if and only if their sum
        weights exceeds the threshold parameter theta.
        r   r   r_   r&   rQ   Nrl   r+   r
   r
   r   
test_theta;  s    z.TestThresholdedRandomGeometricGraph.test_thetaN)	r;   r<   r=   r>   r#   r.   r3   r:   rm   r
   r
   r
   r   rj     s   rj   c               	   C   s<   t d} d}tjt j|d t j| dd W 5 Q R X d S )Nrh   z,All nodes in `G` must have a 'pos' attribute)matchr0   )Zradius)r   Z
path_graphpytestZraisesZNetworkXErrorZgeometric_edges)r"   msgr
   r
   r   "test_geometric_edges_raises_no_posG  s    
rq   )r(   rB   	itertoolsr   ro   Znetworkxr   r   r   r?   rU   rV   r]   re   rj   rq   r
   r
   r
   r   <module>   s   <L5B