
    Vhs                     \    d Z ddlmZ ddlZddlZddlmZmZ  G d d      Z	 G d d      Z
y)	zBUnit tests for the :mod:`~networkx.algorithms.tree.coding` module.    )productN)edges_equalnodes_equalc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestPruferSequenceuN   Unit tests for the Prüfer sequence encoding and decoding
    functions.

    c                     t        j                  t        j                        5  t        j                  d      }t        j
                  |       d d d        y # 1 sw Y   y xY w)N   )pytestraisesnxNotATreecycle_graphto_prufer_sequenceselfGs     Z/home/dcms/DCMS/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_coding.pytest_nontreezTestPruferSequence.test_nontree   sC    ]]2;;' 	%q!A!!!$	% 	% 	%s   +AA!c                     t        j                  t        j                        5  t        j                  t        j
                                d d d        y # 1 sw Y   y xY wN)r
   r   r   NetworkXPointlessConceptr   
null_graphr   s    r   test_null_graphz"TestPruferSequence.test_null_graph   s=    ]]2667 	3!!"--/2	3 	3 	3   (AAc                     t        j                  t        j                        5  t        j                  t        j
                                d d d        y # 1 sw Y   y xY wr   )r
   r   r   r   r   trivial_graphr   s    r   test_trivial_graphz%TestPruferSequence.test_trivial_graph   s@    ]]2667 	6!!""2"2"45	6 	6 	6r   c                     t        j                  t              5  t        j                  t        j
                  j                  d            }t        j                  |       d d d        y # 1 sw Y   y xY w)Nabc)r
   r   KeyErrorr   Graphutilspairwiser   )r   Ts     r   test_bad_integer_labelsz*TestPruferSequence.test_bad_integer_labels   sN    ]]8$ 	%**512A!!!$	% 	% 	%s   AA++A4c                 n    t        j                  g d      }t        j                  |      }|g dk(  sJ y)u_   Tests for encoding a tree as a Prüfer sequence using the
        iterative strategy.

        r   r	      r	   )   r	   )r	      )r-      r	   r	   r	   r-   N)r   r"   r   )r   treesequences      r   test_encodingz TestPruferSequence.test_encoding#   s1     xx@A((.<'''    c                     g d}t        j                  |      }t        t        |      t        t	        d                  sJ g d}t        t        |j                               |      sJ y)u2   Tests for decoding a tree from a Prüfer sequence.r/      r(   Nr   from_prufer_sequencer   listranger   edgesr   r1   r0   r:   s       r   test_decodingz TestPruferSequence.test_decoding-   sU      &&x04:tE!H~66684

-u555r3   c                     g d}t        j                  |      }t        t        |      t        t	        d                  sJ g d}t        t        |j                               |      sJ y )N)r,   r-   r   r+   r	   r	      )r   r+   )r   r-   r*   )r,   r-   r,   r.   r	   r5   r	      r6   r;   s       r   test_decoding2z!TestPruferSequence.test_decoding26   sS    %&&x04:tE!H~666H4

-u555r3   c                    t        j                  d      D ]  }t        j                  t        j                  |            }t	        t        |      t        |            sJ t        t        |j                               t        |j                                     rJ  t        t        d      d      D ]:  }t        j                  t        j                  |            }t        |      |k(  r:J  y)z<Tests that the encoding and decoding functions are inverses.r-   r,   )repeatN)
r   nonisomorphic_treesr7   r   r   r8   r   r:   r   r9   )r   r%   T2seqseq2s        r   test_inversezTestPruferSequence.test_inverse>   s    ''* 	BA(()>)>q)ABBtAwR111tAGGIRXXZ0@AAA	B
 58A. 	%C(()@)@)EFD9$$$	%r3   N)__name__
__module____qualname____doc__r   r   r   r&   r2   r<   rD   rK    r3   r   r   r      s/    
%
36%
(66	%r3   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestNestedTuplez@Unit tests for the nested tuple encoding and decoding functions.c                     t        j                  t        j                        5  t        j                  d      }t        j
                  |d       d d d        y # 1 sw Y   y xY w)Nr	   r   )r
   r   r   r   r   to_nested_tupler   s     r   r   zTestNestedTuple.test_nontreeM   sE    ]]2;;' 	%q!Aq!$	% 	% 	%   ,AA"c                     t        j                  t        j                        5  t        j                  d      }t        j
                  |d       d d d        y # 1 sw Y   y xY w)Nr,   bogus)r
   r   r   NodeNotFound
path_graphrT   r   s     r   test_unknown_rootz!TestNestedTuple.test_unknown_rootR   sE    ]]2??+ 	+a Aq'*	+ 	+ 	+rU   c                 |    t        j                  dd      }d}t        j                  |d      }t        ||      sJ y )Nr,   rC   rP   rP   r]   r   )r   full_rary_treerT   r   )r   r%   expectedactuals       r   r2   zTestNestedTuple.test_encodingW   s;    a*'##Aq)8V,,,r3   c                     t        j                         }|j                  g d       |j                  ddg       |j                  ddg       d}t        j                  ||d      }d	}||k(  sJ y )
N)r?   r   r,   r)   r+   r-   )r+   r.   rA   rB   r   T)canonical_form)rP   r]   r]   )r   r"   add_edges_fromrT   )r   r%   rootr`   r_   s        r   test_canonical_formz#TestNestedTuple.test_canonical_form]   sn    HHJ	12	&&)*	&&)*##AtDA+!!!r3   c                     d}t        j                  dd      }t        j                  |      }t        j                  ||      sJ y )Nr\   r,   rC   )r   r^   from_nested_tupleis_isomorphic)r   balancedr_   r`   s       r   r<   zTestNestedTuple.test_decodingg   s?    '$$Q1%%h/&111r3   c                     d}t        j                  |d      }g d}t        t        |      t        t	        d                  sJ t        t        |j                               |      sJ y )Nr\   T)sensible_relabeling)r?   rb   r*   rc   r@   )r,   r5   rC   )r   ri   r   r8   r9   r   r:   )r   rk   r%   r:   s       r   test_sensible_relabelingz(TestNestedTuple.test_sensible_relabelingm   sU    '  tD@47Dx$9:::4	?E222r3   N)
rL   rM   rN   rO   r   rZ   r2   rg   r<   rn   rP   r3   r   rR   rR   J   s#    J%
+
-"23r3   rR   )rO   	itertoolsr   r
   networkxr   networkx.utilsr   r   r   rR   rP   r3   r   <module>rr      s)    H    3<% <%~(3 (3r3   