
    ix                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl d dl	m
Z
 d ej                         k(  ZddZd dZd Zd	 Zd
 Zd Zd!dZd Zd!dZ G d dej,                        Z G d dej0                  j2                        Z G d de      Z G d de      Z G d de      Z G d dej,                        Z ej>                  ed       G d dej,                               Z e!dk(  r ejD                          yy)"    )OrderedDictN)*)Vector2PyPyc                     t        j                  |       }t        | d   | d   z  dz        D ]M  }t        j                  d| d   dz
        t        j                  d| d   dz
        }}|j                  ||f       O |S )zwrandom_mask(size=(100,100)): return Mask
    Create a mask of the given size, with roughly half the bits set at random.r         )pygameMaskrangerandomrandintset_at)sizemixys        `/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/tests/mask_test.pyrandom_maskr      s~     	DA47T!W$)* ~~aa1-v~~aa1/M1	!Q H    c                 "   t        j                  | j                               }| j                         }|rot	        | j                               D ]Q  }t	        | j                               D ]3  }| j                  |dz   |dz   f      |k7  s |j                  ||fd       5 S |S t	        | j                               D ]N  }t	        | j                               D ]0  }| j                  ||f      d   |kD  s|j                  ||fd       2 P |S )Ng?r      )	r
   r   get_sizeget_colorkeyr   
get_height	get_widthget_atr   )surface	thresholdmaskkeyr   r   s         r   maskFromSurfacer#      s
   ;;w'')*D



 C
w))+, 	+A7,,./ +>>1s7AG"45<KKA*+	+ K	 w))+, 	+A7,,./ +>>1a&)!,y8KKA*+	+ Kr   c                     | d   d   x}}| d   d   x}}| dd D ]5  \  }}t        ||      }t        ||      }t        ||      }t        ||      }7 t        j                  ||f||z
  dz   ||z
  dz   f      S )z.Creates a bounding rect from the given points.r   r   N)minmaxr
   Rect)pointsxminxmaxyminymaxr   r   s          r   create_bounding_rectr-   *   s    )A,D4)A,D4qr
 11d|1d|1d|1d|	 ;;d|dTkAotd{Q%GHHr   c                 2    | |f| dfd|fdffdD        S )zCreates a generator which yields pairs of sizes.

    For each pair of sizes at least one of the sizes will have a 0 in it.
    r   r   r   c              3   F   K   | ]  }D ]  }d |v sd |v s||f   ywr   N ).0absizess      r   	<genexpr>z"zero_size_pairs.<locals>.<genexpr>?   s-     Eq5EaAFa1fQFEFEs   !!r2   )widthheightr6   s     @r   zero_size_pairsr:   8   s*    
 V_uaj1f+v>EEEEEr   c                 X    | j                         \  }}d|dz
  df|dz
  |dz
  fd|dz
  ffS )zjReturns a tuple with the corner positions of the given mask.

    Clockwise from the top left corner.
    r/   r   r   )r   )r!   r8   r9   s      r   cornersr<   B   s?    
 MMOME6UQYNUQY
$;a!_MMr   c                 v   | j                   dz
  | j                  f| j                   dz
  | j                  dz
  f| j                   | j                  dz
  f| j                  dz
  | j                  dz
  f| j                  | j                  dz
  f| j                  | j                  f| j                  | j                  dz
  f| j                  | j                  f| j                  dz
  | j                  f| j                   | j                  f| j                   dz
  | j                  f| j                   dz
  | j                  dz
  ffS )zvReturns a tuple with the positions off of the corners of the given rect.

    Clockwise from the top left corner.
    r   )lefttoprightbottom)rects    r   off_cornersrC   K   s     
Q!	Q1%	DHHqL!	aA&	TXX\"	TXX	T[[1_%	T[[!	a%	DKK 	Q$	Qa( r   c                    |3t        |j                               t        |j                               }no|j                          |j	                  |j                               }t        |j                  |j                        t        |j                  |j                        }|j                          fd|D        D ]$  }| j                  |j                  |      ||       & |j                          y)zChecks to see if the given surface is filled with the given color.

    If an area_rect is provided, only check that area of the surface.
    Nc              3   4   K   | ]  }D ]  }||f 
  y wNr2   r3   r   r   x_ranges      r   r7   z&assertSurfaceFilled.<locals>.<genexpr>o   !     919AA99   )r   r   r   	normalizeclipget_rectr>   r@   r?   rA   lockassertEqualr   unlock)testcaser   expected_color	area_recty_rangeposrH   s         @r   assertSurfaceFilledrV   `   s    
 ))+,**,-NN7#3#3#56			8	y'7'78LLN99 GW^^C0.#FGNNr   c                 R   t        |j                               t        |j                               }|j                          |j	                          fd|D        D ]6  }|j                  |      r| j                  |j                  |      ||       8 |j                          y)zcChecks if the surface is filled with the given color. The
    ignore_rect area is not checked.
    c              3   4   K   | ]  }D ]  }||f 
  y wrF   r2   rG   s      r   r7   z0assertSurfaceFilledIgnoreArea.<locals>.<genexpr>}   rI   rJ   N)	r   r   r   rK   rN   collidepointrO   r   rP   )rQ   r   rR   ignore_rectrT   rU   rH   s         @r   assertSurfaceFilledIgnoreArear[   t   s     G%%'(GG&&()GLLN99 K'',  !4ncJK NNr   c                    |j                         }| j                  |j                         |j                         |       | j                  ||j                         |       | j                  ||j                  |d      |       y)z-Checks to see if the 2 given masks are equal.)msgr/   N)countrO   r   overlap_area)rQ   m1m2r]   m1_counts        r   assertMaskEqualrc      si    xxzH3?288:372??2v#>CHr   c                   \   e Zd ZdZ ej
                  ed      d        Zd Zd Z	 ej
                  ed      d        Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Z ej
                  ed      d        Zd Zd Z ej
                  ed      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z" ej
                  ed      d        Z# ej
                  ed      d         Z$d! Z% ej
                  ed      d"        Z& ej
                  ed      d#        Z'd$ Z( ej
                  ed      d%        Z)d& Z*d' Z+d( Z, ej
                  ed      d)        Z-d* Z. ej
                  ed      d+        Z/d, Z0 ej
                  ed      d-        Z1d. Z2d/ Z3d0 Z4d1 Z5 ej
                  ed      d2        Z6d3 Z7d4 Z8 ej
                  ed      d5        Z9d6 Z:d7 Z; ej
                  ed      d8        Z< ej
                  ed      d9        Z=d: Z>d; Z?d< Z@d= ZAd> ZB ej
                  ed      d?        ZCd@ ZDdA ZEdB ZFdC ZGdD ZHdE ZI ej
                  ed      dF        ZJdG ZKdH ZLdI ZM ej
                  ed      dJ        ZNdK ZOdL ZPdM ZQdN ZRdO ZSdP ZTdQ ZUdR ZVdS ZWdT ZXdU ZYdV ZZdW Z[dX Z\dY Z]dZ Z^d[ Z_d\ Z` ej
                  ed      d]        Zadd^Zbdd_Zcdd`Zdda Zedb Zfdc Zgdd Zhde Zidf Zjdg Zkdh Zldi Zmdj Zndk Zo ej
                  ed      dl        Zp ej
                  ed      dm        Zqdn Zrdo Zsdp Ztdq Zudr Zvds Zwdt Zxdu Zydv Zzdw Z{ej                  dx        Z}dy Z~dz Zd{ Zd| Zd} Zd~ Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej
                  ed      d        Zd Zej                   ej
                  ed      d               Zej                  d        Zej                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej                   ej
                  ed      d               Zej                  d        Zej                   ej
                  ed      d               Zej                   ej
                  ed      d               ZdÄ ZdĄ Zdń ZdƄ ZdǄ ZdȄ ZdɄ Zdʄ Zd˄ Zd̄ Zd̈́ Zd΄ Zdτ ZdЄ Zdф Zd҄ Zdӄ ZdԄ ZdՄ Zdք Zdׄ Zd؄ Zdل Zdڄ Zdۄ Zd܄ Zd݄ Zdބ Zd߄ Zd Zd Zy)MaskTypeTest)	r/   r   r   r   r   r   r   r   r   rj   rj   rj   rj   r   rj   r   zSegfaults on pypyc                 2   d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  |t         j                  j                         | j	                  |j                         |       | j	                  |j                         |       | j                  |t         j                  j                         | j	                  |j                         |       | j	                  |j                         |       y)z:Ensure masks are created correctly without fill parameter.r         r   N)r
   r!   r   assertIsInstancerO   r^   r   )selfexpected_countexpected_sizemask1mask2s        r   	test_maskzMaskTypeTest.test_mask   s        /  m 4eV[[%5%567)=9eV[[%5%567)=9r   c                     dD ]5  }| j                  t              5  t        j                  |      }ddd       7 y# 1 sw Y   BxY w)z=Ensure the mask constructor handles negative sizes correctly.)ri   rn   rl   N)assertRaises
ValueErrorr
   r   ru   r   r!   s      r   test_mask__negative_sizez%MaskTypeTest.test_mask__negative_size   sG    0 	)D"":. ){{4() )	)) )s	   <A	c                 |   d\  }}||f}||z  dd}|j                         D ]  \  }}d| }t        j                  j                  ||      }| j	                  |t        j                  j                  |       | j                  |j                         ||       | j                  |j                         ||        y)z:Ensure masks are created correctly using the fill keyword.)%   /   r   TFfill=fillNitemsr
   r!   r   rt   rO   r^   r   	ru   r8   r9   rw   fill_countsr   rv   r]   r!   s	            r   test_mask__fill_kwargz"MaskTypeTest.test_mask__fill_kwarg   s    v"V^A6$/$5$5$7 	B D.$.C;;##M#=D!!$(8(8#>TZZ\>3?T]]_mSA	Br   c                    t        dd      D ]  }t        dd      D ]  }||z  }||f}d| }t        j                  j                  |d      }| j	                  |t        j                  j                  |       | j                  |j                         ||       | j                  |j                         ||         y)a  Ensures masks are created correctly using the fill keyword
        over a range of sizes.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r      B   size=Tr   N)r   r
   r!   r   rt   rO   r^   r   )ru   r9   r8   rv   rw   r]   r!   s          r   $test_mask__fill_kwarg_bit_boundariesz1MaskTypeTest.test_mask__fill_kwarg_bit_boundaries   s     Aqk 
	FFq" 	F!&!&m_-{{''D'A%%dFKK,<,<cB  ~sC  -E	F
	Fr   c                 z   d\  }}||f}||z  dd}|j                         D ]  \  }}d| }t        j                  j                  ||      }| j	                  |t        j                  j                  |       | j                  |j                         ||       | j                  |j                         ||        y)z4Ensure masks are created correctly using a fill arg.);   G   r   r   r   Nr   r   s	            r   test_mask__fill_argz MaskTypeTest.test_mask__fill_arg   s    v"V^A6$/$5$5$7 	B D.$.C;;##M48D!!$(8(8#>TZZ\>3?T]]_mSA	Br   c                    d\  }}||f}||z  dd}|j                         D ]'  \  }}d| }t        j                  j                  ||      }t        j                  j                  ||      }	| j	                  |t        j                  j                  |       | j	                  |	t        j                  j                  |       | j                  |j                         ||       | j                  |	j                         ||       | j                  |j                         ||       | j                  |	j                         ||       * y)z:Ensure masks are created correctly using the size keyword.)I   S   r   r   r   r   r   )r   r   Nr   )
ru   r8   r9   rw   r   r   rv   r]   rx   ry   s
             r   test_mask__size_kwargz"MaskTypeTest.test_mask__size_kwarg   s   v"V^A6$/$5$5$7 	C D.$.CKK$$$]$CEKK$$-d$CE!!%)9)93?!!%)9)93?U[[]NC@U[[]NC@U^^-}cBU^^-}cB	Cr   c                    dD ]  }dD ]  }t         j                  j                  ||f      }t        |      D ]*  }t        |dz  |d      D ]  }|j	                  ||f        , |j                         t        j
                  |      fD ]K  }| j                  |t         j                  j                         | j                  ||       t        | ||       M   y)z:Ensures copy works correctly with some bits set and unset.       !   ?   @   A   r   r	   N)	r
   r!   r   r   r   copyrt   assertIsNotrc   )ru   r8   r9   r!   r   r   	mask_copys          r   	test_copyzMaskTypeTest.test_copy   s     . 	;E2 ;{{''8 u ,A"1q5&!4 ,QF+,,
 #'))+tyy!? ;I)))V[[5E5EF$$Y5#D)T:;;	;r   c                 L   dD ]  }dD ]  }t         j                  j                  ||fd      }|j                         t        j                  |      fD ]K  }| j	                  |t         j                  j                         | j                  ||       t        | ||       M   y)z0Ensures copy works correctly on a filled masked.r   Tr   Nr
   r!   r   r   rt   r   rc   ru   r8   r9   r!   r   s        r   test_copy__fullzMaskTypeTest.test_copy__full  s     . 	;E2 ;{{''d'C #'))+tyy!? ;I)))V[[5E5EF$$Y5#D)T:;	;	;r   c                 H   dD ]  }dD ]  }t         j                  j                  ||f      }|j                         t        j                  |      fD ]K  }| j	                  |t         j                  j                         | j                  ||       t        | ||       M   y)z.Ensures copy works correctly on an empty mask.r   Nr   r   s        r   test_copy__emptyzMaskTypeTest.test_copy__empty  s    - 	;E2 ;{{''8 #'))+tyy!? ;I)))V[[5E5EF$$Y5#D)T:;	;	;r   c                    d}d}t         j                  j                  d      }|j                         t        j                  |      f}|j	                  |       |D ]  }|j	                  |       | j                  ||       | j                  |j                  |      |j                  |             | j                  |j                  |      |j                  |              y)z3Ensures copy makes an independent copy of the mask.)r   r   )r   r	   r   r   N)r
   r!   r   r   r   r   assertNotEqualr   )ru   mask_set_posmask_copy_set_posr!   mask_copiesr   s         r   test_copy__independentz#MaskTypeTest.test_copy__independent'  s    #{{( yy{DIIdO4L!$ 		I./Y-  .L0I   !23T[[AR5S		r   c                     d}t         j                  j                  |      }| j                  |j	                         |       y)z,Ensure a mask's size is correctly retrieved.)]   e   N)r
   r!   r   rO   r   )ru   rw   r!   s      r   test_get_sizezMaskTypeTest.test_get_size<  s1    !{{.-8r   c                     t        j                  dd      }dD ]O  }t         j                  j                  |j                  |      }|j                         }| j                  ||       Q y)z!Ensures get_rect works correctly.r/   rq      r   r   N)r
   r'   r!   r   r   rM   rO   )ru   expected_rectr   r!   rB   s        r   test_get_rectzMaskTypeTest.test_get_rectC  s]    FH5 " 	2D;;##M$6$6T#BD==?DT=1	2r   c           	      V   d}d}|d|dddgt        dd      fi}d	}t        j                  j                  |      }|j	                         D ]\  \  }}|D ]R  }|D ]K  }	t        j
                  d
|      }
t        |
||	        |j                  di ||	i}| j                  ||
       M T ^ y)ziEnsures get_rect supports a single rect attribute kwarg.

        Tests all the rect attributes.
        )r   r   r?   r>   rA   r@   centerxcenteryr8   r9   wh)
topleft
bottomlefttoprightbottomrightmidtopmidleft	midbottommidrightcenterr   )r   gffffff@)r   g@gffffff@r   r   r      r   r/   Nr2   )	r   r
   r!   r   r   r'   setattrrM   rO   )ru   RECT_SINGLE_VALUE_ATTRIBUTESRECT_DOUBLE_VALUE_ATTRIBUTESrect_attributesr   r!   
attributesvalues	attributevaluer   rB   s               r   test_get_rect__one_kwargz%MaskTypeTest.test_get_rect__one_kwargO  s    (
$ (
$  )((8c1Xwq!}*M

 {{%"1"7"7"9 	:J' :	# :E$*KK$=MM9e<(4==>Iu+=>D$$T=9::	:r   c                     t         j                  j                  d      }t        j                  dd      }ddt	        dd      d}|j                         D ]  \  }}t        |||         |j                  d	i |}| j                  ||       y)
z9Ensures get_rect supports multiple rect attribute kwargs.   r   r/   gffffff@rj   r	   g	@)r   r?   r   Nr2   )	r
   r!   r   r'   r   r   r   rM   rO   )ru   r!   r   kwargsattribr   rB   s          r   test_get_rect__multiple_kwargsz+MaskTypeTest.test_get_rect__multiple_kwargs  s    {{'FF32wq#?#\\^ 	2MFEM651	2 t}}&v&}-r   c                 .   t         j                  j                  d      }| j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       y# 1 sw Y   9xY w# 1 sw Y   yxY w)z&Ensures get_rect only supports kwargs.r   r   r   Nr   r	   r
   r!   r   r|   	TypeErrorrM   ru   r!   rB   s      r   test_get_rect__no_arg_supportz*MaskTypeTest.test_get_rect__no_arg_support  s    {{'y) 	$==#D	$ y) 	)==(D	) 	)	$ 	$	) 	)s   A?$B?BBc                    t         j                  j                  d      }| j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       y# 1 sw Y   jxY w# 1 sw Y   FxY w# 1 sw Y   yxY w)	z(Ensures get_rect detects invalid kwargs.r   rq   )righteNrg   )toplefr   r	   )move)r
   r!   r   r|   AttributeErrorrM   r   s      r   !test_get_rect__invalid_kwarg_namez.MaskTypeTest.test_get_rect__invalid_kwarg_name  s     {{'~. 	,===+D	, ~. 	0===/D	0 ~. 	.==f=-D	. 	.	, 	,	0 	0	. 	.s#   B1%B=C	1B:=C	Cc                    t         j                  j                  d      }| j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d	
      }ddd       | j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       | j                  t              5  |j                  d      }ddd       y# 1 sw Y   +xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xxY w# 1 sw Y   yxY w)z/Ensures get_rect detects invalid kwarg formats.)r   rq   1)r@   Nr   )rA   rg   )r   )r   r   )r   )r   r   r	   r   )r   r   )r   r   r   s      r   #test_get_rect__invalid_kwarg_formatz0MaskTypeTest.test_get_rect__invalid_kwarg_format  s   {{(y) 	,==s=+D	, y) 	.===-D	. y) 	1===0D	1 y) 	3===2D	3 y) 	0==$=/D	0 y) 	7==I=6D	7 y) 	.==1=-D	. 	.%	, 	,	. 	.	1 	1	3 	3	0 	0	7 	7	. 	.sS   E1%E>FF5F#%F/F;1E;>FFF #F,/F8;Gc                    d\  }}t         j                  j                  ||f      }t         j                  j                  ||fd      }d}d}|dz
  |dz
  f}| j                  |j	                  |      |       | j                  |j	                  |      |       | j                  |j	                  t        |            |       | j                  |j	                  t        |            |       y)z4Ensure individual mask bits are correctly retrieved.r   r   Tr   r   r   )rU   N)r
   r!   r   rO   r   r   )ru   r8   r9   mask0rx   mask0_expected_bitmask1_expected_bitrU   s           r   test_get_atzMaskTypeTest.test_get_at  s    v  %1  %t <qy&1*% 	c*,>?#.0BCgcl35GH'#,79KLr   c                 0   d\  }}t         j                  j                  ||f      }| j                  t              5  |j                  |df       ddd       | j                  t              5  |j                  d|f       ddd       | j                  t              5  |j                  d       ddd       | j                  t              5  |j                  d       ddd       y# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   QxY w# 1 sw Y   yxY w)zEnsure get_at() checks bounds.rq   r   r   Nrm   rk   r
   r!   r   r|   
IndexErrorr   ru   r8   r9   r!   s       r   test_get_at__out_of_boundsz'MaskTypeTest.test_get_at__out_of_bounds      v{{0z* 	$KK
#	$ z* 	%KKF$	% z* 	!KK 	! z* 	!KK 	! 	!	$ 	$	% 	%	! 	!	! 	!/   C(-C4D D(C14C= D	Dc                 2   d\  }}t         j                  j                  ||f      }t         j                  j                  ||fd      }d}|j                         }d}|dz
  |dz
  f}|j	                  ||       |j	                  t        |      |       | j                  |j                  |      |       | j                  |j                         |       | j                  |j                  |      |       | j                  |j                         |       y)z)Ensure individual mask bits are set to 1.r      Tr   r   )rU   r   N)r
   r!   r   r^   r   r   rO   r   	ru   r8   r9   r   rx   mask0_expected_countmask1_expected_countexpected_bitrU   s	            r   test_set_atzMaskTypeTest.test_set_at  s    v  %1  %t < ${{}qy&1*%S,'\:c*L9(<=c*L9(<=r   c                 $   d\  }}t         j                  j                  ||f      }t         j                  j                  ||fd      }d}|j                         dz
  }d}|dz
  |dz
  f}|j	                  ||       |j	                  ||       | j                  |j                  |      |       | j                  |j                         |       | j                  |j                  |      |       | j                  |j                         |       y)z)Ensure individual mask bits are set to 0.rq   r   Tr   r   r   Nr
   r!   r   r^   r   rO   r   r   s	            r   test_set_at__to_0zMaskTypeTest.test_set_at__to_0  s    v  %1  %t < ${{}q0qy&1*%S,'S,'c*L9(<=c*L9(<=r   c                    d\  }}t         j                  j                  ||f      }t         j                  j                  ||fd      }d}|j                         }d}|dz
  |dz
  f}|j	                  |       |j	                  |       | j                  |j                  |      |       | j                  |j                         |       | j                  |j                  |      |       | j                  |j                         |       y)z<Ensure individual mask bits are set using the default value.)r      Tr   r   Nr  r   s	            r   test_set_at__default_valuez'MaskTypeTest.test_set_at__default_value	  s    v  %1  %t < ${{}qy&1*%SSc*L9(<=c*L9(<=r   c                 0   d\  }}t         j                  j                  ||f      }| j                  t              5  |j                  |df       ddd       | j                  t              5  |j                  d|f       ddd       | j                  t              5  |j                  d       ddd       | j                  t              5  |j                  d       ddd       y# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   QxY w# 1 sw Y   yxY w)zEnsure set_at() checks bounds.r   r   Nrm   rk   r
   r!   r   r|   r   r   r   s       r   test_set_at__out_of_boundsz'MaskTypeTest.test_set_at__out_of_bounds  r   r   c                    d}d}d}d|i}dD ]0  }t         j                  j                  ||      }|j                         }dD ]  }||f}	d|	 }
t         j                  j                  ||      }|j                         }|j	                  |	|      }|j                  ||      }| j                  |||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
        3 y)aX  Ensure the overlap intersection is correctly calculated.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap 1 (mask2-filled)
            (mask1-empty)  0 overlap 1 (mask2-filled)
            (mask1-filled) 1 overlap 0 (mask2-empty)
            (mask1-empty)  0 overlap 0 (mask2-empty)
        r   r   r/   NTTr   r   key=)r
   r!   r   r^   getoverlaprO   r   )ru   rw   offsetexpected_defaultexpected_overlapsfill2ry   mask2_countfill1r"   r]   rx   mask1_countexpected_posoverlap_poss                  r   test_overlapzMaskTypeTest.test_overlap,  s6    )62" 	GEKK$$]$?E++-K& GenSEl((U(C#kkm044S:JK#mmE6:  lC@   SA  SA  !1=#F  !1=#FG		Gr   c                    t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }| j
                  D ]  }d| }t        |d   d      t        |d   d      f}	|j                  ||      }
| j                  |
|	|       | j                  |j                         ||       | j                  |j                         ||       | j                  |j	                         ||       | j                  |j	                         ||        y	)
z>Ensure an offset overlap intersection is correctly calculated.r   Tr   r   r   offset=r   r   otherr  N)	r
   r!   r   r^   r   ORIGIN_OFFSETSr&   r  rO   )ru   rx   ry   r  r  
mask1_size
mask2_sizer  r]   r  r  s              r   test_overlap__offsetz!MaskTypeTest.test_overlap__offsetO  s-     t 4  t 4kkmkkm^^%
^^%
)) 	@FF8$Cq	1-s6!9a/@AL--eF-CK[,< U[[]K=U[[]K=U^^-z3?U^^-z3?	@r   c                    t         j                  j                  dd      }t         j                  j                  dd      }d}|j                  |d       |j                  |d       |j	                         }|j	                         }|j                         }|j                         }| j                  D ]G  }d| }	|\  }
}t        |d      }d|k(  rt        |
dz   d      }n!d|k  rt        |
dz   d      }nt        |
d      }|j                  |t        |            }| j                  |||f|	       | j                  |j	                         ||	       | j                  |j	                         ||	       | j                  |j                         ||	       | j                  |j                         ||	       | j                  |j                  |      d|	       | j                  |j                  |      d|	       J y	)
z_Ensure an offset overlap intersection is correctly calculated
        when (0, 0) bits not set.r   Tr   r  r/   r   r   r   N)r
   r!   r   r   r^   r   r#  r&   r  r   rO   r   )ru   rx   ry   	unset_posr  r  r$  r%  r  r]   r   r   
expected_y
expected_xr  s                  r   $test_overlap__offset_with_unset_bitsz1MaskTypeTest.test_overlap__offset_with_unset_bitsf  s      t 4  t 4	Y"Y"kkmkkm^^%
^^%
)) 	>FF8$CDAqQJAv Q]
Q Q]
 AY
--wv?K[:z*BCH U[[]K=U[[]K=U^^-z3?U^^-z3?U\\)4a=U\\)4a=+	>r   c                    t         j                  j                  dd      }|j                         }|j	                         }d\  }}||f}t         j                  j                  |      }|dz
  |dz
  f}|j                  |       d}	| j                  D ]  }
