o
    &?e0                     @   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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   i/home/www/facesmatcher.com/pyenv/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                   @   8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )TestRandomGeometricGraphz7Unit tests for :func:`~networkx.random_geometric_graph`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 lTests 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 )BTests 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_names2   s   
**z(TestRandomGeometricGraph.test_node_namesc                 C   2   t jddddd}tdd |j D sJ d S )Nr   r   r   coordsr    pos_namec                 s   $    | ]\}}t |d  dkV  qdS rB   r,   Nr#   r	   ndr   r   r   r   D      " z9TestRandomGeometricGraph.test_pos_name.<locals>.<genexpr>)r!   r"   allr0   itemsr%   r   r   r   test_pos_nameB       z&TestRandomGeometricGraph.test_pos_nameN)	__name__
__module____qualname____doc__r(   r4   r9   r@   rN   r   r   r   r   r      s    r   c                   @   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 )TestSoftRandomGeometricGraphz<Unit tests for :func:`~networkx.soft_random_geometric_graph`c                 C   r   r   )r!   soft_random_geometric_graphr#   r$   r%   r   r   r   r(   J   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!   rU   r   r.   r/   r0   r1   r   r   r   r4   P   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   a   r   zDTestSoftRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r   r   r   r/   `   r   z1TestSoftRandomGeometricGraph.test_p.<locals>.distr   r   r6   r7   r,   r-   N)r!   rU   r   r0   r&   r/   r'   r2   r3   r   r   r   r9   \   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!   rU   r#   r   r.   r/   r0   r?   r   r   r   r@   i   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 )zwTests 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"   rU   r#   edges)r&   r0   r-   ZRGGZSRGGr   rZ   r   test_p_dist_defaultv   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 disconnected 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   rd   r   N)r!   rU   r#   r]   r&   rd   r'   r   r   r   test_p_dist_zero      z-TestSoftRandomGeometricGraph.test_p_dist_zeroc                 C   rA   )Nr   r   r   rB   rC   c                 s   rE   rF   rG   rH   r   r   r   r      rK   z=TestSoftRandomGeometricGraph.test_pos_name.<locals>.<genexpr>)r!   rU   rL   r0   rM   r%   r   r   r   rN      rO   z*TestSoftRandomGeometricGraph.test_pos_nameN)rP   rQ   rR   rS   r(   r4   r9   r@   r^   rh   rN   r   r   r   r   rT   G   s    	rT   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metricZduZdvZu_posZv_posZu_weightZv_weightr   r   r   join   s   rn   c                   @   r   )TestGeographicalThresholdGraphz=Unit tests for :func:`~networkx.geographical_threshold_graph`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 )zoTests that pairs of vertices adjacent if and only if their
        distances meet the given threshold.
        r   
   r,   N)r!   rq   r   rn   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   rr   rm   r,   rs   N)r!   rq   r   r   rn   r1   r   r   r   test_metric   s   z*TestGeographicalThresholdGraph.test_metricc                 C   r_   )r`   c                 S   ra   rb   r   rc   r   r   r   rd      re   z?TestGeographicalThresholdGraph.test_p_dist_zero.<locals>.p_distr   r6   rf   r   N)r!   rq   r#   r]   rg   r   r   r   rh      ri   z/TestGeographicalThresholdGraph.test_p_dist_zeroc                 C   sT   t j}|dddddd}tdd |j D sJ td	d |j D s(J d S )
Nr   rp   r   rB   wtr    rD   Zweight_namec                 s   rE   rF   rG   rH   r   r   r   r      rK   zFTestGeographicalThresholdGraph.test_pos_weight_name.<locals>.<genexpr>c                 s        | ]\}}|d  dkV  qdS rv   r   Nr   rH   r   r   r   r      r   )r!   rq   rL   r0   rM   )r&   Zgtgr'   r   r   r   test_pos_weight_name   s    z3TestGeographicalThresholdGraph.test_pos_weight_nameN)	rP   rQ   rR   rS   r(   r4   ru   rh   rz   r   r   r   r   ro      s    	ro   c                   @   s0   e Zd ZdZd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   r|   )Nr   r}   r~   r6   )Lr   r%   r   r   r   test_number_of_nodes_2   r   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   r}   r~   rt   N)r!   r   r   r#   r%   r   r   r   ru      s   zTestWaxmanGraph.test_metricc                 C   s4   t jdddddd}tdd |j D sJ d S )	Nr   r}   r~   r   rB   rC   c                 s   rE   rF   rG   rH   r   r   r   r      rK   z0TestWaxmanGraph.test_pos_name.<locals>.<genexpr>)r!   r   rL   r0   rM   r%   r   r   r   rN      s    zTestWaxmanGraph.test_pos_nameN)rP   rQ   rR   rS   r   r   ru   rN   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 ||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   r[   )r   r   r   )r!   Znavigable_small_world_graphZgrid_2d_graphZto_directedZis_isomorphicZ
grid_graph)r&   r'   Zggr   r   r   test_navigable_small_world   s   z7TestNavigableSmallWorldGraph.test_navigable_small_worldN)rP   rQ   rR   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 )#TestThresholdedRandomGeometricGraphzCUnit tests for :func:`~networkx.thresholded_random_geometric_graph`c                 C   r|   )Nr   g?r~   r   r   )r!   "thresholded_random_geometric_graphr#   r$   r%   r   r   r   r(      r   z8TestThresholdedRandomGeometricGraph.test_number_of_nodesc                 C   s^   t jddddd}t|dD ]\}}||| v r,t|j| d |j| d dks,J qdS )	r+   r   r   r~   r   r   r,   r-   N)r!   r   r   r.   r/   r0   r1   r   r   r   r4     s   (z2TestThresholdedRandomGeometricGraph.test_distancesc                 C   sf   dd }t jdddddd}t|d	D ]\}}||| v r0||j| d
 |j| d
 dks0J 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   r~   r6   r   )r8   r    r,   r-   Nr!   r   r   r0   rV   r   r   r   r9     s   &z*TestThresholdedRandomGeometricGraph.test_pc                 C   s   ddl }t|j}tj|dd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   r~   r   r   r,   r-   )
r<   r=   r>   r!   r   r#   r   r.   r/   r0   r?   r   r   r   r@     s   
(z3TestThresholdedRandomGeometricGraph.test_node_namesc                 C   sZ   t jdd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   r~   r   r   r,   rj   Nr   r1   r   r   r   
test_theta,  s   $z.TestThresholdedRandomGeometricGraph.test_thetac                 C   sV   t j}|ddddddd}tdd	 |j D sJ td
d	 |j D s)J d S )Nr   r   r~   r   r8   rv   rw   c                 s   rE   )r8   r,   NrG   rH   r   r   r   r   :  rK   zDTestThresholdedRandomGeometricGraph.test_pos_name.<locals>.<genexpr>c                 s   rx   ry   r   rH   r   r   r   r   ;  r   )r!   r   rL   r0   rM   )r&   Ztrggr'   r   r   r   rN   7  s    z1TestThresholdedRandomGeometricGraph.test_pos_nameN)
rP   rQ   rR   rS   r(   r4   r9   r@   r   rN   r   r   r   r   r      s    r   c                  C   sT   t  } | dddifdddifdddifg ddg}|t j| ddd	ks(J d S )
Nr   position)r   r   r6   )r   r6   r,   )r6   r   )r   r,   )radiusrD   )r!   ZGraphZadd_nodes_fromgeometric_edges)r'   Zexpected_edgesr   r   r   "test_geometric_edges_pos_attribute>  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. must have a ')matchr6   )r   )r!   Z
path_graphpytestZraisesZNetworkXErrorr   )r'   msgr   r   r   "test_geometric_edges_raises_no_posK  s
   
"r   )r.   rW   	itertoolsr   r   Znetworkxr!   r   r   rT   rn   ro   r{   r   r   r   r   r   r   r   r   <module>   s    9H4A