o
    ˷e+                     @   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      t dd t| |D S )Nc                 s        | ]\}}t || V  qd S Nabs.0ab r   _/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/generators/tests/test_geometric.py	<genexpr>       zl1dist.<locals>.<genexpr>sumzipxyr   r   r   l1dist
      r   c                   @   0   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   H   t jdddd}t|dksJ t jtdddd}t|dks"J d S N2         ?*   seed)nxrandom_geometric_graphlenrangeselfGr   r   r   test_number_of_nodes      z-TestRandomGeometricGraph.test_number_of_nodesc                 C   s   t dd}t|dD ]3\}}||| v r*t|j| d |j| d dks)J qt|j| d |j| d dkr>J 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nodesr&   r'   uvr   r   r   test_distances   s   **z'TestRandomGeometricGraph.test_distancesc                 C   s   t jdddd}t|dD ]1\}}||| v r+t|j| d |j| d dks*J qt|j| d |j| d dkr>J qdS )TTests for providing an alternate distance metric to the
        generator.

        r   r      pr,   r-   N)r!   r"   r   r   r0   r1   r   r   r   test_p*   s   ((zTestRandomGeometricGraph.test_pc                 C   s   ddl }t|j}t|d}t|t|ksJ t|dD ]3\}}||| v r=t|j	| d |j	| d dks<J qt|j	| d |j	| d dkrQJ 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/   r0   r&   r<   r0   r'   r2   r3   r   r   r   test_node_names9   s   
**z(TestRandomGeometricGraph.test_node_namesN)__name__
__module____qualname____doc__r(   r4   r9   r@   r   r   r   r   r          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   r   r   )r!   soft_random_geometric_graphr#   r$   r%   r   r   r   r(   P   r)   z1TestSoftRandomGeometricGraph.test_number_of_nodesc                 C   sX   t dd}t|dD ]\}}||| v r)t|j| d |j| d dks)J qdS r*   )r!   rG   r   r.   r/   r0   r1   r   r   r   r4   V   s   (z+TestSoftRandomGeometricGraph.test_distancesc                 C   sb   dd }t jdddd}t|dD ]\}}||| v r.||j| d |j| d dks.J qd	S )
r5   c                 S   r   )Nc                 s   r   r   r   r   r   r   r   r   j   r   zDTestSoftRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r   r   r   r/   i   r   z1TestSoftRandomGeometricGraph.test_p.<locals>.distr   r   r6   r7   r,   r-   N)r!   rG   r   r0   r&   r/   r'   r2   r3   r   r   r   r9   c   s   &z#TestSoftRandomGeometricGraph.test_pc                 C   s~   ddl }t|j}t|d}t|t|ksJ t|dD ]\}}||| v r<t|j	| d |j	| d dks<J qdS r:   )
r<   r=   r>   r!   rG   r#   r   r.   r/   r0   r?   r   r   r   r@   r   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s-J 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	   r3   dimr   r   
<dictcomp>   s     zDTestSoftRandomGeometricGraph.test_p_dist_default.<locals>.<dictcomp>r   )r-   N)r$   r!   r"   rG   r#   edges)r&   r0   r-   RGGSRGGr   rL   r   test_p_dist_default   s    z0TestSoftRandomGeometricGraph.test_p_dist_defaultc                 C   .   dd }t jdd|d}t|jdksJ dS );Tests if p_dict = 0 returns disconencted graph with 0 edgesc                 S      dS Nr   r   r/   r   r   r   p_dist      z=TestSoftRandomGeometricGraph.test_p_dist_zero.<locals>.p_distr   r   rX   r   N)r!   rG   r#   rO   r&   rX   r'   r   r   r   test_p_dist_zero      z-TestSoftRandomGeometricGraph.test_p_dist_zeroN)
rA   rB   rC   rD   r(   r4   r9   r@   rR   r\   r   r   r   r   rF   J   s    rF   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)r0   )r'   r2   r3   thetaalphametricdudvu_posv_posu_weightv_weightr   r   r   join   s   rh   c                   @   r   )TestGeographicalThresholdGraphzUUnit tests for the :func:`~networkx.geographical_threshold_graph`
    function.

    c                 C   r   )Nr   d   r   r   )r!   geographical_threshold_graphr#   r$   r%   r   r   r   r(      r)   z3TestGeographicalThresholdGraph.test_number_of_nodesc                 C   sb   t dd}t|dD ]#\}}||| v r"t|||ddtjs!J qt|||ddtjr.J qdS )zpTests that pairs of vertices adjacent if and only if their
        distances meet the given threshold.

        r   
   r,   N)r!   rk   r   rh   r.   r/   r1   r   r   r   r4      s   z-TestGeographicalThresholdGraph.test_distancesc                 C   sb   t jddtd}t|dD ]!\}}||| v r#t|||ddts"J qt|||ddtr.J qdS )r5   r   rl   ra   r,   rm   N)r!   rk   r   r   rh   r1   r   r   r   test_metric   s   z*TestGeographicalThresholdGraph.test_metricc                 C   rS   )rT   c                 S   rU   rV   r   rW   r   r   r   rX      rY   z?TestGeographicalThresholdGraph.test_p_dist_zero.<locals>.p_distr   r6   rZ   r   N)r!   rk   r#   rO   r[   r   r   r   r\      r]   z/TestGeographicalThresholdGraph.test_p_dist_zeroN)rA   rB   rC   rD   r(   r4   ro   r\   r   r   r   r   ri      rE   ri   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   L   t jddddd}t|dksJ t jtddddd}t|dks$J d S )Nr         ?皙?r   r   r!   waxman_graphr#   r$   r%   r   r   r   test_number_of_nodes_1      z&TestWaxmanGraph.test_number_of_nodes_1c                 C   rq   )Nr   rr   rs   r6   )Lrt   r%   r   r   r   test_number_of_nodes_2   rw   z&TestWaxmanGraph.test_number_of_nodes_2c                 C   s&   t jdddtd}t|dksJ dS )r5   r   rr   rs   rn   N)r!   ru   r   r#   r%   r   r   r   ro      s   zTestWaxmanGraph.test_metricN)rA   rB   rC   rD   rv   ry   ro   r   r   r   r   rp      s
    rp   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 ||sJ t jddddd}t g d }t ||s3J t jddddd}t dg }t ||sLJ d S )	N   r6   r   r   )r8   qr       )r8   r|   rM   )r{   r{   r{   )r!   navigable_small_world_graphgrid_2d_graphto_directedis_isomorphic
grid_graph)r&   r'   ggr   r   r   test_navigable_small_world   s   z7TestNavigableSmallWorldGraph.test_navigable_small_worldN)rA   rB   rC   r   r   r   r   r   rz      s    rz   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J t tddd}t|dks"J d S )Nr   g?rs   r   r   )r!   "thresholded_random_geometric_graphr#   r$   r%   r   r   r   r(   
  s   z8TestThresholdedRandomGeometricGraph.test_number_of_nodesc                 C   sZ   t ddd}t|dD ]\}}||| v r*t|j| d |j| d dks*J qdS )r+   r   r   rs   r,   r-   N)r!   r   r   r.   r/   r0   r1   r   r   r   r4     s   (z2TestThresholdedRandomGeometricGraph.test_distancesc                 C   sd   dd }t jddddd}t|dD ]\}}||| v r/||j| d	 |j| d	 dks/J qd