d|
 }|j                  ||
      }| j                  ||       | j                  |j                         ||       | j                  |j                         |	|       | j                  |j	                         ||       | j                  |j	                         ||       | j                  |j                  |      d|        y)z_Ensure an offset overlap intersection is correctly calculated
        when there is no overlap.r   Tr   )C   r   r   r   N)r
   r!   r   r^   r   r   r#  r  assertIsNonerO   r   )ru   rx   r  r$  mask2_wmask2_hr%  ry   set_posr  r  r]   r  s                r   test_overlap__no_overlapz%MaskTypeTest.test_overlap__no_overlap  s?      t 4kkm^^%
 w'
  ,Q;!,W)) 	<FF8$C--v6Kk3/ U[[]K=U[[]K=U^^-z3?U^^-z3?U\\'2As;	<r   c                    t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }|d   dfd|d   f|d    dfd|d    ff}|D ]  }d| }	|j                  ||      }
| j                  |
|	       | j                  |j                         ||	       | j                  |j                         ||	       | j                  |j	                         ||	       | j                  |j	                         ||	        y)	z9Ensures overlap handles offsets and boundaries correctly.)r   r   Tr   r   r   r   r   r   N)r
   r!   r   r^   r   r  r.  rO   )ru   rx   ry   r  r  r$  r%  offsetsr  r]   r  s              r   test_overlap__offset_boundaryz*MaskTypeTest.test_overlap__offset_boundary  sB     t 4  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
  	@FF8$C--v6Kk3/ U[[]K=U[[]K=U^^-z3?U^^-z3?	@r   c                    t        dd      D ]A  }t        dd      D ].  }||f}||z  }t        j                  j                  |d      }t        j                  j                  |d      }| j                  D ]  }d| d| }t        |d   d      t        |d	   d      f}	|j                  ||      }
| j                  |
|	|       | j                  |j                         ||       | j                  |j                         ||       | j                  |j                         ||       | j                  |j                         ||        1 D y
)zEnsures overlap handles masks of different sizes correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r	   r   r   Tr   r   	, offset=r   r   N)
r   r
   r!   r   r#  r&   r  rO   r^   r   )ru   r9   r8   	mask_size
mask_countrx   ry   r  r]   r  r  s              r   test_overlap__bit_boundariesz)MaskTypeTest.test_overlap__bit_boundaries  sG    Aqk 	GFq" G"FO	"V^
(((>(((> #11 GF!)IfX>C$'q	1$5s6!9a7H#IL"'--v">K$$[,D $$U[[]JD$$U[[]JD$$U^^%5y#F$$U^^%5y#FGG	Gr   c                     d}d}t         j                  j                  |      }t        j                  |      }| j	                  t
              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z8Ensure overlap handles invalid mask arguments correctly.r   r   r/   N)r
   r!   r   Surfacer|   r   r  )ru   r   r  r!   invalid_maskr  s         r   test_overlap__invalid_mask_argz+MaskTypeTest.test_overlap__invalid_mask_arg  sc     {{%~~d+y) 	=,,|V<K	= 	= 	=   A**A3c                     d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  t              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z:Ensure overlap handles invalid offset arguments correctly.)r	   r   (0, 0)N)r
   r!   r   r|   r   r  )ru   r   r  rx   ry   r  s         r    test_overlap__invalid_offset_argz-MaskTypeTest.test_overlap__invalid_offset_arg  sg      &  &y) 	7--v6K	7 	7 	7   A44A=c                    dx}\  }}d}d}d||z  i}dD ]0  }t         j                  j                  ||      }|j                         }	dD ]  }
|
|f}d| }t         j                  j                  ||
      }|j                         }|j	                  ||      }|j                  ||      }| j                  |||       | j                  |j                         ||       | j                  |j                         |	|       | j                  |j                         ||       | j                  |j                         ||        3 y)	ad  Ensure the overlap_area is correctly calculated.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap_area 1 (mask2-filled)
            (mask1-empty)  0 overlap_area 1 (mask2-filled)
            (mask1-filled) 1 overlap_area 0 (mask2-empty)
            (mask1-empty)  0 overlap_area 0 (mask2-empty)
        r  r/   r   r  r   r   r  N)r
   r!   r   r^   r  r_   rO   r   )ru   rw   r8   r9   r  r  expected_countsr  ry   r  r  r"   r]   rx   r  rv   overlap_counts                    r   test_overlap_areazMaskTypeTest.test_overlap_area  sD    )/.v'8" 	GEKK$$]$?E++-K& GenSEl((U(C#kkm!0!4!4S:J!K % 2 25& A  D   SA  SA  !1=#F  !1=#FG		Gr   c                 *   t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }|j                         }|j                         }| j                  D ]  }	d|	 }
|	|_        |j                  |      }|j                  |j                  z  }|j                  ||	      }| j                  |||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j	                         ||
       | j                  |j	                         ||
        y)z6Ensure an offset overlap_area is correctly calculated.r   Tr   r  r   r!  N)r
   r!   r   r^   r   rM   r#  r   rL   r   r   r_   rO   )ru   rx   ry   r  r  r$  r%  rect1rect2r  r]   overlap_rectrv   rH  s                 r   test_overlap_area__offsetz&MaskTypeTest.test_overlap_area__offset  sS      t 4  t 4kkmkkm^^%
^^%
   )) 	@FF8$C"EM ::e,L)^^lnn<N!..U6.JM]NC@ U[[]K=U[[]K=U^^-z3?U^^-z3?	@r   c                    t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }d}|d   dfd|d   f|d    dfd|d    ff}|D ]  }	d|	 }
|j                  |t        |	            }| j                  |||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j	                         ||
       | j                  |j	                         ||
        y)	z>Ensures overlap_area handles offsets and boundaries correctly.r   Tr   r   r   r   r   N)r
   r!   r   r^   r   r_   r   rO   )ru   rx   ry   r  r  r$  r%  rv   r5  r  r]   rH  s               r   "test_overlap_area__offset_boundaryz/MaskTypeTest.test_overlap_area__offset_boundary9  sO     t 4  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
  	@FF8$C!..ugfoFM]NC@ U[[]K=U[[]K=U^^-z3?U^^-z3?	@r   c                    t        dd      D ]t  }t        dd      D ]a  }||f}||z  }t        j                  j                  |d      }t        j                  j                  |d      }|j	                         }|j	                         }| j
                  D ]  }	d| d|	 }
|	|_        |j                  |      }|j                  |j                  z  }|j                  ||	      }| j                  |||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
        d w y)	zEnsures overlap_area handles masks of different sizes correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r	   r   r   Tr   r   r8  N)r   r
   r!   r   rM   r#  r   rL   r   r   r_   rO   r^   r   )ru   r9   r8   r9  r:  rx   ry   rK  rL  r  r]   rM  expected_overlap_countrH  s                 r   !test_overlap_area__bit_boundariesz.MaskTypeTest.test_overlap_area__bit_boundariesX  sl    Aqk 	GFq" G"FO	"V^
(((>(((> (( #11 GF!)IfX>C$*EM#(::e#4L-9^^lnn-L*$)$6$6uf$EM$$]4JCP $$U[[]JD$$U[[]JD$$U^^%5y#F$$U^^%5y#FGG	Gr   c                     d}d}t         j                  j                  |      }t        j                  |      }| j	                  t
              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z=Ensure overlap_area handles invalid mask arguments correctly.r   r   r/   N)r
   r!   r   r>  r|   r   r_   )ru   r   r  r!   r?  rH  s         r   #test_overlap_area__invalid_mask_argz0MaskTypeTest.test_overlap_area__invalid_mask_arg|  sg    {{%~~d+y) 	D --lFCM	D 	D 	DrA  c                     d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  t              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z?Ensure overlap_area handles invalid offset arguments correctly.)r   r	   rC  N)r
   r!   r   r|   r   r_   )ru   r   r  rx   ry   rH  s         r   %test_overlap_area__invalid_offset_argz2MaskTypeTest.test_overlap_area__invalid_offset_arg  si      &  &y) 	>!..uf=M	> 	> 	>rE  c                 N   d}d}t         j                  j                  |      }dt         j                  j                  |d      i}dD ]Y  }t         j                  j                  ||      }|j                         }dD ]  }||f}	d|	 }
t         j                  j                  ||      }|j                         }|j	                  |	|      }|j                  ||      }| j                  |t         j                  j                  |
       t        | |||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
       | j                  |j                         ||
       " \ y	)
ad  Ensure overlap_mask's mask has correct bits set.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap_mask 1 (mask2-filled)
            (mask1-empty)  0 overlap_mask 1 (mask2-filled)
            (mask1-filled) 1 overlap_mask 0 (mask2-empty)
            (mask1-empty)  0 overlap_mask 0 (mask2-empty)
        r  r/   r  Tr   r   r  r!  N)
r
   r!   r   r^   r  overlap_maskrt   rc   rO   r   )ru   rw   r  r  expected_masksr  ry   r  r  r"   r]   rx   r  expected_maskrZ  s                  r   test_overlap_maskzMaskTypeTest.test_overlap_mask  su    !;;++M:&(8(8T(8(RS" 	GEKK$$]$?E++-K& GenSEl((U(C#kkm . 2 238H I$11f1M%%lFKK4D4DcJlM3G   SA  SA  !1=#F  !1=#F!G		Gr   c                 Z   t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }|j                  |d      }t        d      D ]=  }t        d      D ]-  }	| j                  |j                  ||	f      dd	| d
|	 d       / ? t        d      D ]>  }t        dd      D ]-  }	| j                  |j                  ||	f      dd	| d
|	 d       / @ | j                  |j                         |       | j                  |j                         |       | j                  |j	                         |       | j                  |j	                         |       y)z0Ensure overlap_mask's mask has correct bits set.2   r`  Tr   )i,  
   rm   r`  ra  r   (, )rq   r   N)	r
   r!   r   r^   r   rZ  r   rO   r   )
ru   rx   ry   r  r  r$  r%  mask3r   js
             r   test_overlap_mask__bits_setz(MaskTypeTest.test_overlap_mask__bits_set  s       5   6kkmkkm^^%
^^%
""5'2r 	IA2Y I  q!f!5qAaS1#Q-HI	I r 	IA2r] I  q!f!5qAaS1#Q-HI	I
 	44):6):6r   c                    t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }t        j                  |      }|j                         }|j                         }	| j                  D ]:  }
d|
 }|
|	_        |j                  |	      }|j                          |j                  t        j                  |j                  d      |j                         |j                  ||
      }| j                  |t         j                  j                  |       t        | |||       | j                  |j                         ||       | j                  |j                         ||       | j                  |j	                         ||       | j                  |j	                         ||       = y)z=Ensure an offset overlap_mask's mask is correctly calculated.r   Tr   r  r   N)r
   r!   r   r^   r   rM   r#  r   rL   cleardrawr   rZ  rt   rc   rO   )ru   rx   ry   r  r  r$  r%  r\  rK  rL  r  r]   rM  rZ  s                 r   test_overlap_mask__offsetz&MaskTypeTest.test_overlap_mask__offset  s     t 4  t 4kkmkkm^^%
^^%
J/   )) 	@FF8$C"EM ::e,L!L--D9<;O;O !--eV<L!!,0@0@#FD,sC U[[]K=U[[]K=U^^-z3?U^^-z3?%	@r   c           	         t         j                  j                  dd      }t         j                  j                  dd      }t        j                  |j                               }|j	                         }|j	                         }|j                  dd      }dD ]  }t        ||t        ||             |j                  }d| }	|j                  |      }
|j                          |j                  t        j                  |
j                  d      |
j                         |j                  ||      }| j                  |t         j                  j                  |	       t        | |||	        y)	a  Ensure an offset overlap_mask's mask is correctly calculated.

        Testing the specific case of:
            -both masks are wider than 32 bits
            -a positive offset is used
            -the mask calling overlap_mask() is wider than the mask passed in
        r   r   Tr   r   r   r   r   r   r   r   N)r
   r!   r   r   rM   inflater   getattrr   rL   ri  rj  r   rZ  rt   rc   )ru   rx   ry   r\  rK  rL  corner_rectcornerr  r]   rM  rZ  s               r   #test_overlap_mask__specific_offsetsz0MaskTypeTest.test_overlap_mask__specific_offsets  s2      t 4  t 4ENN$45    mmB+J 	DFE67;#?@]]FF8$C ::e,L!L--D9<;O;O !--eV<L!!,0@0@#FD,sC	Dr   c                 j   t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }d}|}|d   dfd|d   f|d    dfd|d    ff}	|	D ]  }
d|
 }|j                  ||
      }| j                  |t         j                  j                  |       | j                  |j                         ||       | j                  |j	                         ||       | j                  |j                         ||       | j                  |j                         ||       | j                  |j	                         ||       | j                  |j	                         ||        y)	z>Ensures overlap_mask handles offsets and boundaries correctly.)	   r   Tr   )rq   r   r   r   r   N)r
   r!   r   r^   r   rZ  rt   rO   )ru   rx   ry   r  r  r$  r%  rv   rw   r5  r  r]   rZ  s                r   "test_overlap_mask__offset_boundaryz/MaskTypeTest.test_overlap_mask__offset_boundary  s     d 3  t 4kkmkkm^^%
^^%
" ]A
1m^QA	
  	@FF8$C --eV<L!!,0@0@#F\//1>3G\224mSI U[[]K=U[[]K=U^^-z3?U^^-z3?	@r   c           	         t        dd      D ]  }t        dd      D ]  }||f}||z  }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  |      }|j	                         }|j	                         }	| j
                  D ]=  }
d| d|
 }|
|	_        |j                  |	      }|j                          |j                  t        j                  |j                  d      |j                         |j                  ||
      }| j                  |t        j                  j                  |       t        | |||       | j                  |j                         ||       | j                  |j                         ||       | j                  |j!                         ||       | j                  |j!                         ||       @   y)	zEnsures overlap_mask handles masks of different sizes correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r	   r   r   Tr   r   r8  N)r   r
   r!   r   rM   r#  r   rL   ri  rj  r   rZ  rt   rc   rO   r^   r   )ru   r9   r8   r9  r:  rx   ry   r\  rK  rL  r  r]   rM  rZ  s                 r   !test_overlap_mask__bit_boundariesz.MaskTypeTest.test_overlap_mask__bit_boundaries6  s    Aqk 	GFq" G"FO	"V^
(((>(((> &I 6 (( #11 GF!)IfX>C$*EM#(::e#4L!'')!&&L$5$5DA<CWCW $)#5#5eV#DL)),8H8H#N#D,sK $$U[[]JD$$U[[]JD$$U^^%5y#F$$U^^%5y#F%GG	Gr   c                     d}d}t         j                  j                  |      }t        j                  |      }| j	                  t
              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z=Ensure overlap_mask handles invalid mask arguments correctly.r   r/   N)r
   r!   r   r>  r|   r   rZ  )ru   r   r  r!   r?  rZ  s         r   #test_overlap_mask__invalid_mask_argz0MaskTypeTest.test_overlap_mask__invalid_mask_arg_  sg    {{%~~d+y) 	C,,\6BL	C 	C 	CrA  c                     d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  t              5  |j                  ||      }ddd       y# 1 sw Y   yxY w)z?Ensure overlap_mask handles invalid offset arguments correctly.r   r	   rC  N)r
   r!   r   r|   r   rZ  )ru   r   r  rx   ry   rZ  s         r   %test_overlap_mask__invalid_offset_argz2MaskTypeTest.test_overlap_mask__invalid_offset_argi  si      &  &y) 	= --eV<L	= 	= 	=rE  c                    t        j                  d      j                  dd       | j                  j	                  d      d       j                  dd       | j                  j	                  d      d       | j                  t        fd       | j                  t        fd       | j                  t        fd       | j                  t        fd       y	)
z/do the set_at, and get_at parts work correctly?ra  ra  r/   r   )rw  r   c                  &     j                  d      S )Nrm   )r   r   s   r   <lambda>z/MaskTypeTest.test_mask_access.<locals>.<lambda>  s    ahhw.? r   c                  (     j                  dd      S )Nrm   r   r   r  s   r   r  z/MaskTypeTest.test_mask_access.<locals>.<lambda>      ahhw.B r   c                  (     j                  dd      S )Nra  r   r   r  r  s   r   r  z/MaskTypeTest.test_mask_access.<locals>.<lambda>  r  r   c                  (     j                  dd      S )Nr   ra  r   r  r  s   r   r  z/MaskTypeTest.test_mask_access.<locals>.<lambda>  r  r   N)r
   r   r   rO   r   r|   r   ru   r   s    @r   test_mask_accesszMaskTypeTest.test_mask_accesss  s    KK!	&)1-	&)1- 	*&?@*&BC*&BC*&BCr   c                     d\  }}||z  }||f}t         j                  j                  |      }|j                          | j	                  |j                         |       | j	                  |j                         |       y)zEnsure a mask can be filled.rp   N)r
   r!   r   r   rO   r^   r   )ru   r8   r9   rv   rw   r!   s         r   	test_fillzMaskTypeTest.test_fill  sf    v{{.		~6-8r   c                    t        dd      D ]q  }t        dd      D ]`  }t        j                  j                  ||f      }||z  }|j	                          | j                  |j                         |d| d| d       b s y)zEnsures masks of different sizes are filled correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r   r   r   size=(rc  rd  N)r   r
   r!   r   r   rO   r^   )ru   r9   r8   r!   rv   s        r   test_fill__bit_boundariesz&MaskTypeTest.test_fill__bit_boundaries  s     Aqk 		Fq" {{''8!&		  JJL.F5'F812M		r   c                     d}d}t         j                  j                  |d      }|j                          | j	                  |j                         |       | j	                  |j                         |       y)zEnsure a mask can be cleared.r   r      Tr   N)r
   r!   r   ri  rO   r^   r   ru   rv   rw   r!   s       r   
test_clearzMaskTypeTest.test_clear  sZ     {{D9

~6-8r   c                    d}t        dd      D ]n  }t        dd      D ]]  }t        j                  j                  ||fd      }|j	                          | j                  |j                         |d| d| d	       _ p y
)zEnsures masks of different sizes are cleared correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r   r   r   r   Tr   r  rc  rd  N)r   r
   r!   r   ri  rO   r^   )ru   rv   r9   r8   r!   s        r   test_clear__bit_boundariesz'MaskTypeTest.test_clear__bit_boundaries  s     Aqk 	Fq" {{''d'C

  JJL.F5'F812M	r   c                    d}||f}t         j                  j                  |      }t         j                  j                  |d      }||z  }d}t        |      D ]3  }|dz  }|dz  }||f}|j	                  |       |j	                  |d       5 |j                          |j                          | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       t        |      D ]O  }||f}d| }	| j                  |j                  |      d|	       | j                  |j                  |      d|	       Q y)zEnsure a mask can be inverted.r   Tr   r   r   zpos=N)
r
   r!   r   r   r   invertrO   r^   r   r   )
ru   siderw   rx   ry   expected_count1expected_count2r   rU   r]   s
             r   test_invertzMaskTypeTest.test_invert  sb    t  /  T :+t 	!Aq Oq Oa&CLLLLa 	! 	88)=9)=9t 	8Aa&C,CU\\#.37U\\#.37	8r   c                     d}d}t         j                  j                  |d      }|j                          | j	                  |j                         |       | j	                  |j                         |       y)z#Ensure a full mask can be inverted.r   +   a   Tr   Nr
   r!   r   r  rO   r^   r   r  s       r   test_invert__fullzMaskTypeTest.test_invert__full  sZ     {{D9~6-8r   c                     d\  }}||f}||z  }t         j                  j                  |      }|j                          | j	                  |j                         |       | j	                  |j                         |       y)z%Ensure an empty mask can be inverted.r  Nr  )ru   r8   r9   rw   rv   r!   s         r   test_invert__emptyzMaskTypeTest.test_invert__empty  sf    v{{.~6-8r   c                 $   dD ]  }t        dd      D ]z  }t        dd      D ]i  }t        j                  j                  ||f|      }|rdn||z  }|j	                          | j                  |j                         |d| d| d	| d
       k |  y)zEnsures masks of different sizes are inverted correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r   r   r   r   r   r   r   , size=(rc  rd  N)r   r
   r!   r   r  rO   r^   )ru   r   r9   r8   r!   rv   s         r   test_invert__bit_boundariesz(MaskTypeTest.test_invert__bit_boundaries  s     " 	D1+ "1b\ 
E!;;++UFO$+GD*.QEFNNKKM$$

&vXeWBvha@
	r   c                 |   d\  }}||f}dD ]-  }t         j                  j                  ||      }|r||z  nd}t        |dz
  |dz         D ]  }t        |dz
  |dz         D ]  }||f}	|r||z  nd}
d|	 }|j	                  |	      }| j                  |t         j                  j                  |       | j                  |j                         |
|       | j                  |j                         |	       | j                  |j                         ||       | j                  |j                         ||         0 y)	zEnsure a mask can be scaled.)r  =   r   r   r   ra  r   )scaleN)	r
   r!   r   r   r  rt   rO   r^   r   )ru   r8   r9   original_sizer   original_maskoriginal_countnew_wnew_hrw   rv   r]   r!   s                r   
test_scalezMaskTypeTest.test_scale  sF    v! 	SD"KK,,],FM/3UV^N urz52:6 S"6B;< SE%*ENM6:UU]N!-1C(..].CD))$0@0@#F$$TZZ\>3G$$T]]_mD $$]%8%8%:NCP$$]%;%;%=}cRSS	Sr   c                    t        j                  d      }| j                  t              5  |j	                  d       ddd       | j                  t              5  |j	                  t        dd             ddd       | j                  t              5  |j	                  d       ddd       y# 1 sw Y   rxY w# 1 sw Y   ExY w# 1 sw Y   yxY w)z.Ensure scale handles negative sizes correctly.d   r  rl   Nrj   ra  )ra  rj   )r
   r   r|   r}   r  r   ru   r!   s     r   test_scale__negative_sizez&MaskTypeTest.test_scale__negative_size,  s    {{:&z* 	!JJx 	! z* 	(JJwr2'	( z* 	!JJx 	! 	!	! 	!	( 	(	! 	!s#   B.B:C.B7:CCc                 J   d}d}t         j                  j                  |d      }dt         j                  j                  |      i}dD ]  }t         j                  j                  ||      }|j                         }dD ]  }||f}	d|	 }
t         j                  j                  ||      }|j	                  |	|      }|j                  ||       t        | |||
       | j                  |j                         ||
       | j                  |j                         ||
         y)	aA  Ensure a mask can be drawn onto another mask.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 draw 1 (mask2-filled)
            (mask1-empty)  0 draw 1 (mask2-filled)
            (mask1-filled) 1 draw 0 (mask2-empty)
            (mask1-empty)  0 draw 0 (mask2-empty)
        r  r/   Tr   )FFr   r  N)	r
   r!   r   r^   r  rj  rc   rO   r   ru   rw   r  r  r[  r  ry   r  r  r"   r]   rx   r\  s                r   	test_drawzMaskTypeTest.test_draw9  s    !;;++M+E(&++*:*:=*IJ" 	GEKK$$]$?E++-K& GenSEl((U(C . 2 238H I

5&)e]C@   SA  !1=#FG		Gr   c                 j   t         j                  j                  d      }t         j                  j                  dd      }|j                         }|j	                         }t        j                  |j	                               }|j                         }|j                         }| j                  D ]   }d| }	||_        |j                  |      }
|j                          t        |
j                  |
j                        D ]:  }t        |
j                  |
j                        D ]  }|j                  ||f        < |j                          |j!                  ||       t#        | |||	       | j%                  |j                         ||	       | j%                  |j	                         ||	        y)z5Ensure an offset mask can be drawn onto another mask.r   r  Tr   r   r!  N)r
   r!   r   r^   r   rM   r#  r   rL   ri  r   r>   r@   r?   rA   r   rj  rc   rO   ru   rx   ry   r  r%  r\  rK  rL  r  r]   rM  r   r   s                r   test_draw__offsetzMaskTypeTest.test_draw__offsetY  sm     )  t 4kkm^^%
ENN$45   )) 	@FF8$C"EM ::e,L! <,,l.@.@A 1|//1D1DE 1A!((!Q011 KKMJJU6J2D%< U[[]K=U^^-z3?'	@r   c           	         t         j                  j                  d      }t         j                  j                  dd      }t        j                  |j                               }|j	                         }|j	                         }|j                  dd      }dD ]  }t        ||t        ||             |j                  }d| }	|j                  |      }
|j                          t        |
j                  |
j                        D ]:  }t        |
j                  |
j                        D ]  }|j!                  ||f        < |j                          |j#                  ||       t%        | |||	        y)	a  Ensure an offset mask can be drawn onto another mask.

        Testing the specific case of:
            -both masks are wider than 32 bits
            -a positive offset is used
            -the mask calling draw() is wider than the mask passed in
        rm  rn  Tr   ro  rp  r   N)r
   r!   r   r   rM   rq  r   rr  r   rL   ri  r   r>   r@   r?   rA   r   rj  rc   ru   rx   ry   r\  rK  rL  rs  rt  r  r]   rM  r   r   s                r   test_draw__specific_offsetsz(MaskTypeTest.test_draw__specific_offsetsz  sB      )  t 4ENN$45    mmB+J 	=FE67;#?@]]FF8$C ::e,L! <,,l.@.@A 1|//1D1DE 1A!((!Q011 KKMJJuf%D%<!	=r   c                    t         j                  j                  d      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }|d   dfd|d   f|d    dfd|d    ff}|D ]  }d| }	|j                  ||       | j                  |j                         ||	       | j                  |j                         ||	       | j                  |j	                         ||	       | j                  |j	                         ||	        y)	z6Ensures draw handles offsets and boundaries correctly.)r   r   r   Tr   r   r   r   N)r
   r!   r   r^   r   rj  rO   
