o
    ]ZhF                     @   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d Zdd Zd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 )+    N)combinationsc                 C      t dd t| |D S )Nc                 s        | ]\}}t || V  qd S Nabs.0ab r   W/var/www/auris/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   r[   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   re   r   N)r!   rU   r#   r^   r&   re   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_   ri   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   ro   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!   rr   r   ro   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   rs   rn   r,   rt   N)r!   rr   r   r   ro   r1   r   r   r   test_metric   s   z*TestGeographicalThresholdGraph.test_metricc                 C   r`   )ra   c                 S   rb   rc   r   rd   r   r   r   re      rf   z?TestGeographicalThresholdGraph.test_p_dist_zero.<locals>.p_distr   r6   rg   r   N)r!   rr   r#   r^   rh   r   r   r   ri      rj   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   rq   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 rw   r   Nr   rH   r   r   r   r      r   )r!   rr   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   rv   ri   r{   r   r   r   r   rp      s    	rp   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   ru   N)r!   r   r   r#   r%   r   r   r   rv      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   rv   rN   r   r   r   r   r|      s    r|   c                   @   sR   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
deddd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!   navigable_small_world_graphgrid_2d_graphZto_directedZis_isomorphicZ
grid_graph)r&   r'   Zggr   r   r   test_navigable_small_world   s   z7TestNavigableSmallWorldGraph.test_navigable_small_worldc                 C   sH   t jtjdd tjddddd W d    d S 1 sw   Y  d S )Nz.*p must be >= 1matchr   r   r6   r   pytestraisesr!   ZNetworkXExceptionr   r&   r   r   r   test_invalid_diameter_value      "z8TestNavigableSmallWorldGraph.test_invalid_diameter_valuec                 C   sH   t jtjdd tjddddd W d    d S 1 sw   Y  d S )Nz.*q must be >= 0r   r   r6   r   r   r   r   r   r   )test_invalid_long_range_connections_value   r   zFTestNavigableSmallWorldGraph.test_invalid_long_range_connections_valuec                 C   sJ   t jtjdd tjdddddd W d    d S 1 sw   Y  d S )Nz.*r must be >= 0r   r   r6   r   r   )r8   r   rr\   r   r   r   r   r   4test_invalid_exponent_for_decaying_probability_value  s   "zQTestNavigableSmallWorldGraph.test_invalid_exponent_for_decaying_probability_valuec                 C   s>   t jddddddd}t jddt jd}t j||sJ d	S )
z%Smoke test for radius in range [0, 1]r   r6   r   r~   r,   r   )r8   r   r   r\   r    )Zcreate_usingN)r!   r   r   ZDiGraphutilsZgraphs_equal)r&   r'   expectedr   r   r   test_r_between_0_and_1  s   z3TestNavigableSmallWorldGraph.test_r_between_0_and_1r    i	  i
  rs   c                 C   sb   t jddd|d}t jddd|d}t jddd|d}| | ks%J | | ks/J dS )aG  The probability of adding a long-range edge scales with `1 / dist**r`,
        so a navigable_small_world graph created with r < 1 should generally
        result in more edges than a navigable_small_world graph with r >= 1
        (for 0 < q << n).

        N.B. this is probabilistic, so this test may not hold for all seeds.   r   r~   )r   r   r    r6   r,   N)r!   r   Znumber_of_edges)r&   r    G1G2ZG3r   r   r   test_r_general_scaling  s
   z3TestNavigableSmallWorldGraph.test_r_general_scalingN)rP   rQ   rR   r   r   r   r   r   r   markZparametrizer$   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   8  r   zKTestThresholdedRandomGeometricGraph.test_p.<locals>.dist.<locals>.<genexpr>r   r   r   r   r   r/   7  r   z8TestThresholdedRandomGeometricGraph.test_p.<locals>.distr   r   r   r6   r   )r8   r    r,   r-   Nr!   r   r   r0   rV   r   r   r   r9   3  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,   rk   Nr   r1   r   r   r   
