mò
­fIc           @   s¥  d  Z  d k l Z l Z l Z l Z l Z l Z d k Z d k	 Z	 d k
 l Z d k Z d „  Z d e	 i f d „  ƒ  YZ d f  d „  ƒ  YZ d	 f  d
 „  ƒ  YZ d f  d „  ƒ  YZ d „  Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d k l Z l Z d „  Z d e	 i f d „  ƒ  YZ d d  „ Z! e" d! j o e! d" e# ƒ n d S(#   s   Unittests for heapq.(   s   heappushs   heappops   heapifys   heapreplaces   nlargests	   nsmallestN(   s   test_supportc         c   s0   y x t  |  ƒ Vq WWn t j
 o n Xd  S(   Ni   (   t   heappopt   heapt
   IndexError(   R   (    (    t,   /mit/python/lib/python2.4/test/test_heapq.pyt   heapiter
   s      t   TestHeapc           B   sP   t  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(	   Nc         C   s&  g  } g  } |  i | ƒ xG t d ƒ D]9 } t i ƒ  } | i | ƒ t	 | | ƒ |  i | ƒ q& Wg  } x2 | o* t | ƒ } |  i | ƒ | i | ƒ ql W| } | i ƒ  |  i | | ƒ |  i | ƒ |  i t t	 g  ƒ y- |  i t t	 d  d  ƒ |  i t t d  ƒ Wn t j
 o n Xd  S(   Ni   (   R   t   datat   selft   check_invariantt   ranget   it   randomt   itemt   appendt   heappusht   resultsR    t   data_sortedt   sortt   assertEqualt   assertRaisest	   TypeErrort   Nonet   AttributeError(   R   R   R
   R   R   R   R   (    (    R   t   test_push_pop   s2      
c         C   sQ   xJ t  | ƒ D]< \ } } | o) | d d ?} |  i | | | j ƒ q q Wd  S(   Ni   (   t	   enumerateR   t   posR   t	   parentposR   t   assert_(   R   R   R   R   R   (    (    R   R   0   s
     c         C   sr   xX t  d ƒ D]J } g  } t  | ƒ D] } | t i ƒ  q$ ~ } t | ƒ |  i | ƒ q W|  i	 t
 t d  ƒ d  S(   Ni   (   R	   t   sizet   _[1]t   dummyR   R   t   heapifyR   R   R   R   R   (   R   R   R   R   R   (    (    R   t   test_heapify7   s     -
c         C   s   g  } t d ƒ D] } | t i d ƒ q ~ } g  } x< | D]4 } t | | ƒ t	 | ƒ d j o t
 | ƒ q= q= W| i ƒ  |  i | t | ƒ d ƒ d  S(   Niè  iÐ  i
   iöÿÿÿ(   R   R	   R
   R   t	   randrangeR   R   R   R   t   lenR    R   R   R   t   sorted(   R   R
   R   R   R   R   (    (    R   t   test_naive_nbest?   s    0 
c         C   sä   g  } t d ƒ D] } | t i d ƒ q ~ } | d  } t | ƒ x4 | d D]( } | | d j o t	 | | ƒ qO qO W|  i t t | ƒ ƒ t | ƒ d ƒ |  i t t	 d  ƒ |  i t t	 d  d  ƒ |  i t t	 g  d  ƒ d  S(   Niè  iÐ  i
   i    iöÿÿÿ(   R   R	   R
   R   R!   R   R   R   R   t   heapreplaceR   R   t   listR   R#   R   R   R   R   (   R   R
   R   R   R   R   (    (    R   t
   test_nbestI   s    0

 &c   	      C   sá   xÚ t  d ƒ D]Ì } t i d ƒ } g  } t | ƒ D] } | t i d ƒ q3 ~ } | d @o | } t
 | ƒ n% g  } x | D] } t | | ƒ q Wg  } t | ƒ D] } | t | ƒ q§ ~ } |  i | t | ƒ ƒ q Wd  S(   Nid   i2   i   i   (   t   xranget   trialR   R!   R   R   R	   R
   R   R   R   R   R   R    t   heap_sortedR   R   R#   (	   R   R*   R   R
   R   R)   R   R   R   (    (    R   t   test_heapsort[   s     0 -c      	   C   sh   g  } t d ƒ D] } | t i d ƒ q ~ } x1 d D]) } |  i t	 | | ƒ t
 | ƒ |  ƒ q7 Wd  S(   Niè  iÐ  i    i   i   i
   id   i  iç  iL  (	   i    i   i   i
   id   i  iç  iè  iL  (   R   R	   R
   R   R!   R   t   nR   R   t	   nsmallestR#   (   R   R
   R,   R   R   (    (    R   t   test_nsmallestj   s    0 c      	   C   sn   g  } t d ƒ D] } | t i d ƒ q ~ } x7 d D]/ } |  i t	 | | ƒ t
 | d t ƒ|  ƒ q7 Wd  S(   Niè  iÐ  i    i   i   i
   id   i  iç  iL  t   reverse(	   i    i   i   i
   id   i  iç  iè  iL  (   R   R	   R
   R   R!   R   R,   R   R   t   nlargestR#   t   True(   R   R
   R,   R   R   (    (    R   t   test_largesto   s    0 (
   t   __name__t
   __module__R   R   R    R$   R'   R+   R.   R2   (    (    (    R   R      s   				
			t   LenOnlyc           B   s   t  Z d  Z d „  Z RS(   s:   Dummy sequence class defining __len__ but not __getitem__.c         C   s   d S(   Ni
   (    (   R   (    (    R   t   __len__y   s    (   R3   R4   t   __doc__R6   (    (    (    R   R5   w   s    t   GetOnlyc           B   s   t  Z d  Z d „  Z RS(   s:   Dummy sequence class defining __getitem__ but not __len__.c         C   s   d S(   Ni
   (    (   R   t   ndx(    (    R   t   __getitem__~   s    (   R3   R4   R7   R:   (    (    (    R   R8   |   s    t   CmpErrc           B   s   t  Z d  Z d „  Z RS(   s;   Dummy element that always raises an error during comparisonc         C   s
   t  ‚ d  S(   N(   t   ZeroDivisionError(   R   t   other(    (    R   t   __cmp__ƒ   s    (   R3   R4   R7   R>   (    (    (    R   R;      s    c         c   s   x |  D]
 } | Vq Wd S(   s   Regular generatorN(   t   seqnR
   (   R?   R
   (    (    R   t   R†   s      t   Gc           B   s    t  Z d  Z d „  Z d „  Z RS(   s   Sequence using __getitem__c         C   s   | |  _  d  S(   N(   R?   R   (   R   R?   (    (    R   t   __init__   s    c         C   s   |  i | S(   N(   R   R?   R
   (   R   R
   (    (    R   R:      s    (   R3   R4   R7   RB   R:   (    (    (    R   RA   ‹   s    	t   Ic           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   s    Sequence using iterator protocolc         C   s   | |  _  d |  _ d  S(   Ni    (   R?   R   R
   (   R   R?   (    (    R   RB   ”   s    	c         C   s   |  S(   N(   R   (   R   (    (    R   t   __iter__—   s    c         C   sF   |  i t |  i ƒ j o
 t ‚ n |  i |  i } |  i d 7_ | S(   Ni   (   R   R
   R"   R?   t   StopIterationt   v(   R   RF   (    (    R   t   next™   s
     
(   R3   R4   R7   RB   RD   RG   (    (    (    R   RC   ’   s    		t   Igc           B   s    t  Z d  Z d „  Z d „  Z RS(   s9   Sequence using iterator protocol defined with a generatorc         C   s   | |  _  d |  _ d  S(   Ni    (   R?   R   R
   (   R   R?   (    (    R   RB   ¡   s    	c         c   s   x |  i D]
 } | Vq
 Wd  S(   N(   R   R?   t   val(   R   RI   (    (    R   RD   ¤   s    
 (   R3   R4   R7   RB   RD   (    (    (    R   RH   Ÿ   s    	t   Xc           B   s    t  Z d  Z d „  Z d „  Z RS(   s    Missing __getitem__ and __iter__c         C   s   | |  _  d |  _ d  S(   Ni    (   R?   R   R
   (   R   R?   (    (    R   RB   ª   s    	c         C   sF   |  i t |  i ƒ j o
 t ‚ n |  i |  i } |  i d 7_ | S(   Ni   (   R   R
   R"   R?   RE   RF   (   R   RF   (    (    R   RG   ­   s
     
(   R3   R4   R7   RB   RG   (    (    (    R   RJ   ¨   s    	t   Nc           B   s    t  Z d  Z d „  Z d „  Z RS(   s   Iterator missing next()c         C   s   | |  _  d |  _ d  S(   Ni    (   R?   R   R
   (   R   R?   (    (    R   RB   µ   s    	c         C   s   |  S(   N(   R   (   R   (    (    R   RD   ¸   s    (   R3   R4   R7   RB   RD   (    (    (    R   RK   ³   s    	t   Ec           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   s   Test propagation of exceptionsc         C   s   | |  _  d |  _ d  S(   Ni    (   R?   R   R
   (   R   R?   (    (    R   RB   ½   s    	c         C   s   |  S(   N(   R   (   R   (    (    R   RD   À   s    c         C   s   d d d  S(   Ni   i    (    (   R   (    (    R   RG   Â   s    (   R3   R4   R7   RB   RD   RG   (    (    (    R   RL   »   s    		t   Sc           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   s   Test immediate stopc         C   s   d  S(   N(    (   R   R?   (    (    R   RB   Ç   s    c         C   s   |  S(   N(   R   (   R   (    (    R   RD   É   s    c         C   s
   t  ‚ d  S(   N(   RE   (   R   (    (    R   RG   Ë   s    (   R3   R4   R7   RB   RD   RG   (    (    (    R   RM   Å   s    		(   s   chains   imapc         C   s(   t  t d „  t t t |  ƒ ƒ ƒ ƒ ƒ S(   s    Test multiple tiers of iteratorsc         C   s   |  S(   N(   t   x(   RN   (    (    R   t   <lambda>Ñ   s    N(   t   chaint   imapR@   RH   RA   R?   (   R?   (    (    R   t   LÏ   s     t   TestErrorHandlingc           B   s>   t  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   Nc         C   sa   x' t  t f D] } |  i t | d ƒ q Wx0 t t t t	 f D] } |  i t | d d ƒ q= Wd  S(   Ni
   (
   R   R    t   fR   R   R   R   R%   R0   R-   (   R   RT   (    (    R   t   test_non_sequenceÕ   s      c         C   s‘   x* t  t f D] } |  i t | t ƒ  ƒ q Wx- t t f D] } |  i t | t ƒ  d ƒ q: Wx- t	 t
 f D] } |  i t | d t ƒ  ƒ qj Wd  S(   Ni
   i   (   R   R    RT   R   R   R   R5   R   R%   R0   R-   (   R   RT   (    (    R   t   test_len_onlyÛ   s       c         C   s‘   x* t  t f D] } |  i t | t ƒ  ƒ q Wx- t t f D] } |  i t | t ƒ  d ƒ q: Wx- t	 t
 f D] } |  i t | d t ƒ  ƒ qj Wd  S(   Ni
   i   (   R   R    RT   R   R   R   R8   R   R%   R0   R-   (   R   RT   (    (    R   t   test_get_onlyã   s       c         C   s    t  ƒ  t  ƒ  t  ƒ  g } x' t t f D] } |  i t | | ƒ q% Wx* t t	 f D] } |  i t | | d ƒ qO Wx* t
 t f D] } |  i t | d | ƒ q| Wd  S(   Ni
   i   (   R;   t   seqR   R    RT   R   R   R<   R   R%   R0   R-   (   R   RX   RT   (    (    R   RW   ë   s       c         C   s:   x3 t  t t t t t f D] } |  i t	 | d ƒ q Wd  S(   Ni
   (
   R   R    R   R%   R0   R-   RT   R   R   R   (   R   RT   (    (    R   t   test_arg_parsingô   s     c      	   C   s  xt  t f D]ó } xê d d t d ƒ d
 t d d d ƒ f D]Á } xE t t t t	 t
 f D]. } |  i | d	 | | ƒ ƒ | d	 | ƒ ƒ qW W|  i | d	 t | ƒ ƒ g  ƒ |  i t | d	 t | ƒ ƒ |  i t | d	 t | ƒ ƒ |  i t | d	 t | ƒ ƒ q; Wq Wd  S(   Nt   123t    iè  t   dof1.2iÐ  i˜  i   i   (   R\   f1.2(   R0   R-   RT   R	   R(   t   sRA   RC   RH   RR   R@   t   gR   R   RM   R   R   RJ   RK   R<   RL   (   R   R^   RT   R]   (    (    R   t   test_iterable_argsø   s     (  ,(   R3   R4   RU   RV   RW   RY   R_   (    (    (    R   RS   Ó   s   						c         C   sÂ   d k  l } t g } t t | ƒ o | i t ƒ n t i	 | Œ  |  os t t d ƒ oc d  k } d  g d } xA t t | ƒ ƒ D]- } t i	 | Œ  | i ƒ  t i ƒ  | | <q„ W| GHn d  S(   N(   s   BuiltinFunctionTypet   gettotalrefcounti   (   t   typest   BuiltinFunctionTypeR   t   test_classest
   isinstanceR   R   RS   t   test_supportt   run_unittestt   verboset   hasattrt   syst   gcR   t   countsR(   R"   R
   t   collectR`   (   Rg   R
   Rb   Rj   Rk   Rc   (    (    R   t	   test_main  s    		 
t   __main__Rg   ($   R7   t   heapqR   R    R   R%   R0   R-   R   t   unittestt   testRe   Ri   R   t   TestCaseR   R5   R8   R;   R@   RA   RC   RH   RJ   RK   RL   RM   t	   itertoolsRP   RQ   RR   RS   R   Rm   R3   R1   (   Re   RP   Rp   R   R   R-   Rm   R    RL   RA   RC   RR   R   Ri   RM   R@   R5   R8   RJ   RK   RQ   R   R   R0   R;   RS   R%   RH   (    (    R   t   ?   s0   +				e		
		2