ru   rx   ry   r  r  r$  r%  r5  r  r]   s
             r   test_draw__offset_boundaryz'MaskTypeTest.test_draw__offset_boundary  s+     )  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
  		@FF8$CJJuf% U[[]K=U[[]K=U^^-z3?U^^-z3?		@r   c           	      p   t        dd      D ]  }t        dd      D ]  }||f}||z  }t        j                  j                  |      }t        j                  j                  |d      }t        j                  |      }|j	                         }|j	                         }	| j
                  D ]  }
d| d|
 }|
|	_        |j                  |	      }|j                          t        |j                  |j                        D ]:  }t        |j                  |j                        D ]  }|j                  ||f        < |j                          |j                  ||
       t        | |||       | j!                  |j#                         ||       | j!                  |j%                         ||          y)	zEnsures draw handles masks of different sizes correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r	   r   r   Tr   r   r8  N)r   r
   r!   r   rM   r#  r   rL   ri  r>   r@   r?   rA   r   rj  rc   rO   r^   r   ru   r9   r8   r9  r:  rx   ry   r\  rK  rL  r  r]   rM  r   r   s                  r   test_draw__bit_boundariesz&MaskTypeTest.test_draw__bit_boundaries  s    Aqk !	GFq"  G"FO	"V^
((3(((> &I 6 (( #11 GF!)IfX>C$*EM#(::e#4L!'')
 #<#4#4l6H6HI 9!&|'7'79L9L!M 9A)00!Q899 KKMJJuf-#D%D $$U[[]JD$$U^^%5y#F)G G!	Gr   c                     d}d}t         j                  j                  |      }t        j                  |      }| j	                  t
              5  |j                  ||       ddd       y# 1 sw Y   yxY w)z5Ensure draw handles invalid mask arguments correctly.r   r/   N)r
   r!   r   r>  r|   r   rj  ru   r   r  r!   r?  s        r   test_draw__invalid_mask_argz(MaskTypeTest.test_draw__invalid_mask_arg  s_    {{%~~d+y) 	,IIlF+	, 	, 	,rA  c                     d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  t              5  |j                  ||       ddd       y# 1 sw Y   yxY w)z7Ensure draw handles invalid offset arguments correctly.r   rC  N)r
   r!   r   r|   r   rj  ru   r   r  rx   ry   s        r   test_draw__invalid_offset_argz*MaskTypeTest.test_draw__invalid_offset_arg  se      &  &y) 	&JJuf%	& 	& 	&rE  c                 J   d}d}t         j                  j                  |      }dt         j                  j                  |d      i}dD ]  }t         j                  j                  ||      }|j                         }dD ]  }||f}	d|	 }
t         j                  j                  ||      }|j	                  |	|      }|j                  ||       t        | |||
       | j                  |j                         ||
       | j                  |j                         ||
         y)a=  Ensure a mask can erase another mask.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 erase 1 (mask2-filled)
            (mask1-empty)  0 erase 1 (mask2-filled)
            (mask1-filled) 1 erase 0 (mask2-empty)
            (mask1-empty)  0 erase 0 (mask2-empty)
        r  r/   r   Tr   r  N)	r
   r!   r   r^   r  eraserc   rO   r   r  s                r   
test_erasezMaskTypeTest.test_erase  s    !;;++M:')9)9-d)9)ST" 	GEKK$$]$?E++-K& GenSEl((U(C . 2 238H IE6*e]C@   SA  !1=#FG		Gr   c                 l   t         j                  j                  d      }t         j                  j                  dd      }|j                         }|j	                         }t        j                  |j	                               }|j                         }|j                         }| j                  D ]  }d| }	||_        |j                  |      }
|j                          t        |
j                  |
j                        D ];  }t        |
j                  |
j                        D ]  }|j                  ||fd        = |j                          |j!                  ||       t#        | |||	       | j%                  |j                         ||	       | j%                  |j	                         ||	        y)	z-Ensure an offset mask can erase another mask.r   r  Tr   r   r   r!  N)r
   r!   r   r^   r   rM   r#  r   rL   r   r   r>   r@   r?   rA   r   r  rc   rO   r  s                r   test_erase__offsetzMaskTypeTest.test_erase__offset  so     )  t 4kkm^^%
ENN$45   )) 	@FF8$C"EM ::e,L  <,,l.@.@A 4|//1D1DE 4A!((!Q344 JJLKKeFK3D%< U[[]K=U^^-z3?'	@r   c           	         t         j                  j                  d      }t         j                  j                  dd      }t        j                  |j                               }|j	                         }|j	                         }|j                  dd      }dD ]  }t        ||t        ||             |j                  }d| }	|j                  |      }
|j                          t        |
j                  |
j                        D ];  }t        |
j                  |
j                        D ]  }|j!                  ||fd        = |j                          |j#                  |t%        |             t'        | |||	        y	)
zEnsure an offset mask can erase another mask.

        Testing the specific case of:
            -both masks are wider than 32 bits
            -a positive offset is used
            -the mask calling erase() is wider than the mask passed in
        rm  rn  Tr   ro  rp  r   r   N)r
   r!   r   r   rM   rq  r   rr  r   rL   r   r   r>   r@   r?   rA   r   r  r   rc   r  s                r   test_erase__specific_offsetsz)MaskTypeTest.test_erase__specific_offsets<  sH      )  t 4ENN$45    mmB+J 	=FE67;#?@]]FF8$C ::e,L  <,,l.@.@A 4|//1D1DE 4A!((!Q344 JJLKKwv/D%<!	=r   c                    t         j                  j                  dd      }t         j                  j                  dd      }|j                         }|j                         }|j	                         }|j	                         }|d   dfd|d   f|d    dfd|d    ff}|D ]  }d| }	|j                  ||       | j                  |j                         ||	       | j                  |j                         ||	       | j                  |j	                         ||	       | j                  |j	                         ||	        y)	z7Ensures erase handles offsets and boundaries correctly.r   rq   Tr   )r   r   r   r   r   N)r
   r!   r   r^   r   r  rO   r  s
             r   test_erase__offset_boundaryz(MaskTypeTest.test_erase__offset_boundaryb  s0     t 4  t 4kkmkkm^^%
^^%
 ]A
1m^QA	
  		@FF8$CKKv& U[[]K=U[[]K=U^^-z3?U^^-z3?		@r   c           	      r   t        dd      D ]  }t        dd      D ]  }||f}||z  }t        j                  j                  |      }t        j                  j                  |d      }t        j                  |      }|j	                         }|j	                         }	| j
                  D ]  }
d| d|
 }|
|	_        |j                  |	      }|j                          t        |j                  |j                        D ];  }t        |j                  |j                        D ]  }|j                  ||fd        = |j                          |j                  ||
       t        | |||       | j!                  |j#                         ||       | j!                  |j%                         ||          y	)
zEnsures erase handles masks of different sizes correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r	   r   r   Tr   r   r8  r   N)r   r
   r!   r   rM   r#  r   rL   r   r>   r@   r?   rA   r   r  rc   rO   r^   r   r  s                  r   test_erase__bit_boundariesz'MaskTypeTest.test_erase__bit_boundaries~  s    Aqk !	GFq"  G"FO	"V^
((3(((> &I 6 (( #11 GF!)IfX>C$*EM#(::e#4L!&&(
 #<#4#4l6H6HI <!&|'7'79L9L!M <A)00!Q;<< JJLKKv.#D%D $$U[[]JD$$U^^%5y#F)G G!	Gr   c                     d}d}t         j                  j                  |      }t        j                  |      }| j	                  t
              5  |j                  ||       ddd       y# 1 sw Y   yxY w)z6Ensure erase handles invalid mask arguments correctly.r   r   r/   N)r
   r!   r   r>  r|   r   r  r  s        r   test_erase__invalid_mask_argz)MaskTypeTest.test_erase__invalid_mask_arg  s_    {{%~~d+y) 	-JJ|V,	- 	- 	-rA  c                     d}d}t         j                  j                  |      }t         j                  j                  |      }| j                  t              5  |j                  ||       ddd       y# 1 sw Y   yxY w)z8Ensure erase handles invalid offset arguments correctly.r4  rC  N)r
   r!   r   r|   r   r  r  s        r   test_erase__invalid_offset_argz+MaskTypeTest.test_erase__invalid_offset_arg  se      &  &y) 	'KKv&	' 	' 	'rE  c                 &   d}||f}d}t         j                  j                  |      }t        |      D ]  }|dz  }|j	                  ||f        |j                         }| j                  ||       | j                  |j                         |       y)z/Ensure a mask's set bits are correctly counted.r-  r   r   N)r
   r!   r   r   r   r^   rO   r   )ru   r  rw   rv   r!   r   r^   s          r   
test_countzMaskTypeTest.test_count  s    t{{.t 	 AaNKKA	  

/-8r   c                    dD ]  }t        dd      D ]  }t        dd      D ]  t        j                  j                  |f|      }|r|z  nd}fdt        |      D        D ]b  }|r|j	                  |d       |dz  }n|j	                  |d       |dz  }|j                         }| j                  ||d| d	 d
| d|        d    y)zEnsures the set bits of different sized masks are counted correctly.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r   r   r   r   r   r   c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r   r3   r   r   r8   s      r   r7   z:MaskTypeTest.test_count__bit_boundaries.<locals>.<genexpr>  s%     T1uU|T!ATT   !r   r  rc  z), pos=N)r   r
   r!   r   r   r^   rO   )ru   r   r9   r!   rv   rU   r^   r8   s          @r   test_count__bit_boundariesz'MaskTypeTest.test_count__bit_boundaries  s     " 	D1+ "1b\ E!;;++UFO$+GD7;UV^N  UfT  KKQ/*a/N KKQ/*a/N $

((!*#D6%6('#O	r   c                     d\  }}||f}||z  }t         j                  j                  |d      }|j                         }| j	                  ||       | j	                  |j                         |       y)z4Ensure a full mask's set bits are correctly counted.)r   r  Tr   Nr
   r!   r   r^   rO   r   )ru   r8   r9   rw   rv   r!   r^   s          r   test_count__full_maskz"MaskTypeTest.test_count__full_mask  sg    v{{D9

/-8r   c                     d}d}t         j                  j                  |      }|j                         }| j	                  ||       | j	                  |j                         |       y)z6Ensure an empty mask's set bits are correctly counted.r   r  Nr  )ru   rv   rw   r!   r^   s        r   test_count__empty_maskz#MaskTypeTest.test_count__empty_mask  sQ     {{.

/-8r   c                     t         j                  j                  dd      }|j                         j                  }|j                         }| j                  ||       y)z8Ensure a filled mask's centroid is correctly calculated.r   Tr   N)r
   r!   r   rM   r   centroidrO   )ru   r!   expected_centroidr  s       r   test_centroidzMaskTypeTest.test_centroid  sI    {{T2 MMO22==?#45r   c                     d}d}t         j                  j                  |      }|j                         }| j	                  ||       | j	                  |j                         |       y)z8Ensure an empty mask's centroid is correctly calculated.r/   )r   g   N)r
   r!   r   r  rO   r   )ru   r  rw   r!   r  s        r   test_centroid__empty_maskz&MaskTypeTest.test_centroid__empty_mask  sS    ""{{.==?#45-8r   c                 (   d\  }}t         j                  j                  ||f      }t        |      D ]^  }|j	                          t        |      D ]>  }|j                  ||f       |dz  |f}|j                         }| j                  ||       @ ` y)z`Ensure a mask's centroid is correctly calculated
        when setting points along a single row.r   r	   Nr
   r!   r   r   ri  r   r  rO   ru   r8   r9   r!   r   r   r  r  s           r   test_centroid__single_rowz&MaskTypeTest.test_centroid__single_row  s     v{{0v 		>AJJL5\ >QF#%&!VQK!==?  +<=>		>r   c                 V   d\  }}t         j                  j                  ||f      }t        d|      D ]t  }|j	                          t        |      D ]T  }|j                  |df       |j                  ||f       |dz  |dz  f}|j                         }| j                  ||       V v y)z\Ensure a mask's centroid is correctly calculated
        when setting points along two rows.r   r   r   r	   Nr  r  s           r   test_centroid__two_rowsz$MaskTypeTest.test_centroid__two_rows(  s     v{{0 q&! 
	>AJJL5\ >QF#QF#%&!VQ!V$4!==?  +<=>
	>r   c                 (   d\  }}t         j                  j                  ||f      }t        |      D ]^  }|j	                          t        |      D ]>  }|j                  ||f       ||dz  f}|j                         }| j                  ||       @ ` y)zcEnsure a mask's centroid is correctly calculated
        when setting points along a single column.r   r	   Nr  ru   r8   r9   r!   r   r   r  r  s           r   test_centroid__single_columnz)MaskTypeTest.test_centroid__single_column;  s     v{{0u 		>AJJL6] >QF#%&QK!==?  +<=>		>r   c                 V   d\  }}t         j                  j                  ||f      }t        d|      D ]t  }|j	                          t        |      D ]T  }|j                  d|f       |j                  ||f       |dz  |dz  f}|j                         }| j                  ||       V v y)z_Ensure a mask's centroid is correctly calculated
        when setting points along two columns.r   r   r   r	   Nr  r  s           r   test_centroid__two_columnsz'MaskTypeTest.test_centroid__two_columnsL  s     v{{0 q% 
	>AJJL6] >QF#QF#%&!VQ!V$4!==?  +<=>
	>r   c                     t         j                  j                  d      }|j                         j                  }t        |      D ]  }|j                  |        |j                         }| j                  ||       y)zREnsure a mask's centroid is correctly calculated
        when its corners are set.r   N)	r
   r!   r   rM   r   r<   r   r  rO   )ru   r!   r  rt  r  s        r   test_centroid__all_cornersz'MaskTypeTest.test_centroid__all_corners_  sg     {{' MMO22dm 	 FKK	  ==?#45r   c                    t         j                  j                  d      }|j                         }t	        |      }t        |      D ]  \  }}||dz   d D ]  }|j                          |j                  |       |j                  |       |d   |d   k(  r|d   t        |d   |d   z
        dz  f}n4|d   |d   k(  rt        |d   |d   z
        dz  |d   f}n|j                  }|j                         }| j                  ||         y)zWEnsure a mask's centroid is correctly calculated
        when only two corners are set.r   r   Nr   r	   )r
   r!   r   rM   r<   	enumerateri  r   absr   r  rO   )	ru   r!   	mask_rectmask_cornersr   corner1corner2r  r  s	            r   test_centroid__two_cornersz'MaskTypeTest.test_centroid__two_cornersl  s    {{'MMO	t}#L1 	>JAw'A0 >

G$G$1:+)0Sgaj9P5QUV5V(W%QZ71:-),WQZ'!*-D)E)JGTUJ(W%(1(8(8%==?  +<=>	>r   c                     d}d}t        j                  |      }t         j                  j                  |      }|j	                         }| j                  |t               | j                  ||       y)z:Ensure a mask's orientation angle is correctly calculated.g     Fr  N)r
   r>  r!   from_surfaceanglert   floatrO   )ru   expected_anglerw   r   r!   r
  s         r   
test_anglezMaskTypeTest.test_angle  sY    "../{{''0

eU+/r   c                     d}d}t         j                  j                  |      }|j                         }| j	                  |t
               | j                  ||       | j                  |j                         |       y)z5Ensure an empty mask's angle is correctly calculated.        )k   r  N)	r
   r!   r   r
  rt   r  assertAlmostEqualrO   r   )ru   r  rw   r!   r
  s        r   test_angle__empty_maskz#MaskTypeTest.test_angle__empty_mask  sa    !{{.

eU+un5-8r   c                    t        j                  d      }| j                  |j                         d       |j	                          | j                  |j                         d       t        j                  dd      }|j                  |d       | j                  |j                         d       |j                          | j                  |j                         d	       |j                  |d
       | j                  |j                         d       |j                          | j                  |j                         d       y)z%Test fill, clear, invert, draw, eraser  r   i'  r  Tr   r_  i&  r  r/      N)	r
   r   rO   r^   r   r  r  rj  ri  )ru   r   ra   s      r   test_drawingzMaskTypeTest.test_drawing  s    KK
#A&	E*[[-	HD)	
C(	r6C(		A&r   c                    t        j                  d      }| j                  |j                         g        |j	                  dd       | j                  |j                         dg       |j	                  dd       | j                  |j                  d      dg       |j	                  dd       | j                  |j                         g d       | j                  |j                  d	      g d
       y) )   r  r  r   ra     ra  rq   rq   )r  r  r  r  r  r	   )every)r  r  r  N)r
   r   rO   outliner   r  s     r   test_outlinezMaskTypeTest.test_outline  s     KK!b)	1xj1	12
3	1IIKK	
 	+-KLr   c           	         g d}|D ]  }t        j                  |      }|D ]  }t        j                  |      }|j                  |      }| j                  |t         j                  j                         dD ]M  }| j                  |j                         |   |j                         |   |j                         |   z   dz
         O   y )N)rg   )r   r   )r   r   r  rf   r   )r
   r   convolvert   r!   rO   r   )ru   r6   s1r`   s2ra   or   s           r   test_convolve__sizez MaskTypeTest.test_convolve__size  s    8 	BRB 	[[_KKO%%a)9)9: A$$

Qq)9BKKM!<L)Lq)P		r   c                    t        d      }t        j                  d      }|j                  d       |j	                  |      }| j                  |t        j                  j                         t        | ||       |j	                  |j	                  |            }| j                  |t        j                  j                         t        | ||       y)zaConvolving with a single point is the identity, while convolving a point with something flips it.r  rg   r/   N)r   r
   r   r   r   rt   r!   rc   )ru   r   kconvolve_masks       r   test_convolve__point_identitiesz,MaskTypeTest.test_convolve__point_identities  s    
#KK	

1mV[[-=-=>a/

1::a=1mV[[-=-=>a/r   c                 ~   t        d      }t        j                  d      }|j                  d       t        j                  d      }t        j                  d      }|j	                  ||       |j                  |d       | j                  |t        j                  j                         t        | ||       |j                          |j                          |j	                  ||t        dd             |j                  |d       | j                  |t        j                  j                         t        | ||       y	)
zGchecks that convolution modifies only the correct portion of the outputr  r	   r	   r/   r_  rg   ra  )r"  outputr  r  N)r   r
   r   r   r   rj  rt   r!   rc   ri  r   )ru   r   r&  r#  tests        r   test_convolve__with_outputz'MaskTypeTest.test_convolve__with_output  s     !KK	KK!{{8$	

1a		!Va!1!12a&		

	