S )r5   c                 S   r   )Nc                 s   r   r   r   r   r   r   r   r   $  r   zKTestThresholdedRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r   r   r   r/   #  r   z8TestThresholdedRandomGeometricGraph.test_p.<locals>.distr   r   rs   r6   r7   r,   r-   Nr!   r   r   r0   rH   r   r   r   r9     s   &z*TestThresholdedRandomGeometricGraph.test_pc                 C   s   ddl }t|j}t|dd}t|t|ksJ t|dD ]\}}||| v r=t|j	| d |j	| d dks=J qdS )r;   r   Nr   rs   r,   r-   )
r<   r=   r>   r!   r   r#   r   r.   r/   r0   r?   r   r   r   r@   ,  s   
(z3TestThresholdedRandomGeometricGraph.test_node_namesc                 C   sV   t ddd}t|dD ]\}}||| v r(|j| d |j| d  dks(J qdS )z~Tests that pairs of vertices adjacent if and only if their sum
        weights exceeds the threshold parameter theta.
        r   r   rs   r,   r^   Nr   r1   r   r   r   
test_theta9  s   $z.TestThresholdedRandomGeometricGraph.test_thetaN)	rA   rB   rC   rD   r(   r4   r9   r@   r   r   r   r   r   r     s    r   c                  C   sR   t d} d}tjt j|d t j| dd W d    d S 1 s"w   Y  d S )Nr}   z,All nodes in `G` must have a 'pos' attribute)matchr6   )radius)r!   
path_graphpytestraisesNetworkXErrorgeometric_edges)r'   msgr   r   r   "test_geometric_edges_raises_no_posE  s
   
"r   )r.   rI   	itertoolsr   r   networkxr!   r   r   rF   rh   ri   rp   rz   r   r   r   r   r   r   <module>   s    <K5A