test_thetaM  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   rw   rx   c                 s   rE   )r8   r,   NrG   rH   r   r   r   r   [  rK   zDTestThresholdedRandomGeometricGraph.test_pos_name.<locals>.<genexpr>c                 s   ry   rz   r   rH   r   r   r   r   \  r   )r!   r   rL   r0   rM   )r&   Ztrggr'   r   r   r   rN   X  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 'r   r6   )r   )r!   Z
path_graphr   r   NetworkXErrorr   )r'   msgr   r   r   "test_geometric_edges_raises_no_posl  s
   
"r   c                  C   s(   t jdddddd} t| dksJ d S )N      ?rq   皙@rs   r   betarI   gammamean_degreer    )r!   "geometric_soft_configuration_graphr#   r'   r   r   r   test_number_of_nodes_S1s  s   
r   c                  C   sl   t jdddddd} t | d}t|dksJ t | d}t|dks&J t | d	}t|dks4J d S )
Nr   rq   r   rs   r   r   kapparl   r   )r!   r   get_node_attributesr#   )r'   kappasZthetasZradiir   r   r   test_set_attributes_S1z  s   
r   c                  C   s   t jdddddd} t | d}t| t| }t|d dk s%J t| 	 }t| t| }t|d d	k s@J d S )
Ng      @r   r   rs   iW  r   r   r~   r6   )
r!   r   r   r   valuesr#   r.   fabsdictZdegree)r'   r   Zmean_kappasdegreesr   r   r   r   test_mean_kappas_mean_degree_S1  s   
r   c                  C   sZ   dd t dD } tjd| d}t|dksJ t|d} tdd |  D s+J d S )	Nc                 S      i | ]}|d qS rs   r   rX   r   r   r   r]         z'test_dict_kappas_S1.<locals>.<dictcomp>  r6   )r   r   r   c                 s   s    | ]}|d kV  qdS )rs   Nr   )r	   r   r   r   r   r     s    z&test_dict_kappas_S1.<locals>.<genexpr>)r$   r!   r   r#   r   rL   r   )r   r'   r   r   r   test_dict_kappas_S1  s
   r   c                  C   sD   t jdddddd} t jdddddd}t | t |k s J d S )Nr   rq         @rs   r   r   g      @r!   r   Zaverage_clustering)r   r   r   r   r   test_beta_clustering_S1  s   

r   c                  C   s   t jtjdd tjddddd} W d    n1 sw   Y  t jtjdd d	d
 tdD }tjd|ddd} W d    n1 sFw   Y  t jtjdd tjddd} W d    d S 1 sfw   Y  d S )NzDPlease provide either kappas, or all 3 of: n, gamma and mean_degree.r   r   r   rs   r   )r   r   r   r    z;When kappas is input, n, gamma and mean_degree must not be.c                 S   r   r   r   rX   r   r   r   r]     r   z,test_wrong_parameters_S1.<locals>.<dictcomp>r   ffffff@)r   r   r   r    )r   r    )r   r   r!   r   r   r$   )r'   r   r   r   r   test_wrong_parameters_S1  s.   	"r   c                  C   sJ   t jtjdd tjdddddd} W d    d S 1 sw   Y  d S )	Nz3The parameter beta cannot be smaller or equal to 0.r   r   rq   r   rs   r   r   )r   r   r!   r   r   r   r   r   r   test_negative_beta_S1  s   
"r   c                  C   s*   t jdddddd} t | dksJ d S )Nr~   rq   r   rs   r   r   r   r   r   r   r   r   *test_non_zero_clustering_beta_lower_one_S1  s   
r   c                  C   sL   d} d}t jddd| dd}t jddd|dd}t |t |ks$J d S )Nr,      g333333?rq   r   r   r   )r!   r   Znumber_connected_components)Zlow_mean_degreeZhigh_mean_degreeZG_lowZG_highr   r   r   -test_mean_degree_influence_on_connectivity_S1  s   

r   c                  C   s   t jdddddd} t jdddddd}t | d}t| t| }t |d}t| t| }t|| d	k s?J d S )
Nr   r   r   r   r   r   r   r   r6   )r!   r   r   r   r   r#   r.   r   )r   r   Zkappas1Zmean_kappas1Zkappas2Zmean_kappas2r   r   r   ,test_compare_mean_kappas_different_gammas_S1  s   

r   )r.   rW   	itertoolsr   r   Znetworkxr!   r   r   rT   ro   rp   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s2    9H40A
	