1WR_
=		!Xa!1!12a&r   c                    t        j                  dd      }d}|D ]b  \  }}|j                  |d |      }| j                  |t         j                  j                         | j                  |j                         |       d y )Nr*  Tr   ))r   r   r   )r   r	   r   ))ro  ro  r   ))r1  r   )r
   r   r   rt   r!   rO   r^   )ru   fullpts_dataptrv   r'  s         r   test_convolve__out_of_rangez(MaskTypeTest.test_convolve__out_of_range  sr    {{6-K"* 	DB MM$b9M!!-1A1AB]002NC		Dr   c                    t        d      }t        d      }|j                  |      }| j                  |t        j                  j
                         t        |j                         d         D ]c  }t        |j                         d         D ]B  }| j                  |j                  ||f      dk(  |j                  ||dz
  |dz
  f      du        D e y)z#Tests the definition of convolutionr  r   r   c   N)r   r   rt   r
   r!   r   r   r   rO   r   r  )ru   r`   ra   convr   rf  s         r   test_convolvezMaskTypeTest.test_convolve  s     $${{2dFKK$4$45t}}q)* 	A4==?1-.   KKA'1,bjja"fa"f=M.NRV.V	r   c                     t         j                  j                  ||fd      }|j                  |dz  |dz  fd       |r$|j	                  ||       |j                          |S |j                  ||       |S )NTr   r	   r   )r
   r!   r   r   r  r  rj  )ru   r!   r   rU   inversepatterns         r   _draw_component_pattern_boxz(MaskTypeTest._draw_component_pattern_box  ss     ++""D$<d";	419-q1JJw$NN  IIgs#r   c                 <   t         j                  j                  ||f      }|dz
  }t        |      D ]/  }t        |      D ]  }||||z
  fv s|j	                  ||f       ! 1 |r$|j                  ||       |j                          |S |j                  ||       |S )Nr   r
   r!   r   r   r   r  r  rj  )	ru   r!   r   rU   r;  r<  r,   r   r   s	            r   _draw_component_pattern_xz&MaskTypeTest._draw_component_pattern_x'  s     ++""D$<0axt 	+A4[ +D1H%NNAq6*+	+
 JJw$NN  IIgs#r   c                 B   t         j                  j                  ||f      }|dz  x}}t        |      D ]0  }t        |      D ]   }	|	|k(  s||k(  s|j	                  |	|f       " 2 |r$|j                  ||       |j                          |S |j                  ||       |S )Nr	   r?  )
ru   r!   r   rU   r;  r<  xmidymidr   r   s
             r   _draw_component_pattern_plusz)MaskTypeTest._draw_component_pattern_plus=  s     ++""D$<0aitt 	+A4[ +9T	NNAq6*+	+
 JJw$NN  IIgs#r   c                    d\  }}||f}t         j                  j                  |      }g }d}| j                  |d|      }|j	                  ||f       d}||z
  df}| j                  |||      }|j	                  ||f       |dz  |dz  f}| j                  |d|      }|j	                  ||f       |d   \  }	}
|	j                         }t        d	 |D              }|j                         }| j                  |t         j                  j                         | j                  |j                         |       | j                  |j                         |       | j                  |j                  |	|
      |       | j                  |j                         |       | j                  |j                         |       |D ]5  \  }}| j                  |j                  ||      |j                                7 y
)z<Ensure a mask's connected component is correctly calculated.))   r  r/   r   r   r   r	   r   rj   c              3   B   K   | ]  \  }}|j                           y wrF   )r^   )r3   p_s      r   r7   z8MaskTypeTest.test_connected_component.<locals>.<genexpr>k  s     <41aQWWY<s   N)r
   r!   r   r@  appendrD  r=  r^   sumconnected_componentrt   rO   r   r_   )ru   r8   r9   rw   r  patternsr  r<  r   expected_patternexpected_offsetrv   r  r!   s                 r   test_connected_componentz%MaskTypeTest.test_connected_componentS  s   v((7 006J&)*$,"33M4P&)* 1*fk*22=!VL&)*,4RL)/)//1<8<<002dFKK$4$45~6-8.@.	

 	,,.?//1=A' 	OGV**7F;W]]_	r   c                    d}t         j                  j                  |d      }|j                         }|j	                         }| j                  |t         j                  j                         | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       y)zcEnsure a mask's connected component is correctly calculated
        when the mask is full.
        )rr   r   Tr   Nr
   r!   r   r^   rL  rt   rO   r   )ru   rw   r  rv   r!   s        r   #test_connected_component__full_maskz0MaskTypeTest.test_connected_component__full_mask  s     !((T(B&,,.002dFKK$4$45~6-8 	,,.?//1=Ar   c                    d}t         j                  j                  |      }|j                         }d}|j	                         }| j                  |t         j                  j                         | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       y)zdEnsure a mask's connected component is correctly calculated
        when the mask is empty.
        )r   r  r   NrR  )ru   rw   r  r  rv   r!   s         r   $test_connected_component__empty_maskz1MaskTypeTest.test_connected_component__empty_mask  s     !((7&,,.002dFKK$4$45~6-8 	,,.?//1=Ar   c                    d\  }}||f}t         j                  j                  |d      }|dz  |dz  }}||f}|dz
  |dz
  f}| j                  |d|d      }	d}
|j	                         }|j                  |      }| j                  |t         j                  j                         | j                  |j	                         |
       | j                  |j                         |       | j                  |j                  |	|      |
       | j                  |j	                         |       | j                  |j                         |       | j                  |j                  |	|      |
       y)	zEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is set with a connected component of 1 bit.
        )r   r-  Tr   r	   r   r   )r;  N)
r
   r!   r   r=  r^   rL  rt   rO   r   r_   )ru   r8   r9   rw   r  xsetysetr1  rO  rN  rv   r  r!   s                r   %test_connected_component__one_set_bitz2MaskTypeTest.test_connected_component__one_set_bit  s^    v((T(BaZ1d,!8TAX.  ;;1ot < 
 &,,.009dFKK$4$45~6-8.@.	

 	,,.?//1=A&&'7I	
r   c                    d}t         j                  j                  |      }d\  }}dx}\  }}|dz
  |dz
  f}t         j                  j                  ||fd      }	t        d|      D ]5  }
t        d|      D ]$  }||
|
dz
  |dz
  fv s|	j	                  ||
fd	       & 7 |	j                         }|j                  |	|       |j                  |      }| j                  |t         j                  j                         | j                  |j                         |       | j                  |j                         |       | j                  |j                  |	|      |       | j                  |j                         |       | j                  |j                         |       | j                  |j                  |	|      |       y
)zEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is set with a connected component of > 1 bit.
        )q   r-  r   )rq   r	  r   Tr   r   r   r   N)r
   r!   r   r   r   r^   rj  rL  rt   rO   r   r_   )ru   rw   r  p_widthp_heightr1  rW  rX  rO  rN  r   r   rv   r!   s                 r   (test_connected_component__multi_set_bitsz5MaskTypeTest.test_connected_component__multi_set_bits  s    "((7"%%*$!8TAX.!;;++Wh,?d+K q(# 	7A1g& 7AE7Q;//$++QFA67	7
 *//1+_=009dFKK$4$45~6-8.@.	

 	,,.?//1=A&&'7I	
r   c                 l   d\  }}||f}t         j                  j                  |d      }|dz  |dz  f}|j                  |d       |j	                         }d}|j                  |      }| j                  |t         j                  j                         | j                  |j	                         |       | j                  |j                         |       | j                  |j	                         |       | j                  |j                         |       | j                  |j                  |      d       y)zpEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is unset.
        )m   r   Tr   r	   r   N)
r
   r!   r   r   r^   rL  rt   rO   r   r   )	ru   r8   r9   rw   r  r(  r  rv   r!   s	            r   #test_connected_component__unset_bitz0MaskTypeTest.test_connected_component__unset_bit  s	    !v((T(BaZ1-	Y*&,,.00;dFKK$4$45~6-8 	,,.?//1=A--i8!<r   c                    d\  }}||f}t         j                  j                  |d      }|j                         }ddd|dz   f|dz   dffD ]q  }| j	                  t
              5  |j                  |      }ddd       | j                  |j                         |       | j                  |j                         |       s y# 1 sw Y   LxY w)	z+Ensure connected_component() checks bounds.)   rq   Tr   rk   rm   r   r   N)	r
   r!   r   r^   r|   r   rL  rO   r   )ru   r8   r9   r  r  r  rU   r!   s           r   'test_connected_component__out_of_boundsz4MaskTypeTest.test_connected_component__out_of_bounds	  s    v((T(B&,,.Wq&1*o	1~F 	FC"":. >$88=> ]002NC]335}E	F> >s   #C  C		c                    t        j                  d      }| j                  |j                         g        |j	                         }| j                  |j                         |j                                |j                  dd       |j                  dd       |j	                         }|j                         }|j                  d      }|j                  d      }|j                  d      }| j                  |j                         |d   j                                | j                  |d   j                         d       | j                  |d   j                         d       | j                  |g        |j                  dd       |j	                         }|j	                  d      }|j	                  d	      }|j                         }|j                  d      }|j                  d
      }|j                  d      }| j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  t        |      d       | j                  t        |      d       | j                  t        |      d       | j                  t        |      d       |D ],  }	| j                  |	t         j                  j                         . y)r  r  r/   r   rg   r	   r   r   )rw  rw  r*  )minimumN)r
   r   assertListEqualconnected_componentsrL  rO   r^   r   lenrt   r!   )
ru   r   compcompscomps1comps2comps3comp1comp2r!   s
             r   test_connected_componentsz&MaskTypeTest.test_connected_components	  sZ   KK!Q335r:$$&DJJL1		$$&&&(''*''*''*uQx~~'78*A.*A.VR(	$$&%%f-%%f-&&(''*'''2''*q)**UQ'Va(Va(Va( 	:D!!$(8(89	:r   c                    g }d}d}t         j                  j                  |      }|j                  d      }| j	                  ||       | j                  |j                         |       | j                  |j                         |       y)zEnsures connected_components() properly handles negative min values
        when the mask is empty.

        Negative and zero values for the min parameter (minimum number of bits
        per connected component) equate to setting it to one.
        r   )r   r   rj   N)r
   r!   r   rh  rg  rO   r^   r   )ru   expected_compsr:  r9  r!   connected_compss         r   7test_connected_components__negative_min_with_empty_maskzDMaskTypeTest.test_connected_components__negative_min_with_empty_mask>	  su     
	{{	*33B7_n= 	z2)4r   c                 f   d}t         j                  j                  |d      }|j                         }d}|j	                  d      }| j                  t        |      |       t        | |d   |       | j                  |j                         |       | j                  |j                         |       y)zEnsures connected_components() properly handles negative min values
        when the mask is full.

        Negative and zero values for the min parameter (minimum number of bits
        per connected component) equate to setting it to one.
        )r   rq   Tr   r   ro  r   N)	r
   r!   r   r^   rh  rO   ri  rc   r   )ru   r9  r!   r:  expected_lenrt  s         r   6test_connected_components__negative_min_with_full_maskzCMaskTypeTest.test_connected_components__negative_min_with_full_maskR	  s     	{{	5ZZ\
33B7_-|<oa0$7 	z2)4r   c                 t   d}t         j                  j                  |      }i }t        |      D ]H  }|j	                  |       t         j                  j                  |      }|j	                  |       |||<   J |d   dz  |d   dz  f}|j	                  |       t         j                  j                  |      }|j	                  |       |||<   |j                         }|j                  d      }| j                  t        |      t        |             |D ]_  }	d}
t        |j                               D ]*  }|	j                  |      sd}
t        | |	||          ||=  n | j                  |
d        a | j                  |j                         |       | j                  |j                         |       y	)
a  Ensures connected_components() properly handles negative min values
        when the mask has some bits set.

        Negative and zero values for the min parameter (minimum number of bits
        per connected component) equate to setting it to one.
        )r   r  r   r	   r   r1  FTzmissing component for pt=N)r
   r!   r   r<   r   r^   rh  rO   ri  tuplekeysr   rc   
assertTruer   )ru   r9  r!   rs  rt  new_maskr   r:  rt  rj  foundr4  s               r   :test_connected_components__negative_min_with_some_bits_setzGMaskTypeTest.test_connected_components__negative_min_with_some_bits_setg	  s    	{{	* dm 	.FKK{{''	2HOOF#%-N6"	. A,!#Yq\Q%67F;;##I.!)vZZ\
33B7_-s>/BC# 	ED EN//12 ;;r? E#D$r0BC&r* OOE%>rd#CD	E 	z2)4r   c                 0   g }|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |D ]  \  }}g }t        j                  |      }|D ]4  }|j                  t        |             |D ]  }|j	                  |        6 t        |t              }|j                         }| j                  t        |j                         t              |d|         y	)
z+Ensures get_bounding_rects works correctly.)r  ))r/   rh   rf   )r/  ))r   r   )r   r	   ))r/   rh   rf   rg   r	   r   r   r   )r=  )))r	   r   rg   r  r  r*  )r=  ))r   r   r  r   )r~  ))r  r   r   rf   rg   r  r  )r=  ))r/   )r  )r  )r0  )r  )r"   r   N)	rJ  r
   r   r-   r   sortedrz  get_bounding_rectsrg  )	ru   	mask_datar   rect_point_tuplesrectsr!   rect_pointsr4  expected_rectss	            r   test_get_bounding_rectsz$MaskTypeTest.test_get_bounding_rects	  s5    	 		
 		
 		
 		
 		
 	
	
 (1 	#D#E;;t$D0 $1+>?% $BKKO$$
 $Eu5N++-E  t..0e<v	r   c                 6   d}d}t        j                  |t        d      }t        j                  d      }t        j                  d      dft        j                  d      dff}|D ]  \  }}|j	                  |       t         j
                  j                  ||	      }|j                  |      }	| j                  |	|       t        s%| j                  t        j                  |	      |       | j                  |	j                         |       t        | |	|        y
)z8Ensures empty and full masks can be drawn onto surfaces.r   r   r   r   redwhiteTblackFr   N)r
   r>  SRCALPHAColorr   r!   r   
to_surfaceassertIsIS_PYPYrO   sysgetrefcountr   rV   )
ru   expected_ref_countr   r   surface_color
test_fillsrR   r   r!   r  s
             r   test_to_surfacezMaskTypeTest.test_to_surface
  s     ..x4U+||G,d3fll76KU5ST
$. 
	B NDLL';;##Dt#4D1JMM*g.  !<>PQZ002D9j.A
	Br   c                    d}t         }d}d}t        j                  d      dft        j                  d      dff}|D ]  \  }}t        j                  j	                  ||      }d	D ]  }	|	r|j                  d
      }
n|j                         }
| j                  |
t        j                         t        s%| j                  t        j                  |
      |       | j                  |
j                         |z         | j                  |
j                         |       | j                  |
j                         |       t!        | |
|         y
)zAEnsures empty and full masks can be drawn onto a created surface.r	   r   r  r  Tr  Fr   r   Nr  r
   r  r!   r   r  rt   r>  r  rO   r  r  r|  	get_flagsget_bitsizer   rV   )ru   r  expected_flagexpected_depthr   r  rR   r   r!   use_argr  s              r   test_to_surface__create_surfacez,MaskTypeTest.test_to_surface__create_surface(
  s#    ||G,d3fll76KU5ST
$. 	F ND;;##Dt#4D( F!%!6J!%!2J%%j&..A$$S__Z%@BTU
 4 4 6 FG  !7!7!9>J  !4!4!6=#D*nEF	Fr   c                 *   d}t        j                  d      }t        j                  d      }d}t         j                  j                  |d      }t        j                  |      }d|i}dD ]  }|j                  |       |r |j                  d
i |}	n|j                  |d         }	| j                  |	|       t        s%| j                  t        j                  |	      |       | j                  |	j                         |       t        | |	|        y	)z/Ensures to_surface accepts a surface arg/kwarg.r   r  r  r=  Tr   r   r   Nr2   )r
   r  r!   r   r>  r   r  r  r  rO   r  r  r   rV   )
ru   r  rR   r  r   r!   r   r   
use_kwargsr  s
             r   test_to_surface__surface_paramz+MaskTypeTest.test_to_surface__surface_paramA
  s    g.U+{{40..&W%' 	BJLL',T__6v6
!__VI->?
MM*g.  !<>PQZ002D9j.A	Br   c                    d}t         }d}t        j                  d      }d}t        j                  j	                  |d      }t        j
                  |||      }|j                  |       d|i}dD ]  }	|	r |j                  d
i |}
n|j                  d	|d         }
| j                  |
t        j
                         t        s%| j                  t        j                  |
      |       | j                  |
j                         |z         | j                  |
j                         |       | j                  |
j!                         |       t#        | |
|        y	)z2Ensures to_surface accepts a setsurface arg/kwarg.r	   r   r  r=  Tr   
setsurfacer   Nr2   r  r
   r  r!   r   r>  r   r  rt   r  rO   r  r  r|  r  r  r   rV   )ru   r  r  r  rR   r   r!   r  r   r  r  s              r   !test_to_surface__setsurface_paramz.MaskTypeTest.test_to_surface__setsurface_paramY
  s+    e,{{40^^D-H
'
+' 	BJ,T__6v6
!__T6,3GH
!!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A	Br   c                    d}t         }d}t        j                  d      }d}t        j                  j	                  |      }t        j
                  |||      }|j                  |       d|i}dD ]  }	|	r |j                  di |}
n|j                  dd|d         }
| j                  |
t        j
                         t        s%| j                  t        j                  |
      |       | j                  |
j                         |z         | j                  |
j                         |       | j                  |
j!                         |       t#        | |
|        y)	z4Ensures to_surface accepts a unsetsurface arg/kwarg.r	   r   r  r=  unsetsurfacer   Nr2   r  )ru   r  r  r  rR   r   r!   r  r   r  r  s              r   #test_to_surface__unsetsurface_paramz0MaskTypeTest.test_to_surface__unsetsurface_paramt
  s*    e,{{%~~dM>J.) ,/' 	BJ,T__6v6
!__T49OP
!!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A	Br   c                 j   d}t         }d}t        j                  d      }d}t        j                  j	                  |d      }d|i}dD ]  }|r |j
                  d
i |}	n|j                  d	d	d	|d         }	| j                  |	t        j                         t        s%| j                  t        j                  |	      |       | j                  |	j                         |z         | j                  |	j                         |       | j                  |	j                         |       t!        | |	|        y	)z0Ensures to_surface accepts a setcolor arg/kwarg.r	   r   r  r=  Tr   setcolorr   Nr2   r  
ru   r  r  r  rR   r   r!   r   r  r  s
             r   test_to_surface__setcolor_paramz,MaskTypeTest.test_to_surface__setcolor_param
  s    e,{{40n-' 	BJ,T__6v6
!__T4vj?QR
!!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A	Br   c                     t        j                  d      }d}t         j                  j                  |d      }|j	                  dddd      }| j                  |j                         |       t        | ||       y)z(Ensures the default setcolor is correct.r  r  Tr   N)r   r  r  
unsetcolorr
   r  r!   r   r  rO   r   rV   ru   rR   r   r!   r  s        r   !test_to_surface__setcolor_defaultz.MaskTypeTest.test_to_surface__setcolor_default
  sq    g.{{40__T % 

 	,,.5D*n=r   c           	      h   d}t         }d}t        j                  d      }d}t        j                  j	                  |      }d|i}dD ]  }|r |j
                  di |}	n|j                  dddd|d         }	| j                  |	t        j                         t        s%| j                  t        j                  |	      |       | j                  |	j                         |z         | j                  |	j                         |       | j                  |	j                         |       t!        | |	|        y)	z2Ensures to_surface accepts a unsetcolor arg/kwarg.r	   r   r  r=  r  r   Nr2   r  r  s
             r   !test_to_surface__unsetcolor_paramz.MaskTypeTest.test_to_surface__unsetcolor_param
  s    e,{{%/' 	BJ,T__6v6
!__$dF<,@
 !!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A	Br   c                     t        j                  d      }d}t         j                  j                  |      }|j	                  dddd      }| j                  |j                         |       t        | ||       y)z*Ensures the default unsetcolor is correct.r  r  N)r   r  r  r  r  r  s        r   #test_to_surface__unsetcolor_defaultz0MaskTypeTest.test_to_surface__unsetcolor_default
  sl    g.{{%__Tt % 

 	,,.5D*n=r   c           
      z   d}t         }d}d}t        j                  d      }d}d}t        j                  j	                  |      }d|i}	dD ]  }
|
r|} |j
                  d
i |	}n|}|j                  d	d	d	d	d	|	d         }| j                  |t        j                         t        s%| j                  t        j                  |      |       | j                  |j                         |z         | j                  |j                         |       | j                  |j                         |       t!        | ||        y	)z,Ensures to_surface accepts a dest arg/kwarg.r	   r   r   r   r   r   r  r/   r=  destr   Nr2   r  )ru   r  r  r  default_surface_colordefault_unsetcolorr  r   r!   r   r  rR   r  s                r   test_to_surface__dest_paramz(MaskTypeTest.test_to_surface__dest_param
  s)     ,#\\'2{{%$' 	BJ!3,T__6v6
!6!__$dD&.
 !!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A%	Br   c                    t        j                  d      }t        j                  d      }d}t         j                  j                  |d      }|j	                         }|d   dz   |d   dz   f}t        j
                  |t        d	      }|j                  |       |j                  |d
d
d
      }| j                  ||       | j                  |j                         |       t        | |||       t        | |||       y
)z$Ensures the default dest is correct.r  r  r   Tr   r   r	   r   r   Nr  r  r  r
   r  r!   r   rM   r>  r  r   r  r  rO   r   rV   r[   	ru   rR   r  r9  r!   r  	surf_sizer   r  s	            r   test_to_surface__dest_defaultz*MaskTypeTest.test_to_surface__dest_default
  s    g.U+	{{	5MMO	 q\A%y|a'78	..Hb9]#__4D % 

 	j'*,,.	:D*niH%dJyQr   c                    d}t         }d}d}t        j                  d      }d}t        j                  j	                  |      }d|j                         i}dD ]  }	|	r|}
 |j                  d
i |}n|}
|j                  dddddd	|d         }| j                  |t        j                         t        s%| j                  t        j                  |      |       | j                  |j                         |z         | j                  |j                         |       | j                  |j!                         |       t#        | ||
        y)z-Ensures to_surface accepts an area arg/kwarg.r	   r   r  r  r=  arear   Nr/   r2   )r  r
   r  r!   r   rM   r  rt   r>  r  rO   r  r  r|  r  r  r   rV   )ru   r  r  r  r  r  r   r!   r   r  rR   r  s               r   test_to_surface__area_paramz(MaskTypeTest.test_to_surface__area_param  s/      ,#\\'2{{%$--/*' 	BJ!3,T__6v6
!6!__$dD&&.
 !!*fnn=  !<>PQOOJ002]BCZ335~FZ002D9j.A%	Br   c                    t        j                  d      }t        j                  d      }d}t         j                  j                  |d      }|j	                         }|d   dz   |d   dz   f}t        j
                  |t        d	      }|j                  |       |j                  |d
d
d
      }| j                  ||       | j                  |j                         |       t        | |||       t        | |||       y
)z$Ensures the default area is correct.r  r  r   Tr   r   r	   r   r   Nr  r  r  s	            r   test_to_surface__area_defaultz*MaskTypeTest.test_to_surface__area_default1  s    g.U+	{{	5MMO	 q\A%y|a'78	..Hb9]#__4D % 

 	j'*,,.	:D*niH%dJyQr   c                 ^   t        j                  d      }d}t         j                  j                  |d      }t        j                  |      }t        j                  d      }|j                         }|j                  |       dddt        j                  d	      fd
|fd|j                         fd|fd|ff}t        |      }|D ]f  \  }	}
|j                  |	       |j                  |        |j                  di |}| j                  |j                         |       t        | ||       h y)z.Ensures to_surface accepts the correct kwargs.r  r=  Tr   r  NNr  r/   r  yellowr  r  r  r   Nr2   )r
   r  r!   r   r>  r   r   dictpopr  rO   r   rV   )ru   rR   r   r!   r   r  r  	test_datar   namerI  r  s               r   test_to_surface__kwargsz$MaskTypeTest.test_to_surface__kwargsI  s   g.{{40..&U+\\^
' 6<<12(W\\^,:& 
	 i  	BGD!JJtLL'(262JZ002D9j.A	Br   c                    t        j                  d      }d}t         j                  j                  |      }t        j                  |t
        d      }t        j                  d      }|j                  |       |j                         }|j                  |       ddd|fdt        j                  d	      fd
|fd|fdf}t        |      }|D ]u  \  }	}
|j                  |	        |j                  di |}| j                  |t         j                         | j                  |j                         |       t        | ||       w y)zWEnsures to_surface accepts the correct kwargs
        when creating a surface.
        r  r=  r   r  r  r  r  r  r  r  r  )r   NNr2   )r
   r  r!   r   r>  r  r   r   r  r  r  rt   rO   r   rV   )ru   rR   r   r!   r  setsurface_colorr  r  r   r  rI  r  s               r   &test_to_surface__kwargs_create_surfacez3MaskTypeTest.test_to_surface__kwargs_create_surfaceh  s&     g.{{%^^D(B7
!<<.()!(.) >*h/0\*:&
	 i  	BGD!JJt(262J!!*fnn=Z002D9j.A	Br   c           	      p   t        j                  d      }d}t         j                  j                  |d      }t        j                  |      }|j                  d|d|t        j                  |      d      }| j                  ||       | j                  |j                         |       t        | ||       y)z2Ensures to_surface kwargs are not order dependent.bluer   Tr   r/   N)r  r  r  r   r  r  )
r
   r  r!   r   r>  r  r  rO   r   rV   ru   rR   r   r!   r   r  s         r   )test_to_surface__kwargs_order_independentz6MaskTypeTest.test_to_surface__kwargs_order_independent  s    f-{{40..&__#- % 

 	j'*,,.5D*n=r   c           	         d}t         j                  j                  |d      }t        j                  d      }t        j                  |      }| j                  t              5  |j                  dddddd       ddd       | j                  t              5  |j                  dddd|       ddd       | j                  t              5  |j                  ddd|d       ddd       | j                  t              5  |j                  dd|dd       ddd       | j                  t              5  |j                  d|ddd       ddd       | j                  t              5  |j                  |dddd       ddd       y# 1 sw Y   
xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   yxY w)/Ensures to_surface detects invalid kwarg types.r   Tr   greenNr   )r
   r!   r   r  r>  r|   r   r  )ru   r   r!   invalid_surfinvalid_colors        r   #test_to_surface__args_invalid_typesz0MaskTypeTest.test_to_surface__args_invalid_types  s   {{40||G,t,y) 	@OOD$dD$?	@ y) 	COOD$dMB	C y) 	COOD$mTB	C y) 	BOOD$dDA	B y) 	BOOD,dDA	B y) 	BOOL$dDA	B 	B)	@ 	@	C 	C	C 	C	B 	B	B 	B	B 	BsH   #FF
F=F'0F3#F?FFF$'F03F<?Gc                 J   d}t         j                  j                  |      }t        j                  |      t        j                  |      t        j                  |      t        j                  d      t        j                  d      dd}dt        j                  d      dt        j                  d      t        j                  d      d	d}d}|D ]E  }t        |      }||   ||<   | j                  t              5   |j                  di | d
d
d
       G y
# 1 sw Y   RxY w)r  r   r  r/   r   r  r  r  r  r  )r   r	   r   r   )r   r  r   r*  r   r   r   Nr2   )	r
   r!   r   r>  r  r  r|   r   r  )ru   r   r!   valid_kwargsinvalid_kwargskwarg_orderkwargr   s           r   %test_to_surface__kwargs_invalid_typesz2MaskTypeTest.test_to_surface__kwargs_invalid_types  s   {{% ~~d+ ..."NN40W- ,,w/
 $ ,,w/,F+ ..0

 ! 	*E,'F*51F5M""9- *)&)* *		** *s   ;DD"	c                     t         j                  j                  d      }dt        j                  d      i}| j	                  t
              5   |j                  di | ddd       y# 1 sw Y   yxY w)z/Ensures to_surface detects invalid kwarg names.r   	setcolourr  Nr2   )r
   r!   r   r  r|   r   r  )ru   r!   r   s      r   $test_to_surface__kwargs_invalid_namez1MaskTypeTest.test_to_surface__kwargs_invalid_name  s]    {{'v||E23y) 	&DOO%f%	& 	& 	&s   A((A1c                    d}t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }t        j                  |t        d      }|j	                         }|j	                         }	|j                  |       |	j                  |       t         j                  j                  |d	      }
|}d
d|fd|fd|	fd|fd|fdf}g }t        |      }|D ]Y  \  }}||j                  |       |j                  |       |j                  |        |
j                  |i |}t        | ||       [ y)z7Ensures to_surface accepts a combination of args/kwargsr=  r  r  r  r  cyanr   Tr   r  r   r  r  r  r  r  N)r
   r  r>  r  r   r   r!   r   r  rJ  r  r  rV   )ru   r   r  r  unsetsurface_colorr  r  r   r  r  r!   rR   r  argsr   r  r   r  s                     r    test_to_surface__args_and_kwargsz-MaskTypeTest.test_to_surface__args_and_kwargs  sZ   U+!<<1#\\&1<<(\\&)
..x4\\^
||~(),-{{40)  :&\*":&
	 i % 		BKD%E"JJtLL'($9&9Jj.A		Br   c                 &   d}t         j                  j                  |d      }t        j                  |t        d      }t        j
                  d      }dd|j                  |      |ddd	f}|D ]!  }|j                  |
      }t        | ||       # y)z<Ensures to_surface handles valid setcolor formats correctly.r=  Tr   r   r  r      r   r   r  r   r  	#00FF00FF
0x00FF00FFr  N	r
   r!   r   r>  r  r  map_rgbr  rV   )ru   r   r!   r   rR   test_colorsr  r  s           r   'test_to_surface__valid_setcolor_formatsz4MaskTypeTest.test_to_surface__valid_setcolor_formats  s    {{40..x4g.OON+
 $ 	BH(;Jj.A	Br   c                 "   d}t         j                  j                  |      }t        j                  |t        d      }t        j
                  d      }dd|j                  |      |dddf}|D ]!  }|j                  |      }t        | ||       # y	)
z>Ensures to_surface handles valid unsetcolor formats correctly.r=  r   r  r  r  r  r  r  Nr  )ru   r   r!   r   rR   r  r  r  s           r   )test_to_surface__valid_unsetcolor_formatsz6MaskTypeTest.test_to_surface__valid_unsetcolor_formats-  s    {{%..x4g.OON+
 & 	BJJ?Jj.A	Br   c                    t         j                  j                  d      }dD ]2  }| j                  t              5  |j                  |       ddd       4 t        j                  d      t        j                  d      dfD ]2  }| j                  t              5  |j                  |       ddd       4 y# 1 sw Y   xY w# 1 sw Y   KxY w)z>Ensures to_surface handles invalid setcolor formats correctly.r=  zgreen colorz
#00FF00FF00x00FF00FF0r   r  Nr   r  皙?r
   r!   r   r|   r}   r  r>  r   )ru   r!   r  s      r   )test_to_surface__invalid_setcolor_formatsz6MaskTypeTest.test_to_surface__invalid_setcolor_formatsB  s    {{'L 	3H"":. 323 3	3  /V1DcJ 	3H""9- 323 3	33 33 3   B8C8C	C	c                    t         j                  j                  d      }dD ]2  }| j                  t              5  |j                  |       ddd       4 t        j                  d      t        j                  d      dfD ]2  }| j                  t              5  |j                  |       ddd       4 y# 1 sw Y   xY w# 1 sw Y   KxY w)z@Ensures to_surface handles invalid unsetcolor formats correctly.r=  r  r  Nr   r  r  r  )ru   r!   r  s      r   +test_to_surface__invalid_unsetcolor_formatsz8MaskTypeTest.test_to_surface__invalid_unsetcolor_formatsN  s    {{'N 	7J"":. 7:67 7	7 ">>&16;;v3FL 	7J""9- 7:67 7	77 77 7r	  c                 
   t        j                  d      }t         j                  j                  dd      }dddgt	        dd      dt        j
                  dd      f}|D ]!  }|j                  |	      }t        | ||       # y
)z8Ensures to_surface handles valid dest formats correctly.r  rU  Tr   r/   r   )r   r   r  r  r  r  N)r
   r  r!   r   r   r'   r  rV   ru   rR   r!   destsr  r  s         r   #test_to_surface__valid_dest_formatsz0MaskTypeTest.test_to_surface__valid_dest_formatsZ  s    g.{{T2FAqMKK)
  	BDd3Jj.A	Br   c                     t         j                  j                  d      }ddddhddit        f}|D ]2  }| j	                  t
              5  |j                  |       ddd       4 y# 1 sw Y   ?xY w)z:Ensures to_surface handles invalid dest formats correctly.rU  r  r  r   r   r  N)r
   r!   r   r'   r|   r   r  )ru   r!   invalid_destsr  s       r   %test_to_surface__invalid_dest_formatsz2MaskTypeTest.test_to_surface__invalid_dest_formatsk  s{    {{'FF
 " 	+D""9- +T*+ +	++ +s   	A''A0	c                 >   t        j                  d      }t         j                  j                  dd      }t        j                  dd      t        j                  dd      t        j                  dd      f}|D ]!  }|j                  |	      }t        | ||       # y
)z?Ensures to_surface correctly handles negative sized dest rects.r  rU  Tr   r/   )ra  )r  ra  )r  r  r  Nr
   r  r!   r   r'   r  rV   r  s         r   )test_to_surface__negative_sized_dest_rectz6MaskTypeTest.test_to_surface__negative_sized_dest_rectz  s    g.{{T2KK	*KK	*KK
+
  	BDd3Jj.A	Br   c                 >   t        j                  d      }t         j                  j                  dd      }t        j                  dd      t        j                  dd      t        j                  dd      f}|D ]!  }|j                  |      }t        | ||       # y	)
z;Ensures to_surface correctly handles zero sized dest rects.r  rU  Tr   r/   r  r  r  Nr  r  s         r   %test_to_surface__zero_sized_dest_rectz2MaskTypeTest.test_to_surface__zero_sized_dest_rect  s    g.{{T2KK(KK(KK'
  	BDd3Jj.A	Br   c                    d}t        j                  d      }t        j                  d      }t        j                  |      }t         j                  j	                  |d      }d}d}|d   |d	   |d   |d	   f||f|t        |      ft        |      |ft        |      t        |      f|d   |d	   |d   |d	   g||g|t        |      gt        |      |gt        |      t        |      gt        j                  ||      f}|D ]W  }	|j                  |       t        j                  |	      }
|j                  ||	
      }t        | |||
       t        | |||
       Y y)z8Ensures to_surface handles valid area formats correctly.rU  r  r  Tr   r/   r  r   r   r  N)r
   r  r>  r!   r   listr'   r   r  rV   r[   )ru   r   r  rR   r   r!   area_pos	area_sizeareasr  rS   r  s               r   #test_to_surface__valid_area_formatsz0MaskTypeTest.test_to_surface__valid_area_formats  s^    U+g...&{{40	a[(1+y|Yq\By!tI'(^Y'(^T)_-a[(1+y|Yq\By!tI'(^Y'(^T)_-KK),
  	VDLL'D)It<Jj.)L)$
M9U	Vr   c           	          t         j                  j                  d      }dddddh ddd	d
t        f}|D ]3  }| j	                  t
        d      5  |j                  |      }ddd       5 y# 1 sw Y   @xY w)z:Ensures to_surface handles invalid area formats correctly.rU  r  r/   )r   r   r   )r/   r   )r  rg   >   r   r   r	   r   r   r   r0  zinvalid area argumentr  N)r
   r!   r   r'   assertRaisesRegexr   r  )ru   r!   invalid_areasr  unused_to_surfaces        r   %test_to_surface__invalid_area_formatsz2MaskTypeTest.test_to_surface__invalid_area_formats  s     {{'aL	
 " 	?D''	3JK ?$(OOO$>!? ?	?? ?s   A,,A5	c                    d}t        j                  d      }t        j                  d      }t        j                  |      }t         j                  j	                  |      }|j                  d       t        j                  dd      t        j                  dd      t        j                  d	d
      f}|D ]B  }|j                  |       |j                  ||      }t        | |||       t        | |||       D y)z?Ensures to_surface correctly handles negative sized area rects.rU  r  r  r/   rf   ri   rh   rn   rg   rl   r  N)r
   r  r>  r!   r   r   r'   r   r  rV   r[   )	ru   r   r  rR   r   r!   r  r  r  s	            r   )test_to_surface__negative_sized_area_rectz6MaskTypeTest.test_to_surface__negative_sized_area_rect  s     U+g...&{{%F KK(KK(KK)
  	QDLL't<Jj.$G)$
M4P	Qr   c                    d}t        j                  d      }t        j                  |      }t         j                  j	                  |d      }t        j
                  dd      t        j
                  dd      t        j
                  dd      f}|D ]3  }|j                  |       |j                  ||      }t        | ||       5 y	)
z;Ensures to_surface correctly handles zero sized area rects.rU  r  Tr   r/   rf   rh   r  N)	r
   r  r>  r!   r   r'   r   r  rV   )ru   r   rR   r   r!   r  r  r  s           r   %test_to_surface__zero_sized_area_rectz2MaskTypeTest.test_to_surface__zero_sized_area_rect  s     e,..&{{40 KK'KK'KK'
  	BDLL(t<Jj.A	Br   c                 Z   d}t         }d}d}d}d}t        j                  d      }t        j                  d      }t        j                  d      }	t        j                  d	      }
t        j                  |||      }|j	                         }|j                  |       |j                  |       d
d
d
d
d
d}dD ]p  }t        j                  j                  ||      }|d
fD ]D  }||d<   |d
fD ]4  }||d<   |	d
fD ]$  }||d<   |
d
fD ]  }||d<   |d
fD ]  }||j                  dd
       n||d<   |r||}n||	}n|}n||}n||
}n|} |j                  di |}| j                  |t        j                         t        s%| j                  t        j                  |      |       | j                  |j!                         |z         | j                  |j#                         |       | j                  |j%                         |       t'        | ||         ' 7 G s y
)zEnsures to_surface works with a default surface value
        and combinations of other parameters.

        This tests many different parameter combinations with full and empty
        masks.
        r	   r   r=  r/   r  r  r  r  r  N)r  r  r  r  r  r   r   r  r  r  r  r  r2   )r  r
   r  r>  r   r   r!   r   r  r  rt   r  rO   r  r  r|  r  r  r   rV   )ru   r  r  r  r   r  r  r  r  r  r  r  r  r   r   r!   setsurface_paramunsetsurface_paramsetcolor_paramunsetcolor_param
dest_paramrR   r  s                          r   8test_to_surface__default_surface_with_param_combinationszEMaskTypeTest.test_to_surface__default_surface_with_param_combinations  ss      ,!<<1#\\&1<<(\\&)
^^D-H
!((),-  
 " 1	VD;;##Dt#4D &0$6 -V '7|$+7*> *V&-?F>*+3T*: 'V-;z*1;T0B $V,3CF<0/3Tl !V
#-#5$*JJvt$<5?F6N#''7'C9I)7)C9A9N'9'E9K)9)E9C9N-<T__-Fv-F
 $ 5 5j&.. Q'.$($4$4(+
(CEW%& !%
0D0D0F0V W $ 0 0$.$:$:$<n!" !% 0 01D1D1F M 3D*n UC!V$V'V*V-V	1	Vr   c                    d}t         }d}d}d}t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }	t        j                  d	      }
t        j                  |||      }|j	                         }|j	                         }|j                  |       |j                  |       |d
d
d
d
d
d}dD ]q  }t        j                  j                  ||      }|d
fD ]E  }||d<   |d
fD ]5  }||d<   |	d
fD ]%  }||d<   |
d
fD ]  }||d<   |j                  |       |d
fD ]  }||j                  dd
       n||d<   |r||}n||	}n|}n||}n||
}n|} |j                  di |}| j                  ||       t        s%| j                  t        j                  |      |       | j                  |j!                         |z         | j                  |j#                         |       | j                  |j%                         |       t'        | ||         ( 8 H t y
)zEnsures to_surface works with a surface value
        and combinations of other parameters.

        This tests many different parameter combinations with full and empty
        masks.
        r   r   r=  r/   r  r  r  r  r  Nr  r   r   r  r  r  r  r  r2   )r  r
   r  r>  r   r   r!   r   r  r  r  r  rO   r  r  r|  r  r  r   rV   )ru   r  r  r  r   r  r  r  r  r  r  r   r  r  r   r   r!   r+  r,  r-  r.  r/  rR   r  s                           r   0test_to_surface__surface_with_param_combinationsz=MaskTypeTest.test_to_surface__surface_with_param_combinationsO  s     U+!<<1#\\&1<<(\\&)
..}nE\\^
||~(),-  
 " 2	VD;;##Dt#4D &0$6 .V '7|$+7*> +V&-?F>*+3T*: (V-;z*1;T0B %V,3CF<0#LL7/3Tl !V
#-#5$*JJvt$<5?F6N#''7'C9I)7)C9A9F'9'E9K)9)E9C9F-<T__-Fv-F
 $j' B'.$($4$4(+
(CEW%& !%
0D0D0F0V W $ 0 0$.$:$:$<n!" !% 0 01D1D1F M 3D*n UC!V	%V(V+V.V	2	Vr   c                     t        j                  d      }t        j                  d      }dx\  }}t         j                  j                  |      }|j	                         }t        j
                  |      }t        j                  d      }fdt        |      D        D ]  }	|j                  |	        | j                  D ]  }
|
|_	        |j                  |       |j                  ||
      }|j                          fdt        |      D        D ]f  }	|	d   |
d   z
  |	d	   |
d	   z
  f}|j                  |	      s|}n|j                  |      r|}n|}| j                  |j                  |	      ||
|	f       h |j!                           y
)zEnsures that to_surface works correctly with with set/unset bits
        when using the defaults for setcolor and unsetcolor.
        r  r  ra  r  r  c              3   P   K   | ]  }t        |d z  d      D ]  }||f 
  ywr   r	   Nr  r3   r   r   r9   s      r   r7   zCMaskTypeTest.test_to_surface__set_and_unset_bits.<locals>.<genexpr>  .     Rq%Avq:QRQQFRFR   #&r  c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r7  s      r   r7   zCMaskTypeTest.test_to_surface__set_and_unset_bits.<locals>.<genexpr>  %     L1eFmLALLr  r   r   N)r
   r  r!   r   rM   r>  r   r   r#  r   r   r  rN   rY   r   rO   rP   )ru   default_setcolorr  r8   r   r!   r  r   r  rU   r  r  mask_posrR   r9   s                 @r   #test_to_surface__set_and_unset_bitsz0MaskTypeTest.test_to_surface__set_and_unset_bits  sq    "<<0#\\'2''v{{%MMO	..&U+ SE%LR 	CKK	 '' 	 D $ILL't<JOOLeL 	VFT!W,c!ftAw.>? --c2%2N[[*%5N%7N  !2!23!7$PSU	V #	 r   c           
         dx\  }}t         j                  j                  |      }|j                         }t        j                  |      }t        j
                  d      }|j                         }t        j
                  d      }|j                  |       |j                         }	t        j
                  d      }
|	j                  |
       fdt        |      D        D ]  }|j                  |        | j                  D ]  }||_        dD ]  }|j                  |       |r|j                  ||||	dd      }n|j                  ||||		      }|j                          fd
t        |      D        D ]c  }|d   |d   z
  |d   |d   z
  f}|j                  |      s|}n|j                  |      r|}n|
}| j!                  |j                  |      |       e |j#                            y)zyEnsures that to_surface works correctly with with set/unset bits
        when using setsurface and unsetsurface.
        r4  r  r  r  c              3   P   K   | ]  }t        |d z  d      D ]  }||f 
  ywr6  r  r7  s      r   r7   z`MaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface.<locals>.<genexpr>  r8  r9  r   N)r  r  r  r  r  )r  r  r  c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r7  s      r   r7   z`MaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface.<locals>.<genexpr>  s%     Pq%-PQQFPFPr  r   r   )r
   r!   r   rM   r>  r  r   r   r   r   r#  r   r  rN   rY   r   rO   rP   )ru   r8   r   r!   r  r   r  r  r  r  r  rU   r  disable_color_paramsr  r=  rR   r9   s                    @r   @test_to_surface__set_and_unset_bits_with_setsurface_unsetsurfacezMMaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface  s     ('v{{%MMO	..&U+\\^
!<<0()||~#\\&1,- SE%LR 	CKK	 '' '	$D $I
 )6 !$$]+'!%!#-%1!%#' "1 "J "&!#-%1	 "1 "J !PE%LP 
MC #Aa 0#a&472BCH$11#6)6X.)9);$$Z%6%6s%;^L
M !!#C!$'	$r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                  |       |r|n|}	|j                  |      }
| j                  |
|       | j                  |
j                         |       t        | |
|	        y)	zEnsures that surfaces narrower than the mask work correctly.

        For this test the surface's width is less than the mask's width.
        r  r  r4     r  r  r   r   Nr
   r  r>  r!   r   r   r  r  rO   r   rV   )ru   r<  r  r9  narrow_sizer   r  r   r!   rR   r  s              r   +test_to_surface__surface_narrower_than_maskz8MaskTypeTest.test_to_surface__surface_narrower_than_mask  s    
 "<<0#\\'2	..-U+! 		BD;;##ID#9DLL'15-;MN1JMM*g.Z002K@j.A		Br   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
||       t        | |
||       t        | |
|        y
)zEnsures that setsurfaces narrower than the mask work correctly.

        For this test the setsurface's width is less than the mask's width.
        r  r  r4  rE  r   r  r   r   r  Nr
   r  r>  r  r   rM   r!   r   r  rt   rO   r   rV   r[   )ru   r<  r  r9  rH  r  r  setsurface_rectr   r!   r  s              r   .test_to_surface__setsurface_narrower_than_maskz;MaskTypeTest.test_to_surface__setsurface_narrower_than_mask$  s   
 "<<0#\\'2	^^K2>
!<<.()$--/! 	JD;;##ID#9DJ?J!!*fnn=Z002I> #D*6FX-*&6 $D*6HI	Jr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
|       t        | |
||       t        | |
||        y
)zEnsures that unsetsurfaces narrower than the mask work correctly.

        For this test the unsetsurface's width is less than the mask's width.
        r  r  r4  rE  r   r  r   r   r  NrL  )ru   r<  r  r9  rH  r  r  unsetsurface_rectr   r!   r  s              r   0test_to_surface__unsetsurface_narrower_than_maskz=MaskTypeTest.test_to_surface__unsetsurface_narrower_than_maskD  s
   
 "<<0#\\'2	~~k8R@#\\%0,-(113! 	D;;##ID#9DlCJ!!*fnn=Z002I> #D*6FG#*&8:K .*&8:K	r   c                    d}d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }|j                  |dd	      }	| j                  |	t         j                         | j                  |	j                         |       |rt        | |	||       t        | |	||       t        | |	|        y)
zEnsures that setsurfaces narrower than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the setsurface's width is less than the mask's width.
        r  r4  rE  r   r  r   r   Nr  r  r  r
   r>  r  r  r   rM   r!   r   r  rt   rO   r   rV   r[   )
ru   r  r9  rH  r  r  rM  r   r!   r  s
             r   >test_to_surface__setsurface_narrower_than_mask_and_colors_nonezKMaskTypeTest.test_to_surface__setsurface_narrower_than_mask_and_colors_nonef  s     !-	^^K2>
!<<.()$--/! 	MD;;##ID#9D% ) J !!*fnn=Z002I> #D*6FX-*&;_ $D*6KL#	Mr   c                    d}d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }|j                  |dd	      }	| j                  |	t         j                         | j                  |	j                         |       |rt        | |	|       t        | |	||       t        | |	||        y)
zEnsures that unsetsurfaces narrower than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the unsetsurface's width is less than the mask's width.
        r  r4  rE  r   r  r   r   Nr  r  r  rU  )
ru   r  r9  rH  r  r  rQ  r   r!   r  s
             r   @test_to_surface__unsetsurface_narrower_than_mask_and_colors_nonezMMaskTypeTest.test_to_surface__unsetsurface_narrower_than_mask_and_colors_none  s     !-	~~k8R@#\\%0,-(113! 	D;;##ID#9D)DT ) J !!*fnn=Z002I> #D*6KL#*&8:K .*&;=N#	r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces wider than the mask work correctly.

        For this test the surface's width is greater than the mask's width.
        r  r  rF     rq   r\  r  r   r   Nr
   r  r>  r!   r   rM   r   r  r  rO   r   rV   r[   )ru   r<  r  r9  	wide_sizer   r  r   r!   r  rR   r  s               r   (test_to_surface__surface_wider_than_maskz5MaskTypeTest.test_to_surface__surface_wider_than_mask      
 "<<0#\\'2		..+U+! 	VD;;##ID#9DILL'15-;MN1JMM*g.Z002I>j.)L)$
M9U	Vr   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that setsurfaces wider than the mask work correctly.

        For this test the setsurface's width is greater than the mask's width.
        r  r[  r]  r   r  r   r   rK  Nr
   r  r>  r  r   r!   r   r  rt   rO   r   rV   )
ru   r  r9  r_  r  r  r   r!   rR   r  s
             r   +test_to_surface__setsurface_wider_than_maskz8MaskTypeTest.test_to_surface__setsurface_wider_than_mask  s    
 $\\'2		^^Ix<
!<<.()! 	BD;;##ID#9D15-;MNJ?J!!*fnn=Z002I>j.A	Br   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that unsetsurfaces wider than the mask work correctly.

        For this test the unsetsurface's width is greater than the mask's
        width.
        r  r[  r]  r   r  r   r   rP  Nrc  )
ru   r<  r9  r_  r  r  r   r!   rR   r  s
             r   -test_to_surface__unsetsurface_wider_than_maskz:MaskTypeTest.test_to_surface__unsetsurface_wider_than_mask       "<<0		~~i2>#\\%0,-! 	BD;;##ID#9D15-;MNlCJ!!*fnn=Z002I>j.A	Br   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                  |       |r|n|}	|j                  |      }
| j                  |
|       | j                  |
j                         |       t        | |
|	        y)	zEnsures that surfaces shorter than the mask work correctly.

        For this test the surface's height is less than the mask's height.
        r  r  ra  rq   ra  rF  r  r   r   NrG  )ru   r<  r  r9  
short_sizer   r  r   r!   rR   r  s              r   *test_to_surface__surface_shorter_than_maskz7MaskTypeTest.test_to_surface__surface_shorter_than_mask  s    
 "<<0#\\'2	
..,U+! 		BD;;##ID#9DLL'15-;MN1JMM*g.Z002J?j.A		Br   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
||       t        | |
||       t        | |
|        y
)zEnsures that setsurfaces shorter than the mask work correctly.

        For this test the setsurface's height is less than the mask's height.
        r  r  ri  rj  r   r  r   r   rK  NrL  )ru   r<  r  r9  rk  r  r  rM  r   r!   r  s              r   -test_to_surface__setsurface_shorter_than_maskz:MaskTypeTest.test_to_surface__setsurface_shorter_than_mask  s   
 "<<0#\\'2	
^^J"=
!<<.()$--/! 	JD;;##ID#9DJ?J!!*fnn=Z002I> #D*6FX-*&6 $D*6HI	Jr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
|       t        | |
||       t        | |
||        y
)zEnsures that unsetsurfaces shorter than the mask work correctly.

        For this test the unsetsurface's height is less than the mask's height.
        r  r  ri  rj  r   r  r   r   rP  NrL  )ru   r<  r  r9  rk  r  r  rQ  r   r!   r  s              r   /test_to_surface__unsetsurface_shorter_than_maskz<MaskTypeTest.test_to_surface__unsetsurface_shorter_than_mask-  s
   
 "<<0#\\'2	
~~j(B?#\\%0,-(113! 	D;;##ID#9DlCJ!!*fnn=Z002I> #D*6FG#*&8:K .*&8:K	r   c                    d}d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }|j                  |dd	      }	| j                  |	t         j                         | j                  |	j                         |       |rt        | |	||       t        | |	||       t        | |	|        y)
zEnsures that setsurfaces shorter than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the setsurface's height is less than the mask's height.
        r  ri  rj  r   r  r   r   NrT  rU  )
ru   r  r9  rk  r  r  rM  r   r!   r  s
             r   =test_to_surface__setsurface_shorter_than_mask_and_colors_nonezJMaskTypeTest.test_to_surface__setsurface_shorter_than_mask_and_colors_noneO  s     !-	
^^J"=
!<<.()$--/! 	MD;;##ID#9D% ) J !!*fnn=Z002I> #D*6FX-*&;_ $D*6KL#	Mr   c                    d}d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }|j                  |dd	      }	| j                  |	t         j                         | j                  |	j                         |       |rt        | |	|       t        | |	||       t        | |	||        y)
zEnsures that unsetsurfaces shorter than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the unsetsurface's height is less than the mask's height.
        r  ri  rj  r   r  r   r   NrX  rU  )
ru   r  r9  rk  r  r  rQ  r   r!   r  s
             r   ?test_to_surface__unsetsurface_shorter_than_mask_and_colors_nonezLMaskTypeTest.test_to_surface__unsetsurface_shorter_than_mask_and_colors_noneq  s     !-	
~~j(B?#\\%0,-(113! 	D;;##ID#9D)DT ) J !!*fnn=Z002I> #D*6KL#*&8:K .*&;=N#	r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces taller than the mask work correctly.

        For this test the surface's height is greater than the mask's height.
        r  r  rj  ri  r  r   r   Nr^  )ru   r<  r  r9  	tall_sizer   r  r   r!   r  rR   r  s               r   )test_to_surface__surface_taller_than_maskz6MaskTypeTest.test_to_surface__surface_taller_than_mask  ra  r   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that setsurfaces taller than the mask work correctly.

        For this test the setsurface's height is greater than the mask's
        height.
        r  rj  ri  r   r  r   r   rK  Nrc  )
ru   r  r9  rv  r  r  r   r!   rR   r  s
             r   ,test_to_surface__setsurface_taller_than_maskz9MaskTypeTest.test_to_surface__setsurface_taller_than_mask  s     $\\'2		^^Ix<
!<<.()! 	BD;;##ID#9D15-;MNJ?J!!*fnn=Z002I>j.A	Br   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that unsetsurfaces taller than the mask work correctly.

        For this test the unsetsurface's height is greater than the mask's
        height.
        r  rj  ri  r   r  r   r   rP  Nrc  )
ru   r<  r9  rv  r  r  r   r!   rR   r  s
             r   .test_to_surface__unsetsurface_taller_than_maskz;MaskTypeTest.test_to_surface__unsetsurface_taller_than_mask  rg  r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces wider and taller than the mask work correctly.

        For this test the surface's width is greater than the mask's width and
        the surface's height is greater than the mask's height.
        r  r  rF     r]  r  r   r   Nr^  )ru   r<  r  r9  wide_tall_sizer   r  r   r!   r  rR   r  s               r   3test_to_surface__surface_wider_and_taller_than_maskz@MaskTypeTest.test_to_surface__surface_wider_and_taller_than_mask  s     "<<0#\\'2	!..0U+! 	VD;;##ID#9DILL'15-;MN1JMM*g.Z002NCj.)L)$
M9U	Vr   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that setsurfaces wider and taller than the mask work
        correctly.

        For this test the setsurface's width is greater than the mask's width
        and the setsurface's height is greater than the mask's height.
        r  r}  r]  r   r  r   r   rK  Nrc  )
ru   r  r9  r  r  r  r   r!   rR   r  s
             r   6test_to_surface__setsurface_wider_and_taller_than_maskzCMaskTypeTest.test_to_surface__setsurface_wider_and_taller_than_mask  s     $\\'2	!^^NHbA
!<<.()! 	BD;;##ID#9D15-;MNJ?J!!*fnn=Z002I>j.A	Br   c                    t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}|j                  |      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y	)
zEnsures that unsetsurfaces wider and taller than the mask work
        correctly.

        For this test the unsetsurface's width is greater than the mask's width
        and the unsetsurface's height is greater than the mask's height.
        r  r}  r]  r   r  r   r   rP  Nrc  )
ru   r<  r9  r  r  r  r   r!   rR   r  s
             r   8test_to_surface__unsetsurface_wider_and_taller_than_maskzEMaskTypeTest.test_to_surface__unsetsurface_wider_and_taller_than_mask  s     "<<0	!~~nhC#\\%0,-! 	BD;;##ID#9D15-;MNlCJ!!*fnn=Z002I>j.A	Br   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces wider and shorter than the mask work
        correctly.

        For this test the surface's width is greater than the mask's width and
        the surface's height is less than the mask's height.
        r  r  r  )r   rF  r  r   r   Nr^  )ru   r<  r  r9  wide_short_sizer   r  r   r!   r  rR   r  s               r   4test_to_surface__surface_wider_and_shorter_than_maskzAMaskTypeTest.test_to_surface__surface_wider_and_shorter_than_mask,  s     "<<0#\\'2	!..1U+! 	VD;;##ID#9DILL'15-;MN1JMM*g.Z002ODj.)L)$
M9U	Vr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
||       t        | |
||       t        | |
|        y
)zEnsures that setsurfaces wider and shorter than the mask work
        correctly.

        For this test the setsurface's width is greater than the mask's width
        and the setsurface's height is less than the mask's height.
        r  r  r  rj  r   r  r   r   rK  NrL  )ru   r<  r  r9  r  r  r  rM  r   r!   r  s              r   7test_to_surface__setsurface_wider_and_shorter_than_maskzDMaskTypeTest.test_to_surface__setsurface_wider_and_shorter_than_maskH  s    "<<0#\\'2	!^^OXrB
!<<.()$--/! 	JD;;##ID#9DJ?J!!*fnn=Z002I> #D*6FX-*&6 $D*6HI	Jr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
|       t        | |
||       t        | |
||        y
)zEnsures that unsetsurfaces wider and shorter than the mask work
        correctly.

        For this test the unsetsurface's width is greater than the mask's width
        and the unsetsurface's height is less than the mask's height.
        r  r  r  rj  r   r  r   r   rP  NrL  )ru   r<  r  r9  r  r  r  rQ  r   r!   r  s              r   9test_to_surface__unsetsurface_wider_and_shorter_than_maskzFMaskTypeTest.test_to_surface__unsetsurface_wider_and_shorter_than_maskj  s
    "<<0#\\'2	!~~oxD#\\%0,-(113! 	D;;##ID#9DlCJ!!*fnn=Z002I> #D*6FG#*&8:K .*&8:K	r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces narrower and taller than the mask work
        correctly.

        For this test the surface's width is less than the mask's width and
        the surface's height is greater than the mask's height.
        r  r  ra  r~  r[  r  r   r   Nr^  )ru   r<  r  r9  narrow_tall_sizer   r  r   r!   r  rR   r  s               r   6test_to_surface__surface_narrower_and_taller_than_maskzCMaskTypeTest.test_to_surface__surface_narrower_and_taller_than_mask  s     "<<0#\\'2	"..!12U+! 	VD;;##ID#9DILL'15-;MN1JMM*g.Z0024DEj.)L)$
M9U	Vr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
||       t        | |
||       t        | |
|        y
)zEnsures that setsurfaces narrower and taller than the mask work
        correctly.

        For this test the setsurface's width is less than the mask's width
        and the setsurface's height is greater than the mask's height.
        r  r  r  r[  r   r  r   r   rK  NrL  )ru   r<  r  r9  r  r  r  rM  r   r!   r  s              r   9test_to_surface__setsurface_narrower_and_taller_than_maskzFMaskTypeTest.test_to_surface__setsurface_narrower_and_taller_than_mask  s    "<<0#\\'2	"^^$4hC
!<<.()$--/! 	JD;;##ID#9DJ?J!!*fnn=Z002I> #D*6FX-*&6 $D*6HI	Jr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
|       t        | |
||       t        | |
||        y
)zEnsures that unsetsurfaces narrower and taller than the mask work
        correctly.

        For this test the unsetsurface's width is less than the mask's width
        and the unsetsurface's height is greater than the mask's height.
        r  r  r  r[  r   r  r   r   rP  NrL  )ru   r<  r  r9  r  r  r  rQ  r   r!   r  s              r   ;test_to_surface__unsetsurface_narrower_and_taller_than_maskzHMaskTypeTest.test_to_surface__unsetsurface_narrower_and_taller_than_mask  s    "<<0#\\'2	"~~&6"E#\\%0,-(113! 	D;;##ID#9DlCJ!!*fnn=Z002I> #D*6FG#*&8:K .*&8:K	r   c                    t        j                  d      }t        j                  d      }d}d}t        j                  |      }t        j                  d      }dD ]  }t         j                  j	                  ||      }|j                         }	|j                  |       |r|n|}
|j                  |      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	        y)	zEnsures that surfaces narrower and shorter than the mask work
        correctly.

        For this test the surface's width is less than the mask's width and
        the surface's height is less than the mask's height.
        r  r  ra     r[  r  r   r   Nr^  )ru   r<  r  r9  narrow_short_sizer   r  r   r!   r  rR   r  s               r   7test_to_surface__surface_narrower_and_shorter_than_maskzDMaskTypeTest.test_to_surface__surface_narrower_and_shorter_than_mask  s     "<<0#\\'2	#..!23U+! 	VD;;##ID#9DILL'15-;MN1JMM*g.Z0024EFj.)L)$
M9U	Vr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
||       t        | |
||       t        | |
|        y
)zEnsures that setsurfaces narrower and shorter than the mask work
        correctly.

        For this test the setsurface's width is less than the mask's width
        and the setsurface's height is less than the mask's height.
        r  r  r  r[  r   r  r   r   rK  NrL  )ru   r<  r  r9  r  r  r  rM  r   r!   r  s              r   :test_to_surface__setsurface_narrower_and_shorter_than_maskzGMaskTypeTest.test_to_surface__setsurface_narrower_and_shorter_than_mask  s    "<<0#\\'2	#^^$5xD
!<<.()$--/! 	JD;;##ID#9DJ?J!!*fnn=Z002I> #D*6FX-*&6 $D*6HI	Jr   c                 N   t        j                  d      }t        j                  d      }d}d}t        j                  |t        d      }t        j                  d      }|j	                  |       |j                         }dD ]  }t         j                  j                  ||      }	|	j                  |	      }
| j                  |
t         j                         | j                  |
j                         |       |rt        | |
|       t        | |
||       t        | |
||        y
)zEnsures that unsetsurfaces narrower and shorter than the mask work
        correctly.

        For this test the unsetsurface's width is less than the mask's width
        and the unsetsurface's height is less than the mask's height.
        r  r  r  r[  r   r  r   r   rP  NrL  )ru   r<  r  r9  r  r  r  rQ  r   r!   r  s              r   <test_to_surface__unsetsurface_narrower_and_shorter_than_maskzIMaskTypeTest.test_to_surface__unsetsurface_narrower_and_shorter_than_mask.  s    "<<0#\\'2	#~~&72F#\\%0,-(113! 	D;;##ID#9DlCJ!!*fnn=Z002I> #D*6FG#*&8:K .*&8:K	r   c                 T   t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }d}d}d}d	}	t        j                  |      }
t        j                  |      }t        j                  |	      }|
j                  |       |j                  |       |j                  |       |
j	                         |j	                         }|j	                         }t         j
                  j                  |d
      }|j	                         }t        j                  dd      |j                  _        fdt        j                  j                        D        D ]  }|j                  |d        |j                  |
||      }| j                  ||
       | j                  |j!                         |       |j#                          fdt        j                        D        D ]u  }|j%                  |      s|}n>|j'                  |      r|j%                  |      r|}n|}n|j%                  |      r|}n|}| j                  |j'                  |      |       w |j)                          y)zBEnsures that all the surface parameters can be of different sizes.r  r  r  r  r  )ra  r\  )rq      )rw  r~  )r     Tr   r/   r   c              3   p   K   | ]-  }t        j                  j                        D ]  }||f 
 / y wrF   )r   r   r   )r3   r   r   unfilled_rects      r   r7   zWMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_mask.<locals>.<genexpr>r  sA      
=??MOO<
  F

s   36r   c              3   Z   K   | ]"  }t        j                        D ]  }||f 
 $ y wrF   )r   r   )r3   r   r   surface_rects      r   r7   zWMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_mask.<locals>.<genexpr>  s5      
5;P
67QF

s   (+N)r
   r  r>  r   rM   r!   r   r'   r   r   r   r   r   r  r  rO   r   rN   rY   r   rP   )ru   r<  r  r  r  r  r9  surface_sizesetsurface_sizeunsetsurface_sizer   r  r  rM  rQ  r!   r  rU   r  rR   r  r  s                       @@r   7test_to_surface__all_surfaces_different_sizes_than_maskzDMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_maskR  sE    "<<0#\\'2U+!<<0#\\&1	 $...^^O4
~~&78]#(),-'')$--/(113 {{	5MMO	FF3(//
=??MOO<
 	 C
 KKQ	  __Wj,G
j'*,,.= 	
!,..1
 	EC ))#.!.S!"//4%5N%5N %11#6%7N%7NZ..s3^D%	E( 	r   c           	         d}t        j                  ||f      }|j                         }|j                         }t        j                  d      }t        j                  d      }t        j                  d      }d t        | |dz         D        d t        | |dz         D        d t        | |dz         D        d	 t        | |dz         D        f}d
D ]  }	t         j                  j                  ||f|	      }
|	r|n|}|D ]a  }|D ]Z  }||_        |j                  |      }|j                  |       |
j                  ||      }t        | |||       t        | |||       \ c  y)zBEnsures dest values can be different locations on/off the surface.r   r  r  r  c              3   $   K   | ]  }|d f 
 ywr1   r2   r3   ss     r   r7   z?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>       4aV4   r   c              3   $   K   | ]  }d |f 
 ywr1   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>  r  r  c              3   $   K   | ]  }||f 
 y wrF   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>  r  r  c              3   &   K   | ]	  }| |f  y wrF   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>       5qb!W5   r   r   r  N)r
   r>  rM   r   r  r   r!   r   r   rL   r   r  rV   r[   )ru   SIDEr   r  	dest_rectr  r<  r  
directionsr   r!   rR   	directionrU   rM  r  s                   r   test_to_surface__dest_locationsz,MaskTypeTest.test_to_surface__dest_locations  sh   ..$.'') %%'	U+!<<0#\\'2 5UD5$(344UD5$(344UD5$(345eTE4!845	

 " 	D;;##T4Lt#<D15-;MN' 	$ 
C(+I%#,>>,#?LLL/!%y!IJ'j.,W1j-
		r   c           	         d}t        j                  ||f      }t        j                  d      }t        j                  d      }t        j                  d      }d t        | |dz         D        d t        | |dz         D        d t        | |dz         D        d	 t        | |dz         D        f}d
D ]  }t         j                  j                  ||f|      }|j                         }	|	j                         }
|r|n|}|D ]h  }|D ]a  }||
_        |
j                  |	      }d|_        |j                  |       |j                  ||
      }t        | |||       t        | |||       c j  y)z>Ensures area rects can be different locations on/off the mask.r   r  r  r  c              3   $   K   | ]  }|d f 
 ywr1   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>  r  r  r   c              3   $   K   | ]  }d |f 
 ywr1   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>  r  r  c              3   $   K   | ]  }||f 
 y wrF   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>  r  r  c              3   &   K   | ]	  }| |f  y wrF   r2   r  s     r   r7   z?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>  r  r  r   r   r/   r  N)r
   r>  r  r   r!   r   rM   r   r   rL   r   r  rV   r[   )ru   r  r   r  r<  r  r  r   r!   r  rS   rR   r  rU   rM  r  s                   r   test_to_surface__area_locationsz,MaskTypeTest.test_to_surface__area_locations  sm    ..$.U+!<<0#\\'2 5UD5$(344UD5$(344UD5$(345eTE4!845	

 " 	D;;##T4Lt#<DI!(I15-;MN' 	$ C(+I%#,>>)#<L+1L(LL/!%y!IJ'j.,W1j-	r   c           
         d}t        j                  ||f      }|j                         }|j                         }t        j                  d      }t        j                  d      }t        j                  d      }d t        | |dz         D        d t        | |dz         D        d t        | |dz         D        d	 t        | |dz         D        f}t        |d
         }	dD ]  }
t         j                  j                  ||f|
      }|j                         }|j                         }|
r|n|}|D ]  }|D ]  }||_	        |	D ]}  }||_	        |j                  |      }|j                  |_	        |j                  |      }|j                  |       |j                  |||      }t        | |||       t        | |||           y)z]Ensures dest/area values can be different locations on/off the
        surface/mask.
        r   r  r  r  c              3   $   K   | ]  }|d f 
 ywr1   r2   r  s     r   r7   zHMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>  r  r  r   c              3   $   K   | ]  }d |f 
 ywr1   r2   r  s     r   r7   zHMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>  r  r  c              3   $   K   | ]  }||f 
 y wrF   r2   r  s     r   r7   zHMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>  r  r  c              3   &   K   | ]	  }| |f  y wrF   r2   r  s     r   r7   zHMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>  r  r  r	   r   r   )r  r  N)r
   r>  rM   r   r  r   r  r!   r   r   rL   r   r  rV   r[   )ru   r  r   r  r  r  r<  r  dest_directionsarea_positionsr   r!   r  rS   rR   dest_directiondest_posr  area_overlap_rectdest_overlap_rectr  s                        r   (test_to_surface__dest_and_area_locationsz5MaskTypeTest.test_to_surface__dest_and_area_locations  s   
 ..$.'') %%'	U+!<<0#\\'2 5UD5$(344UD5$(344UD5$(345eTE4!845	
 oa01! 	D;;##T4Lt#<DI!(I15-;MN"1  . H(0I%$2 ,4	),5NN9,E)4=4E4E)1,5NN;L,M)]3%)__#)) &5 &
 , *n>O 6 *m=N	r   c                    d}dddd|dz
  |dz
  f|dz
  |f||dz
  f||f|dz   |f||dz   f|dz   |dz   ff}t        j                  ||f      }t        j                  d      }t        j                  d      }t        j                  d	      }d
D ]  }t         j                  j	                  ||f|      }|j                         }	|r|n|}
|D ]  }t        j                  d|      }| j                  D ]a  }||_        |j                  |	      }d|_        |j                  |       |j                  ||      }t        | ||
|       t        | |||       c   y)z*Ensures area rects can be different sizes.r   r/   rf   rh   rg   r   r  r  r  r   r   r  N)r
   r>  r  r!   r   rM   r'   r#  r   rL   r   r  rV   r[   )ru   r  SIZESr   r  r<  r  r   r!   r  rR   r   rS   rU   rM  r  s                   r   test_to_surface__area_sizesz(MaskTypeTest.test_to_surface__area_sizes  s    AXtax AXt4!84LAXt4!8AXtax 
 ..$.U+!<<0#\\'2! 	D;;##T4Lt#<DI15-;MN "KK5	.. C(+I%#,>>)#<L+1L(LL/!%y!IJ'j.,W1j-	r   c                 H   d}t        j                  d      }d|_        t        j                  d      }d|_        t        j                  |t        d      }t        j                  |t        d      }|j                  |       |j                  |       dD ]  }t         j                  j                  ||	      }|r|n|}|j                  ||
      }	| j                  |	t         j                         | j                  |	j                         |       t        | |	|        y)zEEnsures the setsurface/unsetsurface color alpha values are respected.r   r  5   r  r`  r   flagsdepthr   r   r  r  N)r
   r  r4   r>  r  r   r!   r   r  rt   rO   r   rV   )
ru   r   r  r  r  r  r   r!   rR   r  s
             r   %test_to_surface__surface_color_alphasz2MaskTypeTest.test_to_surface__surface_color_alphasB  s    !<<0#\\&1"^^DC
~~d("E(),-! 
	BD;;##Dt#4D15-;MN%L ) J !!*fnn=Z002D9j.A
	Br   c                    d}t        j                  d      }d|_        t        j                  d      }d|_        dD ]  }t         j                  j	                  ||      }|r|n|}|j                  ||      }| j                  |t         j                         | j                  |j                         |       t        | ||        y	)
z;Ensures the setcolor/unsetcolor alpha values are respected.r   r  #   r     r   r   )r  r  N)r
   r  r4   r!   r   r  rt   r>  rO   r   rV   )ru   r   r  r  r   r!   rR   r  s           r   test_to_surface__color_alphasz*MaskTypeTest.test_to_surface__color_alphas\  s    <<(
\\&)

! 	BD;;##Dt#4D)-X:N(zRJ!!*fnn=Z002D9j.A	Br   c                    d}t        j                  d      }t        j                  d      }t        j                  d      }dD ]'  }t        j                  ||      }t        j                  ||      }t        j                  ||      }|j                  |       |j                  |       |j                  |       dD ]  }	t         j                  j                  ||	      }
|	r|j                  d	      n|j                  d	      }|
j                  |||      }| j                  |t         j                         | j                  |j                         |       t        | ||        * y
)zAEnsures to_surface works correctly with supported surface depths.r   r  r  r  r~  r     r   r  r   r   r/   N)r
   r  r>  r   r!   r   r   r  rt   rO   r   rV   )ru   r   r  r  r  r  r   r  r  r   r!   rR   r  s                r   test_to_surface__depthsz$MaskTypeTest.test_to_surface__depthsn  s7   U+!<<0#\\&1$ 	FEnnT7GE:J!>>$e<LLL'OO,-01% F{{''4'8
 26J%%f-<;N;Nv;V  "__Wj,O
%%j&..A  !4!4!6=#D*nEF	Fr   c                 R   d}t        j                  d      }t        j                  d      }t        j                  d      }t         j                  j                  |      }d}|D ]  }t        j                  ||d         }t        j                  ||d         }	t        j                  ||d	         }
|j                  |       |	j                  |       |
j                  |       | j                  t              5  |j                  ||	|
       d
d
d
        y
# 1 sw Y   xY w)zCEnsures an exception is raised when surfaces have different depths.r   r  r  r  )	)r~  r~  r  )r~  r~  r  )r~  r~  r   )r  r  r  )r  r  r   )r  r  r~  )r   r  r  )r   r   r  )r   r  r   r   r  r   r	   N	r
   r  r!   r   r>  r   r|   r}   r  )ru   r   r  r  r  r!   test_depthsdepthsr   r  r  s              r   !test_to_surface__different_depthsz.MaskTypeTest.test_to_surface__different_depths  s   U+!<<0#\\&1{{%

 " 
	CFnnT;GF1I>J!>>$fQi@LLL'OO,-01"":. C\BC C
	CC Cs   >DD&	c                    d}t        j                  d      }t        j                  d      }t         j                  j                  |      }d}|D ]  \  }}t        j                  ||      }t        j                  ||      }	|j                  |       |	j                  |       | j                  t              5  |j                  ||	       ddd        y# 1 sw Y   xY w)zmEnsures an exception is raised when surfaces have different depths
        than the created surface.
        r   r  r  ))r~  r~  )r  r  )r  r  )r  r  )r   r~  )r   r  )r   r  r  r   r  r  Nr  )
ru   r   r  r  r!   r  	set_depthunset_depthr  r  s
             r   7test_to_surface__different_depths_with_created_surfaceszDMaskTypeTest.test_to_surface__different_depths_with_created_surfaces  s     !<<0#\\&1{{%	
 '2 	R"I{I>J!>>$kBLOO,-01"":. R:LQR R	RR Rs   ;CC#	c                    d}t        j                  d      }t        j                  d      }t        j                  d      }dD ]@  }dt        fD ]1  }t        j                  |||      }t        j                  |||      }t        j                  |||      }	|j	                  |       |j	                  |       |	j	                  |       dD ]  }
t         j
                  j                  ||
	      }|
r|n|}|j                  |||	      }| j                  |t         j                         | j                  |j                         |       t        | ||       |s| j                  |j                         |z          4 C y
)zHEnsures to_surface works correctly when the SRCALPHA flag is set or not.r   r  r  r  r  r   r  r   r   Nr
   r  r  r>  r   r!   r   r  rt   rO   r   rV   r|  r  )ru   r   r  r  r  r  r  r   r  r  r   r!   rR   r  s                 r   test_to_surface__same_srcalphasz,MaskTypeTest.test_to_surface__same_srcalphas  sT   U+!<<0#\\&1 	HEX H ..U%H#^^DUK
%~~d%uM]+ 01!!"45) 
HD!;;++Dt+<D9=%5CUN!%*l!SJ))*fnnE$$Z%8%8%:DA'j.I
(<(<(>(FG
HH	Hr   c                 l   d}t        j                  d      }t        j                  d      }t        }t        j                  ||d      }t        j                  ||d      }|j	                  |       |j	                  |       dD ]  }t         j
                  j                  ||      }|r|n|}	|j                  ||      }
| j                  |
t         j                         | j                  |
j                         |       t        | |
|	       | j                  |
j                         |z          y	)
zEnsures to_surface works correctly when it creates a surface
        and the SRCALPHA flag is set on both setsurface and unsetsurface.
        r   r  r  r   r  r   r   r  Nr  )ru   r   r  r  expected_flagsr  r  r   r!   rR   r  s              r   5test_to_surface__same_srcalphas_with_created_surfaceszBMaskTypeTest.test_to_surface__same_srcalphas_with_created_surfaces  s    !<<0#\\&1!^^DbI
~~d.K(),-! 	ED;;##Dt#4D15-;MN%L ) J !!*fnn=Z002D9j.AOOJ002^CD	Er   c                    d}t        j                  d      }t        j                  d      }t        j                  d      }t         j                  j                  |      }t        ddft        t        dfdt        t        fddt        ff}dD ]  }|D ]  }t        j
                  ||d   |      }	t        j
                  ||d   |      }
t        j
                  ||d	   |      }|	j                  |       |
j                  |       |j                  |       | j                  t              5  |j                  |	|
|       d
d
d
         y
# 1 sw Y   xY w)zdEnsures an exception is raised when surfaces have different SRCALPHA
        flag settings.
        r   r  r  r  r   r  r  r   r	   N
r
   r  r!   r   r  r>  r   r|   r}   r  )ru   r   r  r  r  r!   
test_flagsr  r  r   r  r  s               r   $test_to_surface__different_srcalphasz1MaskTypeTest.test_to_surface__different_srcalphas  sE    U+!<<0#\\&1{{% q!x#(#8	

  	GE# 
G ..U1XUK#^^DaN
%~~d%(%P]+ 01!!"45&&z2 GOOGZFG G
G	GG Gs   .EEc                    d}t        j                  d      }t        j                  d      }t         j                  j                  |      }dD ]  }dt        dfdt        ffD ]  }t        j
                  ||d   |      }t        j
                  ||d   |      }|j                  |       |j                  |       | j                  t              5  |j                  ||	       d
d
d
         y
# 1 sw Y   xY w)z}Ensures an exception is raised when surfaces have different SRCALPHA
        flag settings than the created surface.
        r   r  r  r  r/   r   r  r   r  Nr  )	ru   r   r  r  r!   r  r  r  r  s	            r   :test_to_surface__different_srcalphas_with_created_surfaceszGMaskTypeTest.test_to_surface__different_srcalphas_with_created_surfaces'  s     !<<0#\\&1{{% 	VE !8Q-!X? V#^^DaN
%~~d%(%P 01!!"45&&z2 VOOzOUV VV	VV Vs   C33C<c                 h   t        j                  d      }t        j                  d      }dx\  }}t        j                  |t        d      }t        j                  d      }dD ]  }t         j                  j                  ||      }|j                         }	|r|n|}
fdt        |      D        D ]{  }|j                  |       ||	_	        |j                  ||	      }| j                  ||       | j                  |j                         |       t        | ||
|	       t        | |||	       }  y
)zwEnsures dest values on the surface work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   rw  r   r  r   r   c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r  s      r   r7   z@MaskTypeTest.test_to_surface__dest_on_surface.<locals>.<genexpr>M  %     MAeM1!QMMr  r  N)r
   r  r>  r  r!   r   rM   r   r   r   r  r  rO   r   rV   r[   )ru   r<  r  r9   r   r   r  r   r!   r  rR   r  r  r8   s                @r    test_to_surface__dest_on_surfacez-MaskTypeTest.test_to_surface__dest_on_surface=  s    "<<0#\\'2%%v..x4U+! 	D;;##Dt#4DI15-;MN NvM ]+$(	!!__W4_@
j'2  !4!4!6=#D*niP-*mY	r   c           	      T   dx\  }}t        j                  |t        d      }t        j                  d      }|j	                         }t        j                  d      }|j                  |       |j	                         }t        j                  d      }|j                  |       |||dd}	t        |	      }
|
j                  d       d	D ]  }t         j                  j                  ||
      }|j                         }|r|n|}fdt        |      D        D ]  }||_        d	D ]~  }|j                  |       |r|
n|	}||d<    |j                  di |}| j                  ||       | j                  |j!                         |       t#        | |||       t%        | |||          y)zjEnsures dest values on the surface work correctly
        when using setsurface and unsetsurface.
        r  r   r  r  r  Nr   r  r  r  )r  N)r  Nr   r   c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r  s      r   r7   z]MaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurface.<locals>.<genexpr>|  r  r  r  r2   )r
   r>  r  r  r   r   r  updater!   r   rM   r   r   r  r  rO   r   rV   r[   )ru   r9   r   r   r  r  r  r  r  r   color_kwargsr   r!   r  rR   r  use_color_paramstest_kwargsr  r8   s                      @r   =test_to_surface__dest_on_surface_with_setsurface_unsetsurfacezJMaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurfaceZ  s     &%v..x4U+\\^
!<<0()||~#\\&1,-
 $(	
 F|FG! 	D;;##Dt#4DI15-;MN NvM $(	!(5 $LL/2B,K*.K'!0!?;!?JMM*g6$$Z%8%8%:DA'j.)T1j-	r   c                    t        j                  d      }t        j                  d      }dx\  }}}t        j                  |t        d      }t        j                  d      }| | f| dfd| fg}|j	                  t        |j                                      dD ]  }	t         j                  j                  ||	      }
|
j                         }|	r|n|}|D ]{  }|j                  |       ||_
        |
j                  ||	      }| j                  ||       | j                  |j                         |       t        | |||       t!        | |||       }  y
)zxEnsures dest values off the surface work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   r   r  r   r   r   r  N)r
   r  r>  r  extendrC   rM   r!   r   r   r   r  r  rO   r   rV   r[   )ru   r<  r  r8   r9   r   r   r  r  r   r!   r  rR   r  r  s                  r   !test_to_surface__dest_off_surfacez.MaskTypeTest.test_to_surface__dest_off_surface  sF    "<<0#\\'2%%v..x4U+ &6'"eVQK!fW>[!1!1!345! 	D;;##Dt#4DI15-;MN ]+$(	!!__W4_@
j'2  !4!4!6=#D*niP-*mY	r   c           	         dx\  }}}t        j                  |t        d      }t        j                  d      }|j	                         }t        j                  d      }|j                  |       |j	                         }t        j                  d      }	|j                  |	       | | f| dfd| fg}
|
j                  t        |j                                      |||dd}t        |      }|j                  d	       d
D ]  }t         j                  j                  ||      }|j                         }|r|n|	}|
D ]  }||_        d
D ]~  }|j                  |       |r|n|}||d<    |j                  di |}| j                  ||       | j!                  |j#                         |       t%        | |||       t'        | |||          y)zkEnsures dest values off the surface work correctly
        when using setsurface and unsetsurface.
        r   r   r  r  r  r   Nr  r  r   r   r  r2   )r
   r>  r  r  r   r   r  rC   rM   r  r  r!   r   r   r  r  rO   r   rV   r[   )ru   r8   r9   r   r   r  r  r  r  r  r  r   r  r   r!   r  rR   r  r  r  r  s                        r   >test_to_surface__dest_off_surface_with_setsurface_unsetsurfacezKMaskTypeTest.test_to_surface__dest_off_surface_with_setsurface_unsetsurface  s     &%v..x4U+\\^
!<<0()||~#\\&1,- &6'"eVQK!fW>[!1!1!345
 $(	
 F|FG! 	D;;##Dt#4DI15-;MN $(	!(5 $LL/2B,K*.K'!0!?;!?JMM*g6$$Z%8%8%:DA'j.)T1j-	r   c                    t        j                  d      }t        j                  d      }dx\  }}t        j                  |t        d      }t        j                  d      }dD ]  }t         j                  j                  ||      }|j                         }	|	j                         }
|r|n|}fdt        |      D        D ]  }|j                  |       ||
_
        |	j                  |
      }d	|_
        |j                  ||

      }| j                  ||       | j                  |j                         |       t!        | |||       t#        | |||         y)ztEnsures area values on the mask work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r  r   r  r   r   c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r  s      r   r7   z=MaskTypeTest.test_to_surface__area_on_mask.<locals>.<genexpr>  %     L1uU|L!ALLr  r/   r  N)r
   r  r>  r  r!   r   rM   r   r   r   r   rL   r  r  rO   r   rV   r[   )ru   r<  r  r9   r   r   r  r   r!   r  rS   rR   rU   rM  r  r8   s                  @r   test_to_surface__area_on_maskz*MaskTypeTest.test_to_surface__area_on_mask  s8    "<<0#\\'2%%v..x4U+! 	D;;##Dt#4DI!(I15-;MN MfL ]+$'	!(~~i8'-$!__W9_E
j'2  !4!4!6=#D*nlS-*m\	r   c           	         dx\  }}t        j                  |t        d      }t        j                  d      }|j	                         }t        j                  d      }|j                  |       |j	                         }t        j                  d      }|j                  |       |||t        j                  d|      d}	t        |	      }
|
j                  d       d	D ]%  }t         j                  j                  ||
      }|j                         }|j	                         }|r|n|}fdt        |      D        D ]  }||_        |j                  |      }d|_        d	D ]  }|j                  |       |r|
n|	}||d   _        |j                  |d         }d|_         |j                  di |}| j!                  ||       | j#                  |j%                         |       t'        | |||       t)        | |||         ( y)zgEnsures area values on the mask work correctly
        when using setsurface and unsetsurface.
        r  r   r  r  r  r/   r   r  r  r  r  r   r   c              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r  s      r   r7   zZMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurface.<locals>.<genexpr>(  r  r  r  Nr2   )r
   r>  r  r  r   r   r'   r  r  r!   r   rM   r   r   rL   r  r  rO   r   rV   r[   )ru   r9   r   r   r  r  r  r  r  r   r  r   r!   r  rS   rR   rU   rM  r  r  r  r8   s                        @r   :test_to_surface__area_on_mask_with_setsurface_unsetsurfacezGMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurface  s   
  &%v..x4U+\\^
!<<0()||~#\\&1,-
 $(KK-	
 F|FG! 	D;;##Dt#4DI!(I15-;MN MfL $'	!(~~i8'-$(5 $LL/2B,K25K'/#,>>+f2E#FL+1L(!0!?;!?JMM*g6$$Z%8%8%:DA'j.,W1j-	r   c           	         t        j                  d      }t        j                  d      }dx\  }}}t        j                  |t        d      }t        j                  d      }| | f| dfd| fg}|j	                  t        t        j                  d||f                   dD ]  }	t         j                  j                  ||		      }
|
j                         }|j                         }|	r|n|}|D ]  }|j                  |       ||_        |j                  |      }d|_        |
j                  ||
      }| j                  ||       | j!                  |j#                         |       t%        | |||       t'        | |||         y)zuEnsures area values off the mask work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   r   r  r   r/   r   r   r  N)r
   r  r>  r  r  rC   r'   r!   r   rM   r   r   r   rL   r  r  rO   r   rV   r[   )ru   r<  r  r8   r9   r   r   r  	positionsr   r!   r  rS   rR   rU   rM  r  s                    r   test_to_surface__area_off_maskz+MaskTypeTest.test_to_surface__area_off_mask=  sp    "<<0#\\'2%%v..x4U+ fvg&%a&\B	V[[%%IJK! 	D;;##Dt#4DI!(I15-;MN  ]+$'	!(~~i8'-$!__W9_E
j'2  !4!4!6=#D*nlS-*m\	r   c           	         dx\  }}}t        j                  |t        d      }t        j                  d      }|j	                         }t        j                  d      }|j                  |       |j	                         }t        j                  d      }	|j                  |	       | | f| dfd| fg}
|
j                  t        t        j                  d||f                   |||t        j                  d|      d}t        |      }|j                  d	       d
D ]  }t         j                  j                  ||      }|j                         }|r|n|	}|
D ]  }d
D ]  }|j                  |       |r|n|}||d   _        |j                  |d         }d|_         |j                   di |}| j#                  ||       | j%                  |j'                         |       t)        | |||       t+        | |||          y)zhEnsures area values off the mask work correctly
        when using setsurface and unsetsurface.
        r   r   r  r  r  r   r/   r  r  r   r   r  Nr2   )r
   r>  r  r  r   r   r  rC   r'   r  r  r!   r   rM   r   rL   r  r  rO   r   rV   r[   )ru   r8   r9   r   r   r  r  r  r  r  r  r   r  r   r!   r  rR   rU   r  r  rM  r  s                         r   ;test_to_surface__area_off_mask_with_setsurface_unsetsurfacezHMaskTypeTest.test_to_surface__area_off_mask_with_setsurface_unsetsurfaceb  s     &%v..x4U+\\^
!<<0()||~#\\&1,- fvg&%a&\B	V[[%%IJK
 $(KK-	
 F|FG! 	D;;##Dt#4DI15-;MN  (5 $LL/2B,K25K'/#,>>+f2E#FL+1L(!0!?;!?JMM*g6$$Z%8%8%:DA'j.,W1j-	r   c                 T   d}d}t        j                  |      }t         j                  j                  dd      }|j	                  |      }| j                  ||       t        s%| j                  t        j                  |      |       | j                  |j                         |       y)z2Ensures zero sized surfaces are handled correctly.r   r/   r   r   Tr   N)r
   r>  r!   r   r  r  r  rO   r  r  r   )ru   r  r   r   r!   r  s         r   'test_to_surface__surface_with_zero_sizez4MaskTypeTest.test_to_surface__surface_with_zero_size  s    ..&{{T2__W-
j'*S__Z8:LM,,.5r   c                 N   d}t         }d}t        j                  d      }d}t        j                  j	                  |d      }t        j
                  d||      }|j                  |      }| j                  |t        j
                         t        s%| j                  t        j                  |      |       | j                  |j                         |z         | j                  |j                         |       | j                  |j                         |       t!        | ||       y	)
z5Ensures zero sized setsurfaces are handled correctly.r	   r   r  r	   r   Tr   r/   rK  Nr  r
   r  r!   r   r>  r  rt   r  rO   r  r  r|  r  r  r   rV   )	ru   r  r  r  rR   r9  r!   r  r  s	            r   *test_to_surface__setsurface_with_zero_sizez7MaskTypeTest.test_to_surface__setsurface_with_zero_size  s     g.	{{	5^^FM>J
__
_;
j&..9S__Z8:LM
,,.>?//1>B,,.	:D*n=r   c                 J   d}t         }d}t        j                  d      }d}t        j                  j	                  |      }t        j
                  d||      }|j                  |      }| j                  |t        j
                         t        s%| j                  t        j                  |      |       | j                  |j                         |z         | j                  |j                         |       | j                  |j                         |       t!        | ||       y)z7Ensures zero sized unsetsurfaces are handled correctly.r	   r   r  r  r/   rP  Nr  )	ru   r  r  r  rR   r9  r!   r  r  s	            r   ,test_to_surface__unsetsurface_with_zero_sizez9MaskTypeTest.test_to_surface__unsetsurface_with_zero_size  s     g.	{{	*~~fm^L__,_?
j&..9S__Z8:LM
,,.>?//1>B,,.	:D*n=r   c                 
   dD ]~  }dD ]w  }d| d| }t         j                  j                  ||      }| j                  |t         j                  j                  |       | j	                  |j                         ||       y  y)z-Ensures masks can be created with zero sizes.)r  r   )r   r  r/   r   r   z, fill=r   N)r
   r!   r   rt   rO   r   )ru   r   r   r]   r!   s        r   test_zero_maskzMaskTypeTest.test_zero_mask  s    0 	=D% =dV74&1{{''4'8%%dFKK,<,<cB  $<=	=r   c                    dD ]z  }t         j                  j                  |      }|j                         }| j	                  |t         j                  j                         | j                  ||       t        | ||       | y)z0Ensures copy correctly handles zero sized masks.)rq   r   )r   rq   r/   Nr   )ru   rw   r!   r   s       r   test_zero_mask_copyz MaskTypeTest.test_zero_mask_copy  sf    7 	3M;;##M2D		I!!)V[[-=-=>Y-D)T2	3r   c                     dD ]C  }t         j                  j                  |      }|j                         }| j	                  ||       E y)z4Ensures get_size correctly handles zero sized masks.))rF  r   )r   (   r/   N)r
   r!   r   r   rO   ru   rw   r!   r   s       r   test_zero_mask_get_sizez$MaskTypeTest.test_zero_mask_get_size  s@    7 	2M;;##M2D==?DT=1	2r   c                     dD ]Y  }t        j                  d|      }t         j                  j                  |      }|j	                         }| j                  ||       [ y)z4Ensures get_rect correctly handles zero sized masks.)r  )r   r   r/   r/   N)r
   r'   r!   r   rM   rO   )ru   rw   r   r!   rB   s        r   test_zero_mask_get_rectz$MaskTypeTest.test_zero_mask_get_rect  sP    5 	2M"KK>M;;##M2D==?DT=1	2r   c                     dD ]P  }t         j                  j                  |      }| j                  t              5  |j                  d      }ddd       R y# 1 sw Y   ]xY w)z2Ensures get_at correctly handles zero sized masks.))3   r   )r   r`  r/   r/   Nr   )ru   r   r!   r   s       r   test_zero_mask_get_atz"MaskTypeTest.test_zero_mask_get_at  s[    . 	,D;;##D)D"":. ,F+, ,	,, ,   AA 	c                     dD ]P  }t         j                  j                  |      }| j                  t              5  |j                  d       ddd       R y# 1 sw Y   ]xY w)z2Ensures set_at correctly handles zero sized masks.))r   r   )r      r/   r/   Nr  r~   s      r   test_zero_mask_set_atz"MaskTypeTest.test_zero_mask_set_at  sY    . 	$D;;##D)D"":. $F#$ $	$$ $r+  c                    d}t        dd      D ]s  \  }}d| d| }t        j                  j                  |d      }t        j                  j                  |d      }|j	                  ||      }| j                  ||       u y)	zwEnsures overlap correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r/   r)  *   size1=, size2=Tr   N)r:   r
   r!   r   r  r.  )ru   r  size1size2r]   rx   ry   r  s           r   test_zero_mask_overlapz#MaskTypeTest.test_zero_mask_overlap	  s    
 +B3 	0LE55'%1CKK$$U$6EKK$$U$6E--v6Kk3/	0r   c                    d}d}t        dd      D ]t  \  }}d| d| }t        j                  j                  |d      }t        j                  j                  |d      }|j	                  ||      }| j                  |||       v y	)
z|Ensures overlap_area correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r/   r   rF  4   r1  r2  Tr   N)r:   r
   r!   r   r_   rO   )	ru   r  rv   r3  r4  r]   rx   ry   rH  s	            r   test_zero_mask_overlap_areaz(MaskTypeTest.test_zero_mask_overlap_area  s    
 +B3 	ALE55'%1CKK$$U$6EKK$$U$6E!..uf=M]NC@	Ar   c                    d}d}t        dd      D ]  \  }}d| d| }t        j                  j                  |d      }t        j                  j                  |d      }|j	                  ||      }| j                  |t        j                  j                  |       | j                  |j                         ||       | j                  |j                         ||        y	)
z|Ensures overlap_mask correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r/   r   r  r  r1  r2  Tr   N)	r:   r
   r!   r   rZ  rt   rO   r^   r   )	ru   r  rv   r3  r4  r]   rx   ry   rZ  s	            r   test_zero_mask_overlap_maskz(MaskTypeTest.test_zero_mask_overlap_mask*  s    
 +B3 		BLE55'%1CKK$$U$6EKK$$U$6E --eV<L!!,0@0@#F\//1>3G\224eSA		Br   c                     d}dD ]U  }t         j                  j                  |      }|j                          | j	                  |j                         |d|        W y)z0Ensures fill correctly handles zero sized masks.r   r  r   N)r
   r!   r   r   rO   r^   )ru   rv   r   r!   s       r   test_zero_mask_fillz MaskTypeTest.test_zero_mask_fill=  sS    0 	KD;;##D)DIIKTZZ\>U4&>J	Kr   c                     d}|D ]Q  }t         j                  j                  |      }|j                          | j	                  |j                         d       S y Nr  r   )r
   r!   r   ri  rO   r^   ru   r6   r   r!   s       r   test_zero_mask_clearz!MaskTypeTest.test_zero_mask_clearH  sI    , 	.D;;##D)DJJLTZZ\1-	.r   c                     d}|D ]Q  }t         j                  j                  |      }|j                          | j	                  |j                         d       S y r>  )r
   r!   r   r  rO   r^   r?  s       r   test_zero_mask_flipz MaskTypeTest.test_zero_mask_flipP  sI    , 	.D;;##D)DKKMTZZ\1-	.r   c                 
   d}|D ]|  }t         j                  j                  |      }|j                  d      }| j	                  |t         j                  j                         | j                  |j                         d       ~ y )Nr  r	   r   )r
   r!   r   r  rt   rO   r   )ru   r6   r   r!   ry   s        r   test_zero_mask_scalez!MaskTypeTest.test_zero_mask_scaleX  si    , 	7D;;##D)DJJv&E!!%)9)9:U^^-v6	7r   c                    d}t        dd      D ]  \  }}d| d| }t        j                  j                  |d      }t        j                  j                  |d      }|j	                         }|j                  ||       | j                  |j	                         ||       | j                  |j                         ||        y)	ztEnsures draw correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r/   r   r   r1  r2  Tr   N)r:   r
   r!   r   r^   rj  rO   r   ru   r  r3  r4  r]   rx   ry   rv   s           r   test_zero_mask_drawz MaskTypeTest.test_zero_mask_drawb  s    
 +B3 		;LE55'%1CKK$$U$6EKK$$U$6E"[[]NJJuf%U[[]NC@U^^-uc:		;r   c                    d}t        dd      D ]  \  }}d| d| }t        j                  j                  |d      }t        j                  j                  |d      }|j	                         }|j                  ||       | j                  |j	                         ||       | j                  |j                         ||        y)	zuEnsures erase correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r/      rr   r1  r2  Tr   N)r:   r
   r!   r   r^   r  rO   r   rG  s           r   test_zero_mask_erasez!MaskTypeTest.test_zero_mask_eraset  s    
 +B3 		;LE55'%1CKK$$U$6EKK$$U$6E"[[]NKKv&U[[]NC@U^^-uc:		;r   c                     d}|D ]C  }t         j                  j                  |d      }| j                  |j	                         d       E y )Nr  Tr   r   )r
   r!   r   rO   r^   r?  s       r   test_zero_mask_countz!MaskTypeTest.test_zero_mask_count  sE    , 	.D;;##Dt#4DTZZ\1-	.r   c                     d}|D ]A  }t         j                  j                  |      }| j                  |j	                         d       C y )Nr  r/   )r
   r!   r   rO   r  r?  s       r   test_zero_mask_centroidz$MaskTypeTest.test_zero_mask_centroid  s@    , 	6D;;##D)DT]]_f5	6r   c                     d}|D ]A  }t         j                  j                  |      }| j                  |j	                         d       C y )Nr  r  )r
   r!   r   rO   r
  r?  s       r   test_zero_mask_anglez!MaskTypeTest.test_zero_mask_angle  s@    , 	0D;;##D)DTZZ\3/	0r   c                     g }dD ]G  }t         j                  j                  |      }|j                         }| j	                  ||d|        I y)z3Ensures outline correctly handles zero sized masks.))r  r   r   <   r/   r   Nr
   r!   r   r  rg  ru   expected_pointsr   r!   r(   s        r   test_zero_mask_outlinez#MaskTypeTest.test_zero_mask_outline  sO    . 	JD;;##D)D\\^F  E$.I	Jr   c                     g }dD ]H  }t         j                  j                  |      }|j                  d      }| j	                  ||d|        J y)z_Ensures outline correctly handles zero sized masks
        when using the skip pixels argument.))r   r   )r   r   r/   ra  r   NrU  rV  s        r    test_zero_mask_outline__with_argz-MaskTypeTest.test_zero_mask_outline__with_arg  sT     . 	JD;;##D)D\\"%F  E$.I	Jr   c           	         dD ]  }t         j                  j                  |d      }dD ]  }d| d| }t         j                  j                  |d      }t        d|d   |d   z   dz
        t        d|d   |d   z   dz
        f}|j	                  |      }| j                  |t         j                  j                  |       | j                  |||       | j                  |j                         ||         y	)
zEnsures convolve correctly handles zero sized masks.

        Tests the different combinations of sized and zero sized masks.
        ))r   r   r   r   r   F   r/   Tr   )r  Q   r   rS  r/   sizes=rc  r   r   N)	r
   r!   r   r&   r   rt   r   rO   r   )ru   r3  rx   r4  r]   ry   rw   r!   s           r   test_zero_mask_convolvez$MaskTypeTest.test_zero_mask_convolve  s    
 : 	FEKK$$U$6E< FugRw/((T(:58eAh.2358eAh.23!
 ~~e,%%dFKK,<,<cB  uc2  -EF	Fr   c           	         dD ]  }t         j                  j                  |d      }dD ]  }t         j                  j                  |d      }dD ]  }d| d| d| }t         j                  j                  |      }|j                  ||      }| j	                  |t         j                  j                  |       | j                  |||       | j                  |j                         ||          y)	zEnsures convolve correctly handles zero sized masks
        when using an output mask argument.

        Tests the different combinations of sized and zero sized masks.
        ))rq   r   [   r   r   Z   r/   Tr   ))r   rq   )r   r   )r   >   r/   )r4  r\  r]  r/   ra  rc  N)r
   r!   r   r   rt   r  rO   r   )	ru   r3  rx   r4  ry   output_sizer]   output_maskr!   s	            r   )test_zero_mask_convolve__with_output_maskz6MaskTypeTest.test_zero_mask_convolve__with_output_mask  s     : 	HEKK$$U$6E= H((T(:#E HK"5'E7"[MBC"(++"2"2;"?K >>%=D))$0@0@#FMM$S9$$T]]_k3GHH	Hr   c                 V   d}dD ]  }d| }t         j                  j                  |      }|j                         }| j	                  |t         j                  j                  |       | j                  |j                         |       | j                  |j                         ||        y)z?Ensures connected_component correctly handles zero sized masks.r   )r_  )r   P   r/   r   N)r
   r!   r   rL  rt   rO   r   r^   )ru   rv   r   r]   r!   cc_masks         r   "test_zero_mask_connected_componentz/MaskTypeTest.test_zero_mask_connected_component  s    . 	CD$.C;;##D)D..0G!!'6;;+;+;SAW--/6W]]_ncB	Cr   c                     dD ]P  }t         j                  j                  |      }| j                  t              5  |j                  d      }ddd       R y# 1 sw Y   ]xY w)zdEnsures connected_component correctly handles zero sized masks
        when using an index argument.)rd  rf  r/   r/   N)r
   r!   r   r|   r   rL  )ru   r   r!   rn  s       r   +test_zero_mask_connected_component__indexedz8MaskTypeTest.test_zero_mask_connected_component__indexed  s_     / 	;D;;##D)D"":. ;226:; ;	;; ;r+  c                     g }dD ]G  }t         j                  j                  |      }|j                         }| j	                  ||d|        I y)z@Ensures connected_components correctly handles zero sized masks.)r   r  r/   r   N)r
   r!   r   rh  rg  )ru   expected_cc_masksr   r!   cc_maskss        r   #test_zero_mask_connected_componentsz0MaskTypeTest.test_zero_mask_connected_components  sT    . 	ND;;##D)D002H  +<dVnM	Nr   c                     g }dD ]G  }t         j                  j                  |      }|j                         }| j	                  ||d|        I y)z>Ensures get_bounding_rects correctly handles zero sized masks.))r	  r   )r   r  r/   r   N)r
   r!   r   r  rg  )ru   expected_bounding_rectsr   r!   bounding_rectss        r   !test_zero_mask_get_bounding_rectsz.MaskTypeTest.test_zero_mask_get_bounding_rects   sU    "$. 	D;;##D)D!446N   75	r   c                    t        j                  d      }t        j                  d      }dD ]  }t        j                  |t        d      }|j	                  |       dD ]z  }t         j
                  j                  |d      }|j                  ||      }| j                  ||       | j                  |j                         |       d	|vsnt        | ||       |  y
)zCEnsures to_surface correctly handles zero sized masks and surfaces.r  r  )r   )r   r   )r   r   r/   r   ))r   r   )r   r   r/   Tr   r  r   N)r
   r  r>  r  r   r!   r   r  r  rO   r   rV   )ru   
mask_color
surf_colorr  r   r9  r!   r  s           r   test_zero_mask_to_surfacez&MaskTypeTest.test_zero_mask_to_surface  s    \\&)
\\%(
9 	FInnY"=GLL$5 	F	{{''	'=!__Wz_J
j'2  !4!4!6	BI%'j*E	F		Fr   c                 "   t        j                  d      }dD ]u  }t         j                  j                  |d      }|j	                  |      }| j                  |t         j                         | j                  |j                         |       w y)z|Ensures to_surface correctly handles zero sized masks and surfaces
        when it has to create a default surface.
        r  )r  r/  r/   Tr   r  N)	r
   r  r!   r   r  rt   r>  rO   r   )ru   r{  r9  r!   r  s        r   )test_zero_mask_to_surface__create_surfacez6MaskTypeTest.test_zero_mask_to_surface__create_surface!  sw     \\&)
1 	?I;;##ID#9D*=J!!*fnn=Z002I>	?r   N)F)__name__
__module____qualname__r#  unittestskipIfr  rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r&  r+  r2  r6  r;  r@  rD  rI  rN  rP  rS  rV  rX  r]  rg  rk  ru  rx  rz  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r(  r-  r5  r9  r=  r@  rD  rP  rS  rU  rY  r^  ra  rd  rq  ru  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  expectedFailurer  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r%  r'  r)  r0  r2  r>  rC  rI  rN  rR  rV  rY  r`  rd  rf  rl  rn  rp  rr  rt  rw  ry  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r	  r  r  r  r  r  r  r  r!  r%  r'  r*  r.  r5  r8  r:  r<  r@  rB  rE  rH  rK  rM  rO  rQ  rX  rZ  rb  rk  ro  rq  ru  ry  r}  r  r2   r   r   re   re      s		   
N X__W12: 3: )B X__W12F 3F(BC&;$;
;*9
2 X__W125: 35:n.) X__W12. 3..2M!">$>$>$!"!GF@.">H<8@< X__W12G 3G: X__W12= 3=7 X__W12!G 3!GF X__W12@ 3@:@> X__W12!G 3!GFD>"GH X__W127 372 @D X__W12!D 3!DF @D X__W12&G 3&GPC=D&
9 X__W12 3$	9& X__W128 38>	9
9 X__W12 3* X__W12S 3S6!G@@B$=L@8 X__W12(G 3(GT,&G@@B$=L@8 X__W12(G 3(GT-'9  X__W12 3<
9	96	9>">&>">&6>0
0
9'*M(0 '2	D X__W12 3",,*XB$B&!
F$
L=.F):V5(5*05d X__W12w 3wr X__W12B 3B(F2B0B6B4B0>B4>B@R. B B>R0B>BB>(B>%*N&+BZB*B*
3
7B"+BB V V@ ? ?$ Q Q0 B B*RVhUVn# J?$BB0J@ D MD"HV4B.B0B0J@ D MD"HV4B0B0V6B2B2V8 JD"HV8 JD"HV8 JD"H X__W12B 3BH!F X__W12" 3 "H 3 3j ) )VB4B$F>CBR@H:E:G>V,:1f@3j X__W12 3 @ 6 6p X__W12! 3 !F X__W124 3 4l6>(>(	=	322,$0 A"B&	K..7;$;$.60	J
JF,H,C;	NF(?r   re   c                   "     e Zd ZdZ fdZ xZS )SubMaskz4Subclass of the Mask class to help test subclassing.c                 2    t        |   |i | d| _        y )NT)super__init__test_attribute)ru   r  r   	__class__s      r   r  zSubMask.__init__3  s    $)&)"r   )r  r  r  __doc__r  __classcell__r  s   @r   r  r  0  s    ># #r   r  c                   "     e Zd ZdZ fdZ xZS )SubMaskCopy;Subclass of the Mask class to help test copying subclasses.c                 F    t         |          }| j                  |_        |S rF   )r  r   r  ru   r   r  s     r   r   zSubMaskCopy.copy;  s"    GLN	#'#6#6	 r   r  r  r  r  r   r  r  s   @r   r  r  8      E r   r  c                   "     e Zd ZdZ fdZ xZS )SubMaskDunderCopyr  c                 F    t         |          }| j                  |_        |S rF   )r  __copy__r  r  s     r   r  zSubMaskDunderCopy.__copy__D  s$    G$&	#'#6#6	 r   )r  r  r  r  r  r  r  s   @r   r  r  A  r  r   r  c                   "     e Zd ZdZ fdZ xZS )SubMaskCopyAndDunderCopyr  c                      t         |          S rF   )r  r   )ru   r  s    r   r   zSubMaskCopyAndDunderCopy.copyM  s    w|~r   r  r  s   @r   r  r  J  s    E r   r  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)MaskSubclassTestzTest subclassed Masks.c                     t        dd      }| j                  |t        j                  j                         | j                  |t                | j                  |j                         y)z)Ensures the Mask class can be subclassed.r=  Tr   N)r  rt   r
   r!   r   r|  r  r  s     r   test_subclass_maskz#MaskSubclassTest.test_subclass_maskT  sJ    vD)dFKK$4$45dG,++,r   c                 f   t        dd      }|j                         t        j                  |      fD ]|  }| j                  |t        j                  j
                         | j                  |t                | j                  ||       t        | ||       | j                  t        |d             ~ y)z(Ensures copy works for subclassed Masks.r   r	   Tr   r  N)
r  r   rt   r
   r!   r   r   rc   assertFalsehasattrru   r!   r   s      r   test_subclass_copyz#MaskSubclassTest.test_subclass_copy\  s    wT* ))+tyy7 	CI!!)V[[-=-=>!!)W5Y-D)T2WY0@AB	Cr   c                    t        dd      }t        |j                         t        j                  |      f      D ]  \  }}| j                  |t        j
                  j                         | j                  |t                | j                  ||       t        | ||       d|k(  r| j                  t        |d             | j                  |j                          y)z8Ensures copy works for subclassed Masks overriding copy.r  Tr   r   r  N)r  r  r   rt   r
   r!   r   r   rc   r  r  r|  r  )ru   r!   r   r   s       r   !test_subclass_copy__override_copyz2MaskSubclassTest.test_subclass_copy__override_copyi  s    7. &tyy{DIIdO&DE 
	:LAy!!)V[[-=-=>!!)[9Y-D)T2Av  4D!EF	 8 89
	:r   c                 f   t        dd      }|j                         t        j                  |      fD ]|  }| j                  |t        j                  j
                         | j                  |t                | j                  ||       t        | ||       | j                  |j                         ~ y)z<Ensures copy works for subclassed Masks overriding __copy__.r  Tr   N)
r  r   rt   r
   r!   r   r   rc   r|  r  r  s      r   (test_subclass_copy__override_dunder_copyz9MaskSubclassTest.test_subclass_copy__override_dunder_copyz  s     t4 ))+tyy7 	6I!!)V[[-=-=>!!)->?Y-D)T2 OOI445	6r   c                 f   t        dd      }|j                         t        j                  |      fD ]|  }| j                  |t        j                  j
                         | j                  |t                | j                  ||       t        | ||       | j                  |j                         ~ y)zAEnsures copy works for subclassed Masks overriding copy/__copy__.r  Tr   N)
r  r   rt   r
   r!   r   r   rc   r|  r  r  s      r   .test_subclass_copy__override_both_copy_methodsz?MaskSubclassTest.test_subclass_copy__override_both_copy_methods  s    'd; ))+tyy7 	6I!!)V[[-=-=>!!)-EFY-D)T2OOI445	6r   c                 b    d}t        |      }|j                         }| j                  ||       y)z,Ensures get_size works for subclassed Masks.rD  N)r  r   rO   r$  s       r   test_subclass_get_sizez'MaskSubclassTest.test_subclass_get_size  s,    }%}}}-r   c                     t        j                  dd      }t        |j                  d      }|j	                         }| j                  ||       y)z,Ensures get_rect works for subclassed Masks.r/   )r   r   Tr   N)r
   r'   r  r   rM   rO   )ru   r   r!   rB   s       r   test_subclass_mask_get_rectz,MaskSubclassTest.test_subclass_mask_get_rect  s?    FH5}))5}}}-r   c                 h    d}t        dd      }|j                  d      }| j                  ||       y)z*Ensures get_at works for subclassed Masks.r   r   Tr   r/   N)r  r   rO   )ru   r  r!   bits       r   test_subclass_get_atz%MaskSubclassTest.test_subclass_get_at  s1    vD)kk&!l+r   c                     d}d}d}t        dd      }|j                  |       | j                  |j                  |      |       | j                  |j	                         |       y)z*Ensures set_at works for subclassed Masks.r   r/   Fr  r   N)r  r   rO   r   r^   )ru   r  rv   rU   r!   s        r   test_subclass_set_atz%MaskSubclassTest.test_subclass_set_at  sX    E/CS)<8~6r   c                 $   d}d}t         j                  j                  d|      t        |d      f}t         j                  j                  d|      t        |d      f}|D ]-  }|D ]&  }|j	                  |d      }| j                  ||       ( / y)z+Ensures overlap works for subclassed Masks.r/   rD  Tr   N)r
   r!   r   r  r  rO   )ru   r  r9  masks	arg_masksr!   arg_maskr  s           r   test_subclass_overlapz&MaskSubclassTest.test_subclass_overlap  s    	!!t)!<giQU>VWKK$Y7It$
	  	<D% <"ll8V<  l;<	<r   c                 6   d}|d   |d   z  }t         j                  j                  d|      t        |d      f}t         j                  j                  d|      t        |d      f}|D ]-  }|D ]&  }|j	                  |d      }| j                  ||       ( / y)z0Ensures overlap_area works for subclassed Masks.r   r   r   Tr   r/   N)r
   r!   r   r  r_   rO   )ru   r9  rv   r  r  r!   r  rH  s           r   test_subclass_overlap_areaz+MaskSubclassTest.test_subclass_overlap_area  s    	"1	!4!!t)!<giQU>VWKK$Y7It$
	  	@D% @ $ 1 1(F C  ?@	@r   c                    d}|d   |d   z  }t         j                  j                  d|      t        |d      f}t         j                  j                  d|      t        |d      f}|D ]  }|D ]  }|j	                  |d      }| j                  |t         j                  j                         | j                  |t               | j                  |j                         |       | j                  |j                         |         y)z0Ensures overlap_mask works for subclassed Masks.r   r   r   Tr   r/   N)
r
   r!   r   r  rZ  rt   assertNotIsInstancerO   r^   r   )ru   rw   rv   r  r  r!   r  rZ  s           r   test_subclass_overlap_maskz+MaskSubclassTest.test_subclass_overlap_mask  s    &q)M!,<<KK$];M4(

 KK$];M4(
	  	ID% I#006B%%lFKK4D4DE((w?  !3!3!5~F  !6!6!8-HI	Ir   c                     d}|d   |d   z  }t        d|      }|j                          | j                  |j                         |       y)z(Ensures fill works for subclassed Masks.r  r   r   Fr   N)r  r   rO   r^   ru   r9  rv   r!   s       r   test_subclass_fillz#MaskSubclassTest.test_subclass_fill  sD    	"1	!4E	2		~6r   c                     d}d}t        |d      }|j                          | j                  |j                         |       y)z)Ensures clear works for subclassed Masks.)r   r   r   TN)r  ri  rO   r^   r  s       r   test_subclass_clearz$MaskSubclassTest.test_subclass_clear  s7    	y$'

~6r   c                     d}|d   |d   z  }t        d|      }|j                          | j                  |j                         |       y)z*Ensures invert works for subclassed Masks.r   r   r   r   Fr   N)r  r  rO   r^   r  s       r   test_subclass_invertz%MaskSubclassTest.test_subclass_invert  sD    	"1	!4E	2~6r   c                     d}t        d      }|j                  |      }| j                  |t        j                  j
                         | j                  |t                | j                  |j                         |       y)z)Ensures scale works for subclassed Masks.r~  r  N)	r  r  rt   r
   r!   r   r  rO   r   )ru   rw   r!   scaled_masks       r   test_subclass_scalez$MaskSubclassTest.test_subclass_scale  sa    vjj/k6;;+;+;<  g6--/?r   c                 h   d}|d   |d   z  }t         j                  j                  d|      t        |d      f}t         j                  j                  |      t        |      fD ]K  }|D ]D  }|j	                          |j                  |d       | j                  |j                         |       F M y)z(Ensures draw works for subclassed Masks.r   r   r   Tr   r/   N)r
   r!   r   r  ri  rj  rO   r^   )ru   r9  rv   r  r!   r  s         r   test_subclass_drawz#MaskSubclassTest.test_subclass_draw  s    	"1	!4KK$Y7It$
	 [[%%i0')2DE 	?D% ?

		(F+  ~>?	?r   c                 \   d}d}t         j                  j                  |d      t        |d      f}t         j                  j                  |d      t        |d      f}|D ]K  }|D ]D  }|j	                          |j                  |d       | j                  |j                         |       F M y)z)Ensures erase works for subclassed Masks.r  r   Tr/   N)r
   r!   r   r  r   r  rO   r^   )ru   r9  rv   r  r  r!   r  s          r   test_subclass_erasez$MaskSubclassTest.test_subclass_erase/  s    	!!)T2GIt4LM[[%%i6	48PQ	  	?D% ?		

8V,  ~>?	?r   c                     d}|d   |d   z  dz
  }t        d|      }|j                  dd       |j                         }| j                  ||       y)z)Ensures count works for subclassed Masks.r~  r   r   Tr   rg   N)r  r   r^   rO   )ru   r9  rv   r!   r^   s        r   test_subclass_countz$MaskSubclassTest.test_subclass_count?  sS    	"1	!4q8Dy1FA

/r   c                 f    d}d}t        d      }|j                         }| j                  ||       y)z,Ensures centroid works for subclassed Masks.r/   r   N)r  r  rO   )ru   r  r9  r!   r  s        r   test_subclass_centroidz'MaskSubclassTest.test_subclass_centroidJ  s2    "	v==?#45r   c                 d    d}t        d      }|j                         }| j                  ||       y)z)Ensures angle works for subclassed Masks.r  r   rs   N)r  r
  r  )ru   r  r!   r
  s       r   test_subclass_anglez$MaskSubclassTest.test_subclass_angleT  s,    F#

un5r   c                 b    g }t        d      }|j                         }| j                  ||       y)z+Ensures outline works for subclassed Masks.r  N)r  r  rg  )ru   expected_outliner!   r  s       r   test_subclass_outlinez&MaskSubclassTest.test_subclass_outline]  s-    v,,.W&67r   c                     d\  }}||f}d}t        d|dz  dz
        t        d|dz  dz
        f}t        j                  j                  |      t	        |      f}t        j                  j                  |      t	        |      f}t        j                  j                  |      t	        |      fD ]]  }|D ]T  }	|j                  |	      }
| j                  |
t        j                  j                         | j                  |
t               | j                  |
j                         |       | j                  |
j                         |       |D ]  }|j                  |	|      }
| j                  |
t        j                  j                         | j                  |
j                         |       | j                  |
j                         |       t        |t              r| j                  |
t               | j                  |
t                W ` y)z,Ensures convolve works for subclassed Masks.r4  r   r	   r   N)r&   r
   r!   r   r  r   rt   r  rO   r^   r   
isinstance)ru   r8   r9   r9  rv   rw   r  output_masksr!   r  r'  rj  s               r   test_subclass_convolvez'MaskSubclassTest.test_subclass_convolvef  s   vFO	Q	A.AvzA~0FG[[%%i0')2DE	((3WY5GH [[%%i0')2DE 	ID% I $h 7%%mV[[5E5EF((@  !4!4!6G  !7!7!9=I $0 
IK$(MM(K$HM))-9I9IJ$$]%8%8%:NK$$]%;%;%=yI!+w7--mWE00H
II	Ir   c                 B   d}d}t        |      }|j                         }| j                  |t        j                  j
                         | j                  |t                | j                  |j                         |       | j                  |j                         |       y)z7Ensures connected_component works for subclassed Masks.r   r  N)
r  rL  rt   r
   r!   r   r  rO   r^   r   )ru   rv   rw   r!   rn  s        r   !test_subclass_connected_componentz2MaskSubclassTest.test_subclass_connected_component  s}    }%**,gv{{'7'78  '2.9))+];r   c                 b    g }t        d      }|j                         }| j                  ||       y)z8Ensures connected_components works for subclassed Masks.r   N)r  rh  rg  )ru   expected_ccsr!   ccss       r   "test_subclass_connected_componentsz3MaskSubclassTest.test_subclass_connected_components  s.    v'')S,/r   c                 b    g }t        d      }|j                         }| j                  ||       y)z6Ensures get_bounding_rects works for subclassed Masks.r   N)r  r  rg  )ru   rw  r!   rx  s       r    test_subclass_get_bounding_rectsz1MaskSubclassTest.test_subclass_get_bounding_rects  s0    "$v002^-DEr   c                 n   t        j                  d      }d}t        |d      }t        j                  |t        d      }|j                  t        j                  d             |j                  ||      }| j                  ||       | j                  |j                         |       t        | ||       y)	z.Ensures to_surface works for subclassed Masks.r  r=  Tr   r   r  r  N)r
   r  r  r>  r  r   r  r  rO   r   rV   r  s         r   test_subclass_to_surfacez)MaskSubclassTest.test_subclass_to_surface  s    f-t$'..x4V\\%()__W~_F
j'*,,.5D*n=r   N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r2   r   r   r  r  Q  s     -C:"6
6..,
7<"@"I.777	@?$? 	0668IB<0F>r   r  zpypy has lots of mask failuresc                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)MaskModuleTestc           	      f   d}g d}d}|d   |d   z  }d}dD ]  }t        j                  |t        |      }t        |      D ]  }||d<   |j	                  |       |dk  r|j                  d	      d   }d
d|dz
  ||dz   ddh}	|	D ]  }
d| d| d|
 }||
kD  r|}n|}t         j                  j                  ||
      }| j                  |t         j                  j                  |       | j                  |j                         ||       | j                  |j                         ||          y)a  Ensures from_surface creates a mask with the correct bits set.

        This test checks the masks created by the from_surface function using
        16 and 32 bit surfaces. Each alpha value (0-255) is tested against
        several different threshold values.
        Note: On 16 bit surface the requested alpha value can differ from what
              is actually set. This test uses the value read from the surface.
           )7      r  r   )rq   rw  r   r   r  r   r   r/   rj   r  depth=z, alpha=z, threshold=)r   r    N)r
   r>  r  r   r   r   r!   r	  rt   r   rO   r   r^   )ru   threshold_countr  rw   all_set_countnone_set_countr  r   alphathreshold_test_valuesr    r]   rv   r!   s                 r   test_from_surfacez MaskModuleTest.test_from_surface  s^    )%a(=+;; 	HEnn]HeDG/ H#(a ]+2: $NN6215E *,Q	5%!)SRU(V%!6 HI"5'%YKPCy()6)7!;;33 '9 4 D ))$0@0@#F$$T]]_mSI$$TZZ\>3GHH	Hr   c                    d}d}g d}|df}t        j                  |d      }t        j                  |t        d      }|j	                          t        |      D ]  }||d<   |j                  |d	f|        |j                          t        |      D ]  }d
| }	|j                  |d	fd	       |j                         }
t         j                  j                  ||      }| j                  |t         j                  j                  |	       | j                  |j                         ||	       | j                  |j                         |
|	       | j                  |j                  ||      |
|	        y)a  Ensures from_surface creates a mask with the correct bits set
        when pixels have different alpha values (32 bits surfaces).

        This test checks the masks created by the from_surface function using
        a 32 bit surface. The surface is created with each pixel having a
        different alpha value (0-255). This surface is tested over a range
        of threshold values (0-255).
        r/   r  )ra  r  r-  r   r   Tr   r   r   r   
threshold=N)r
   r   r>  r  rN   r   r   rP   r^   r!   r	  rt   rO   r   r_   )ru   r  r  r  rw   r\  r   r4   r    r]   rv   r!   s               r   )test_from_surface__different_alphas_32bitz8MaskModuleTest.test_from_surface__different_alphas_32bit  sN    '(!,M=.."= 	' 	2A M!NNAq6=1	2 	 / 	Iyk*C  )Q3*002N;;++GY?D!!$(8(8#>T]]_mSATZZ\>3?!!-8.#	r   c                 &   d}g d}|df}t        j                  |t        d      }|j                          t	        |      D ]  }||d<   |j                  |df|        |j                          t               }t               }t	        |      D ]N  }|j                  |df      d   }	|	|vr|g||	<   n||	   j                  |       ||	k  s>|j                  |       P g }
d}t        j                  |      }t        j                  |d	      }|j                         D ]  }|D ]  }||v r|
j                  ||dz   |f       |d
   dz   }t	        |      D ]  }|j                  |dfd        t        j                  |d	      }|j                  ||       |
j                  |||f          |
D ]  \  }}}|j                         }t	        ||      D ]  }d| }t         j                   j#                  ||      }| j%                  |t         j                   j                  |       | j'                  |j)                         ||       | j'                  |j                         ||       | j'                  |j+                  ||      ||         y)a  Ensures from_surface creates a mask with the correct bits set
        when pixels have different alpha values (16 bit surfaces).

        This test checks the masks created by the from_surface function using
        a 16 bit surface. Each pixel of the surface is set with a different
        alpha value (0-255), but since this is a 16 bit surface the requested
        alpha value can differ from what is actually set. The resulting surface
        will have groups of alpha values which complicates the test as the
        alpha groups will all be set/unset at a given threshold. The setup
        calculates these groups and an expected mask for each. This test data
        is then used to test each alpha grouping over a range of threshold
        values.
        r  )n   x      r   r   r  r   r   r/   Tr   rj   r  N)r
   r>  r  rN   r   r   rP   r   setr   rJ  addr   r   r  r^   r!   r	  rt   rO   r   r_   )ru   r  r  rw   r   r4   alpha_thresholdsspecial_thresholdsr    r  r  r  
erase_maskexp_mask
thresholdsto_thresholdthresfrom_thresholdr\  rv   r]   r!   s                         r   )test_from_surface__different_alphas_16bitz8MaskModuleTest.test_from_surface__different_alphas_16bit  s    *(!,.."= 	' 	2A M!NNAq6=1	2 	&= U / 	2I NNIq>215E,,+4+ ' '..y95 "&&y1	2 	[[/
;;}48*113 	J' 	 22$$iQ%IJ#-b>A#5L "'|!4 9"))5!*a89  &{{=tDHNN:v6$$ix%HI	& <E 	7NL-*002N"><@ 
	"9+.{{//C%%dFKK,<,<cB  -E  ~sC  %%mV<nc
	r   c                    d}d}d}dD ]  }d| }t        j                  |d|      }|D ]  }|j                  |       |j                  |j	                                t         j
                  j                  |      }| j                  |t         j
                  j                  |       | j                  |j                         ||       | j                  |j                         ||         y)zEnsures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with the colorkey color so the resulting masks
        are expected to have no bits set.
        )r  r   r`  r  r  r  r  r  r  r   r  r  N)r
   r>  set_colorkeyr   r   r!   r	  rt   r   rO   r   r^   )	ru   	colorkeysrw   rv   r  r]   r   colorkeyr!   s	            r   -test_from_surface__with_colorkey_mask_clearedz<MaskModuleTest.test_from_surface__with_colorkey_mask_cleareda  s     L	$ 	DE5'"Cnn]Au=G% 
D$$X. W1134{{//8%%dFKK,<,<cB  -E  ~sC
D		Dr   c                    d}d}d}|d   |d   z  }dD ]  }d| }t        j                  |d|      }|j                  |       |D ]  }|j                  |       t         j                  j                  |      }	| j                  |	t         j                  j                  |       | j                  |	j                         ||       | j                  |	j                         ||         y)	zEnsures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with a color that is not the colorkey color so
        the resulting masks are expected to have all bits set.
        )r  r   )ra  r  r  r  r  r  r   r   r  r  N)r
   r>  r   r	  r!   r	  rt   r   rO   r   r^   )
ru   r
  r  rw   rv   r  r]   r   r  r!   s
             r   ,test_from_surface__with_colorkey_mask_filledz;MaskModuleTest.test_from_surface__with_colorkey_mask_filled|  s     L	&&q)M!,<<$ 	DE5'"Cnn]Au=GLL'% D$$X.{{//8%%dFKK,<,<cB  -E  ~sCD	Dr   c                    d }d}d}d}t         j                  j                  |      } ||j                  ddg|  |j	                         }d}dD ]  }d	| }	t        j
                  |d|      }
 ||
j                  ||g|  |
j                  |       t         j                  j                  |
      }| j                  |t         j                  j                  |	       | j                  |j                         ||	       | j                  |j	                         ||	       | j                  |j                  ||      ||	        y
)a  Ensures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with alternating pixels of colorkey and
        non-colorkey colors, so the resulting masks are expected to have
        alternating bits set.
        c                 \    d}fdt        |      D        D ]  } | ||r|n|       | } y )NFc              3   F   K   | ]  }t              D ]  }||f 
  y wrF   r  r7  s      r   r7   zbMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate.<locals>.<genexpr>  r;  r  r  )func	set_valueunset_valuer8   r9   setbitrU   s       `  r   	alternatezOMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate  s5    FLeL $Sv);?#$r   )r   ra  r  )r`  rT  r^  )rq   r	   r   r   r/   r  r  N)r
   r!   r   r   r^   r>  r	  r	  rt   rO   r   r_   )ru   r  r  r  rw   r\  rv   r  r  r]   r   r!   s               r   -test_from_surface__with_colorkey_mask_patternz<MaskModuleTest.test_from_surface__with_colorkey_mask_pattern  s(   	$ $((7-&&1=}=&,,.$ 	E5'"Cnn]Au=GgnnmXNN  *;;++G4D!!$(8(8#>T]]_mSATZZ\>3?!!-8.#	r   c                    g d}|D ]  }t         j                  j                  dd|      }|j                  dd       t         j                  j                  |dd      }|j                         }| j                  |j                         d       | j                  |j                         t        j                  d      g        |D ]  }t         j                  j                  dd|      }t         j                  j                  dd|      }|j                  d	       |j                  d
       |j                  d	d       t         j                  j                  |dd|      }| j                  |t         j                  j                         | j                  |j                         d       | j                  |j                         t        j                  d      g        y)z*Does mask.from_threshold() work correctly?r  r  r   )r^  r^  r   r  r`  r  r  r  r  r  r  r`  r  r  ra  ra  ra  r  i  r  r  r     r   r   r#  r#  ra  ra  r  )r   colorr    othersurfacer  N)r
   r   r>  r   r!   r  r  rO   r^   r'   rt   r   )ru   r4   r   surfr!   r  surf2s          r   test_from_thresholdz"MaskModuleTest.test_from_threshold  s     
	YA>>))(Aq9DIIn&67;;--)+<D ++-ETZZ\3/T446EU9V8WX
	Y  	YA>>))(Aq9DNN**8Q:EIIo&JJ'JJ(89;;--"+"	 . D !!$(8(89TZZ\3/T446EU9V8WX	Yr   c                    dD ]  }t         j                  j                  t        j                  |            }| j	                  |t         j                  j
                  d|        | j                  |j                         |        y)z?Ensures from_surface can create masks from zero sized surfaces.r  r   N)r
   r!   r	  r>  rt   MaskTyperO   r   r~   s      r   test_zero_size_from_surfacez*MaskModuleTest.test_zero_size_from_surface  sf    0 	4D;;++FNN4,@AD!!$(<(<dVnMT]]_d3		4r   c                 v   g d}d}|D ]  }|D ]  }t         j                  j                  |d|      }|j                  dd       t         j                  j                  |dd      }| j                  |j                         d       |j                         }| j                  |g         |D ]  }t         j                  j                  |d|      }t         j                  j                  |d|      }|j                  d       |j                  d	       |j                  dd
       t         j                  j                  |dd|      }| j                  |t         j                  j                         | j                  |j                         d       |j                         }| j                  |g        
  y )Nr  r  r   r  r  r  r  r  r  r!  r  )r
   r   r>  r   r!   r  rO   r^   r  rt   r   )	ru   r4   r6   r   r   r$  r!   r  r%  s	            r   test_zero_size_from_thresholdz,MaskModuleTest.test_zero_size_from_threshold  sz   , 	,D 
,~~--dAq9		.*:;{{11-/@   q1//1  +
,  ,~~--dAq9..tQ:		/*

?+

?,<={{11,(95 %%dFKK,<,<=  q1//1  +,	,r   c                 ~   d}d}d}t        j                  |      }|D ]  }|j                  |d        t        |      }d|j                  d   z  }|D ]1  }|\  }}	||z  }
| j                  ||
|	f   ||z  z	  dz  dd| d       3 |D ]1  }|\  }}	||z  }
| j                  ||
|	f   ||z  z	  dz  dd| d	       3 y )
N)i  r  )rf   )r  ra  )   rg  )r/   )r   ra  )r-  re  r   r~  zthe pixel at z is not set to 1r   z is not set to 0)r
   r   r   
memoryviewstridesrO   )ru   r   
pixels_setpixels_unsetr!   pointviewintwidthr   r   cols              r   test_buffer_interfacez$MaskModuleTest.test_buffer_interface	  s   3
5{{4  	"EKKq!	" $t||A& 	EDAqx-Cc1f!h,/14w&67	 " 	EDAqx-Cc1f!h,/14w&67	r   N)r  r  r  r  r  r  r  r  r  r&  r)  r+  r6  r2   r   r   r  r    s?    .H`$LRhD6D4&P YD4,Br   r  __main__)r  )   rF   )#collectionsr   r   platformr   r  r  r
   pygame.localspygame.mathr   python_implementationr  r   r#   r-   r:   r<   rC   rV   r[   rc   TestCasere   r!   r   r  r  r  r  r  r  r  r  mainr2   r   r   <module>r@     s   #     
    2H224
4 IFN*(I[V?8$$ [V?|l#fkk #'  0 a>x(( a>H :;oX&& o <od zHMMO r   