
    &hx                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK7  S SK	J
r
  S\R                  " 5       :H  rSS jrS S jrS rS	 rS
 rS rS!S jrS rS!S jr " S S\R,                  5      r " S S\R0                  R2                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\R,                  5      r\R>                  " \S5       " S S\R,                  5      5       r \!S:X  a  \RD                  " 5         gg)"    )OrderedDictN)*)Vector2PyPyc                    [         R                  " U 5      n[        U S   U S   -  S-  5       HN  n[        R                  " SU S   S-
  5      [        R                  " SU S   S-
  5      pCUR                  X445        MP     U$ )zsrandom_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        N/var/www/auris/envauris/lib/python3.13/site-packages/pygame/tests/mask_test.pyrandom_maskr      su     	DA47T!W$)*~~aa1-v~~aa1/M1	! + H    c                 @   [         R                  " U R                  5       5      nU R                  5       nU(       at  [	        U R                  5       5       HU  n[	        U R                  5       5       H5  nU R                  US-   US-   45      U:w  d  M"  UR                  XT4S5        M7     MW     U$ [	        U R                  5       5       HQ  n[	        U R                  5       5       H1  nU R                  XT45      S   U:  d  M  UR                  XT4S5        M3     MS     U$ )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* 0 - K	 w))+,A7,,./>>1&)!,y8KK* 0 - Kr   c                     U S   S   =pU S   S   =p4U SS  H1  u  pV[        XQ5      n[        XR5      n[        Xc5      n[        Xd5      nM3     [        R                  " X4X!-
  S-   XC-
  S-   45      $ )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,D)A,Dqr
1|1|1|1|	  ;;|dkAot{Q%GHHr   c                 2   ^ X4U S4SU4S4mU4S jT 5       $ )zxCreates 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   Z   >#    U  H   nT  H  nS U;   d  S U;   d  M  X4v   M     M"     g7fr   N ).0absizess      r   	<genexpr>"zero_size_pairs.<locals>.<genexpr>?   s)     EEq5aAFa1fFQF5FEs   ++r2   )widthheightr6   s     @r   zero_size_pairsr;   8   s(    
 _uaj1f+v>EEEEEr   c                 V    U R                  5       u  pSUS-
  S4US-
  US-
  4SUS-
  44$ )zbReturns a tuple with the corner positions of the given mask.

Clockwise from the top left corner.
r/   r   r   )r   )r!   r9   r:   s      r   cornersr=   B   s=    
 MMOMEUQYNUQY
$;a!_MMr   c                 v   U R                   S-
  U R                  4U R                   S-
  U R                  S-
  4U R                   U R                  S-
  4U R                  S-
  U R                  S-
  4U R                  U R                  S-
  4U R                  U R                  4U R                  U R                  S-
  4U R                  U R                  4U R                  S-
  U R                  4U R                   U R                  4U R                   S-
  U R                  4U R                   S-
  U R                  S-
  44$ )znReturns 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_cornersrD   K   s     
Q!	Q1%	DHHqL!	aA&	TXX\"	TXX	T[[1_%	T[[!	a%	DKK 	Q$	Qa( r   c                   ^ Uc3  [        UR                  5       5      m[        UR                  5       5      nOoUR                  5         UR	                  UR                  5       5      n[        UR                  UR                  5      m[        UR                  UR                  5      nUR                  5         U4S jU 5        H$  nU R                  UR                  U5      X%5        M&     UR                  5         g)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   >   >#    U  H  nT  H  o"U4v   M
     M     g 7fNr2   r3   r   r   x_ranges      r   r7   &assertSurfaceFilled.<locals>.<genexpr>o        91AA   )r   r   r   	normalizeclipget_rectr?   rA   r@   rB   lockassertEqualr   unlock)testcaser   expected_color	area_recty_rangeposrI   s         @r   assertSurfaceFilledrX   `   s    
 ))+,**,-NN7#3#3#56			8	y'7'78LLN99W^^C0.F :NNr   c                 b  ^ [        UR                  5       5      m[        UR                  5       5      nUR                  5         UR	                  5         U4S jU 5        H<  nUR                  U5      (       a  M  U R                  UR                  U5      X%5        M>     UR                  5         g)z[Checks if the surface is filled with the given color. The
ignore_rect area is not checked.
c              3   >   >#    U  H  nT  H  o"U4v   M
     M     g 7frG   r2   rH   s      r   r7   0assertSurfaceFilledIgnoreArea.<locals>.<genexpr>}   rK   rL   N)	r   r   r   rM   rP   collidepointrQ   r   rR   )rS   r   rT   ignore_rectrV   rW   rI   s         @r   assertSurfaceFilledIgnoreArear^   t   s     G%%'(GG&&()GLLN99'',,  !4nJ : NNr   c                     UR                  5       nU R                  UR                  5       UR                  5       US9  U R                  XBR                  5       US9  U R                  XAR                  US5      US9  g)z-Checks to see if the 2 given masks are equal.)msgr/   N)countrQ   r   overlap_area)rS   m1m2r`   m1_counts        r   assertMaskEqualrf      se    xxzH3?88:37??2v#>CHr   c                   j   \ rS rSrSr\R                  " \S5      S 5       rS r	S r
\R                  " \S5      S 5       rS rS	 rS
 rS rS rS rS rS r\R                  " \S5      S 5       rS rS r\R                  " \S5      S 5       rS rS rS rS rS rS rS rS rS r S r!S r"S r#\R                  " \S5      S  5       r$\R                  " \S5      S! 5       r%S" r&\R                  " \S5      S# 5       r'\R                  " \S5      S$ 5       r(S% r)\R                  " \S5      S& 5       r*S' r+S( r,S) r-\R                  " \S5      S* 5       r.S+ r/\R                  " \S5      S, 5       r0S- r1\R                  " \S5      S. 5       r2S/ r3S0 r4S1 r5S2 r6\R                  " \S5      S3 5       r7S4 r8S5 r9\R                  " \S5      S6 5       r:S7 r;S8 r<\R                  " \S5      S9 5       r=\R                  " \S5      S: 5       r>S; r?S< r@S= rAS> rBS? rC\R                  " \S5      S@ 5       rDSA rESB rFSC rGSD rHSE rISF rJ\R                  " \S5      SG 5       rKSH rLSI rMSJ rN\R                  " \S5      SK 5       rOSL rPSM rQSN rRSO rSSP rTSQ rUSR rVSS rWST rXSU rYSV rZSW r[SX r\SY r]SZ r^S[ r_S\ r`S] ra\R                  " \S5      S^ 5       rbSS_ jrcSS` jrdSSa jreSb rfSc rgSd rhSe riSf rjSg rkSh rlSi rmSj rnSk roSl rp\R                  " \S5      Sm 5       rq\R                  " \S5      Sn 5       rrSo rsSp rtSq ruSr rvSs rwSt rxSu rySv rzSw r{Sx r|\R                  Sy 5       r~Sz rS{ rS| rS} rS~ rS rS rS rS rS rS rS rS rS rS rS r\R                  S 5       r\R                  S 5       r\R                  S 5       r\R                  S 5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r\R                  " \S5      S 5       rS r\R                  \R                  " \S5      S 5       5       r\R                  S 5       r\R                  S 5       rS rS rS rS rS rS rS rS rS rS rS rS rS r\R                  \R                  " \S5      S 5       5       r\R                  S 5       r\R                  \R                  " \S5      S 5       5       r\R                  \R                  " \S5      S 5       5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSrg)MaskTypeTest   )	r/   r   r   r   r   r   r   r   r   rn   rn   rn   rn   r   rn   r   zSegfaults on pypyc                 ,   SnSn[         R                  R                  U5      n[         R                  R                  US9nU R                  U[         R                  R                  5        U R	                  UR                  5       U5        U R	                  UR                  5       U5        U R                  U[         R                  R                  5        U R	                  UR                  5       U5        U R	                  UR                  5       U5        g)z:Ensure masks are created correctly without fill parameter.r         r   N)r
   r!   r   assertIsInstancerQ   ra   r   )selfexpected_countexpected_sizemask1mask2s        r   	test_maskMaskTypeTest.test_mask   s        /  m 4eV[[%5%567)=9eV[[%5%567)=9r   c                     S H7  nU R                  [        5         [        R                  " U5      nSSS5        M9     g! , (       d  f       MK  = f)z=Ensure the mask constructor handles negative sizes correctly.)rm   rr   rp   N)assertRaises
ValueErrorr
   r   ry   r   r!   s      r   test_mask__negative_size%MaskTypeTest.test_mask__negative_size   s7    0D"":.{{4( /. 1..s	   ?
A	c                 l   Su  pX4nX-  SS.nUR                  5        H  u  pVSU 3n[        R                  R                  X5S9nU R	                  U[        R                  R                  U5        U R                  UR                  5       Xg5        U R                  UR                  5       X75        M     g)z:Ensure masks are created correctly using the fill keyword.)%   /   r   TFfill=fillNitemsr
   r!   r   rx   rQ   ra   r   	ry   r9   r:   r{   fill_countsr   rz   r`   r!   s	            r   test_mask__fill_kwarg"MaskTypeTest.test_mask__fill_kwarg   s    "^A6$/$5$5$7 D$.C;;##M#=D!!$(8(8#>TZZ\>?T]]_mA %8r   c                 z   [        SS5       H  n[        SS5       H  nX!-  nX!4nSU 3n[        R                  R                  USS9nU R	                  U[        R                  R                  U5        U R                  UR                  5       X55        U R                  UR                  5       XE5        M     M     g)zEnsures 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   rx   rQ   ra   r   )ry   r:   r9   rz   r{   r`   r!   s          r   $test_mask__fill_kwarg_bit_boundaries1MaskTypeTest.test_mask__fill_kwarg_bit_boundaries   s     AqkFq"!&!&m_-{{''D'A%%dFKK,<,<cB  ~C  -E & "r   c                 p   Su  pX4nX-  SS.nUR                  5        H  u  pVSU 3n[        R                  R                  X55      nU R	                  U[        R                  R                  U5        U R                  UR                  5       Xg5        U R                  UR                  5       X75        M     g)z4Ensure masks are created correctly using a fill arg.);   G   r   r   r   Nr   r   s	            r   test_mask__fill_arg MaskTypeTest.test_mask__fill_arg   s    "^A6$/$5$5$7 D$.C;;##M8D!!$(8(8#>TZZ\>?T]]_mA %8r   c                    Su  pX4nX-  SS.nUR                  5        GH  u  pVSU 3n[        R                  R                  XSS9n[        R                  R                  X5S9n	U R	                  U[        R                  R                  U5        U R	                  U	[        R                  R                  U5        U R                  UR                  5       Xg5        U R                  U	R                  5       Xg5        U R                  UR                  5       X75        U R                  U	R                  5       X75        GM     g)z:Ensure masks are created correctly using the size keyword.)I   S   r   r   r   r   r   )r   r   Nr   )
ry   r9   r:   r{   r   r   rz   r`   r|   r}   s
             r   test_mask__size_kwarg"MaskTypeTest.test_mask__size_kwarg   s    "^A6$/$5$5$7 D$.CKK$$$$CEKK$$-$CE!!%)9)93?!!%)9)93?U[[]N@U[[]N@U^^-}BU^^-}B %8r   c                    S H  nS H  n[         R                  R                  X45      n[        U5       H,  n[        US-  US5       H  nUR	                  XE45        M     M.     UR                  5       [
        R
                  " U5      4 HJ  nU R                  U[         R                  R                  5        U R                  Xc5        [        XU5        ML     M     M     g)z:Ensures copy works correctly with some bits set and unset.       !   ?   @   A   r   r	   N)	r
   r!   r   r   r   copyrx   assertIsNotrf   )ry   r9   r:   r!   r   r   	mask_copys          r   	test_copyMaskTypeTest.test_copy   s     .E2{{''8 uA"1q5&!4QF+ 5 &
 #'))+tyy!?I)))V[[5E5EF$$Y5#DT: "@ 3 .r   c                 N   S H  nS H  n[         R                  R                  X4SS9nUR                  5       [        R                  " U5      4 HJ  nU R	                  U[         R                  R                  5        U R                  XC5        [        XU5        ML     M     M     g)z0Ensures copy works correctly on a filled masked.r   Tr   Nr
   r!   r   r   rx   r   rf   ry   r9   r:   r!   r   s        r   test_copy__fullMaskTypeTest.test_copy__full  s     .E2{{''d'C #'))+tyy!?I)))V[[5E5EF$$Y5#DT: "@	 3 .r   c                 P   S H  nS H  n[         R                  R                  X45      nUR                  5       [        R                  " U5      4 HJ  nU R	                  U[         R                  R                  5        U R                  XC5        [        XU5        ML     M     M     g)z.Ensures copy works correctly on an empty mask.r   Nr   r   s        r   test_copy__emptyMaskTypeTest.test_copy__empty  s~    -E2{{''8 #'))+tyy!?I)))V[[5E5EF$$Y5#DT: "@	 3 .r   c                    SnSn[         R                  R                  S5      nUR                  5       [        R                  " U5      4nUR	                  U5        U H  nUR	                  U5        U R                  XS5        U R                  UR                  U5      UR                  U5      5        U R                  UR                  U5      UR                  U5      5        M     g)z3Ensures copy makes an independent copy of the mask.)r   r   )r   r	   r   r   N)r
   r!   r   r   r   r   assertNotEqualr   )ry   mask_set_posmask_copy_set_posr!   mask_copiesr   s         r   test_copy__independent#MaskTypeTest.test_copy__independent'  s    #{{( yy{DIIdO4L!$I./Y-  .L0I   !23T[[AR5S %r   c                     Sn[         R                  R                  U5      nU R                  UR	                  5       U5        g)z,Ensure a mask's size is correctly retrieved.)]   e   N)r
   r!   r   rQ   r   )ry   r{   r!   s      r   test_get_sizeMaskTypeTest.test_get_size<  s1    !{{.-8r   c                     [         R                  " SS5      nS HL  n[         R                  R                  UR                  US9nUR                  5       nU R                  XA5        MN     g)z!Ensures get_rect works correctly.r/   ru      r   r   N)r
   r'   r!   r   r   rO   rQ   )ry   expected_rectr   r!   rC   s        r   test_get_rectMaskTypeTest.test_get_rectC  sV    FH5 "D;;##M$6$6T#BD==?DT1 "r   c           	      \   SnSnUSUSSS/[        SS5      40nS	n[        R                  R                  U5      nUR	                  5        H^  u  pgU HS  nU HJ  n	[        R
                  " S
U5      n
[        XU	5        UR                  " S0 X0D6nU R                  X5        ML     MU     M`     g)zYEnsures get_rect supports a single rect attribute kwarg.

Tests all the rect attributes.
)r   r   r@   r?   rB   rA   centerxcenteryr9   r:   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'   setattrrO   rQ   )ry   RECT_SINGLE_VALUE_ATTRIBUTESRECT_DOUBLE_VALUE_ATTRIBUTESrect_attributesr   r!   
attributesvalues	attributevaluer   rC   s               r   test_get_rect__one_kwarg%MaskTypeTest.test_get_rect__one_kwargO  s    (
$ (
$  )((8c1Xwq!}*M

 {{%"1"7"7"9J'	#E$*KK$=MMe<==>I+=>D$$T9 $ ( #:r   c                     [         R                  R                  S5      n[         R                  " SS5      nSS[	        SS5      S.nUR                  5        H  u  pE[        X$U5        M     UR                  " S	0 UD6nU R                  Xb5        g)
z9Ensures get_rect supports multiple rect attribute kwargs.   r   r/   gffffff@rn   r	   g	@)r   r@   r   Nr2   )	r
   r!   r   r'   r   r   r   rO   rQ   )ry   r!   r   kwargsattribr   rC   s          r   test_get_rect__multiple_kwargs+MaskTypeTest.test_get_rect__multiple_kwargs  su    {{'FF32wq#?#\\^MFM51 , }}&v&-r   c                 B   [         R                  R                  S5      nU R                  [        5         UR                  S5      nSSS5        U R                  [        5         UR                  S5      nSSS5        g! , (       d  f       N>= f! , (       d  f       g= f)z&Ensures get_rect only supports kwargs.r   r   r   Nr   r	   r
   r!   r   r   	TypeErrorrO   ry   r!   rC   s      r   test_get_rect__no_arg_support*MaskTypeTest.test_get_rect__no_arg_support  so    {{'y)==#D * y)==(D *) *) *)s   A?$B?
B
Bc                    [         R                  R                  S5      nU R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        g! , (       d  f       Ni= f! , (       d  f       NM= f! , (       d  f       g= f)	z(Ensures get_rect detects invalid kwargs.r   ru   )righteNrk   )toplefr   r	   )move)r
   r!   r   r   AttributeErrorrO   r   s      r   !test_get_rect__invalid_kwarg_name.MaskTypeTest.test_get_rect__invalid_kwarg_name  s     {{'~.===+D / ~.===/D / ~.==f=-D /. /. /. /.s#   B("B9C
(
B69
C

Cc                    [         R                  R                  S5      nU R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  S	S
9nSSS5        U R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        U R                  [        5         UR                  SS9nSSS5        g! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)z/Ensures get_rect detects invalid kwarg formats.)r   ru   1)rA   Nr   )rB   rk   )r   )r   r   )r   )r   r   r	   r   )r   r   )r   r   r   s      r   #test_get_rect__invalid_kwarg_format0MaskTypeTest.test_get_rect__invalid_kwarg_format  sY   {{(y)==s=+D * y)===-D * y)===0D * y)===2D * y)==$=/D * y)==I=6D * y)==1=-D *)% *) *) *) *) *) *) *)sS   E"E.F <F)F"F3G
E+.
E= 
F
F"
F03
G
Gc                    Su  p[         R                  R                  X45      n[         R                  R                  X4SS9nSnSnUS-
  US-
  4nU R                  UR	                  U5      U5        U R                  UR	                  US9U5        U R                  UR	                  [        U5      5      U5        U R                  UR	                  [        U5      S9U5        g)z4Ensure individual mask bits are correctly retrieved.r   r   Tr   r   r   )rW   N)r
   r!   r   rQ   r   r   )ry   r9   r:   mask0r|   mask0_expected_bitmask1_expected_bitrW   s           r   test_get_atMaskTypeTest.test_get_at  s      %1  %t <qy&1*% 	c*,>?#.0BCgcl35GH'#,79KLr   c                 T   Su  p[         R                  R                  X45      nU R                  [        5         UR                  US45        SSS5        U R                  [        5         UR                  SU45        SSS5        U R                  [        5         UR                  S5        SSS5        U R                  [        5         UR                  S5        SSS5        g! , (       d  f       N= f! , (       d  f       N~= f! , (       d  f       N`= f! , (       d  f       g= f)zEnsure get_at() checks bounds.ru   r   r   Nrq   ro   r
   r!   r   r   
IndexErrorr   ry   r9   r:   r!   s       r   test_get_at__out_of_bounds'MaskTypeTest.test_get_at__out_of_bounds      {{0z*KK
# + z*KKF$ + z*KK  + z*KK  +* +* +* +* +*/   C&+C7DD&
C47
D
D
D'c                    Su  p[         R                  R                  X45      n[         R                  R                  X4SS9nSnUR                  5       nSnUS-
  US-
  4nUR	                  X5        UR	                  [        U5      US9  U R                  UR                  U5      U5        U R                  UR                  5       U5        U R                  UR                  U5      U5        U R                  UR                  5       U5        g)z)Ensure individual mask bits are set to 1.r      Tr   r   )rW   r   N)r
   r!   r   ra   r   r   rQ   r   	ry   r9   r:   r  r|   mask0_expected_countmask1_expected_countexpected_bitrW   s	            r   test_set_atMaskTypeTest.test_set_at  s      %1  %t < ${{}qy&1*%S'\:c*L9(<=c*L9(<=r   c                    Su  p[         R                  R                  X45      n[         R                  R                  X4SS9nSnUR                  5       S-
  nSnUS-
  US-
  4nUR	                  X5        UR	                  X5        U R                  UR                  U5      U5        U R                  UR                  5       U5        U R                  UR                  U5      U5        U R                  UR                  5       U5        g)z)Ensure individual mask bits are set to 0.ru   r   Tr   r   r   Nr
   r!   r   ra   r   rQ   r   r  s	            r   test_set_at__to_0MaskTypeTest.test_set_at__to_0  s      %1  %t < ${{}q0qy&1*%S'S'c*L9(<=c*L9(<=r   c                    Su  p[         R                  R                  X45      n[         R                  R                  X4SS9nSnUR                  5       nSnUS-
  US-
  4nUR	                  U5        UR	                  U5        U R                  UR                  U5      U5        U R                  UR                  5       U5        U R                  UR                  U5      U5        U R                  UR                  5       U5        g)z<Ensure individual mask bits are set using the default value.)r      Tr   r   Nr  r  s	            r   test_set_at__default_value'MaskTypeTest.test_set_at__default_value	  s      %1  %t < ${{}qy&1*%SSc*L9(<=c*L9(<=r   c                 T   Su  p[         R                  R                  X45      nU R                  [        5         UR                  US45        SSS5        U R                  [        5         UR                  SU45        SSS5        U R                  [        5         UR                  S5        SSS5        U R                  [        5         UR                  S5        SSS5        g! , (       d  f       N= f! , (       d  f       N~= f! , (       d  f       N`= f! , (       d  f       g= f)zEnsure set_at() checks bounds.r  r   Nrq   ro   r
   r!   r   r   r  r   r  s       r   test_set_at__out_of_bounds'MaskTypeTest.test_set_at__out_of_bounds  r  r  c                 l   SnSnSnSU0nS GH#  n[         R                  R                  XS9nUR                  5       nS H  nX4n	SU	 3n
[         R                  R                  XS9nUR                  5       nUR	                  X5      nUR                  Xb5      nU R                  XU
5        U R                  UR                  5       X5        U R                  UR                  5       Xz5        U R                  UR                  5       X5        U R                  UR                  5       X5        M     GM&     g)a(  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   ra   getoverlaprQ   r   )ry   r{   offsetexpected_defaultexpected_overlapsfill2r}   mask2_countfill1r"   r`   r|   mask1_countexpected_posoverlap_poss                  r   test_overlapMaskTypeTest.test_overlap,  s    )62"EKK$$]$?E++-K&nSEl(((C#kkm044SK#mmE:  C@   A  A  !1=F  !1=F '	 #r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nU R
                   H  nSU 3n[        US   S5      [        US   S5      4n	UR                  X'S9n
U R                  XU5        U R                  UR                  5       X85        U R                  UR                  5       XH5        U R                  UR	                  5       XX5        U R                  UR	                  5       Xh5        M     g	)
z>Ensure an offset overlap intersection is correctly calculated.r   Tr   r   r   offset=r   r   otherr/  N)	r
   r!   r   ra   r   ORIGIN_OFFSETSr&   r.  rQ   )ry   r|   r}   r5  r3  
mask1_size
mask2_sizer/  r`   r6  r7  s              r   test_overlap__offset!MaskTypeTest.test_overlap__offsetO  s     t 4  t 4kkmkkm^^%
^^%
))FF8$Cq	1-s6!9a/@AL--e-CK[< U[[]K=U[[]K=U^^-z?U^^-z? *r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nSnUR                  US5        UR                  US5        UR	                  5       nUR	                  5       nUR                  5       nUR                  5       nU R                   GHD  nSU 3n	Uu  p[        US5      nSU:X  a  [        U
S-   S5      nO"SU:  a  [        U
S-   S5      nO[        U
S5      nUR                  U[        U5      5      nU R                  XU4U	5        U R                  UR	                  5       XI5        U R                  UR	                  5       XY5        U R                  UR                  5       Xi5        U R                  UR                  5       Xy5        U R                  UR                  U5      SU	5        U R                  UR                  U5      SU	5        GMG     g	)
zWEnsure 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   ra   r   r?  r&   r.  r   rQ   r   )ry   r|   r}   	unset_posr5  r3  r@  rA  r/  r`   r   r   
expected_y
expected_xr7  s                  r   $test_overlap__offset_with_unset_bits1MaskTypeTest.test_overlap__offset_with_unset_bitsf  s      t 4  t 4	Y"Y"kkmkkm^^%
^^%
))FF8$CDAQJAv Q]
Q Q]
 AY
--wv?K[z*BCH U[[]K=U[[]K=U^^-z?U^^-z?U\\)4a=U\\)4a=+ *r   c                    [         R                  R                  SSS9nUR                  5       nUR	                  5       nSu  pEXE4n[         R                  R                  U5      nUS-
  US-
  4nUR                  U5        Sn	U R                   H  n
SU
 3nUR                  Xz5      nU R                  X5        U R                  UR                  5       X+5        U R                  UR                  5       X5        U R                  UR	                  5       X;5        U R                  UR	                  5       Xk5        U R                  UR                  U5      SU5        M     g)zWEnsure an offset overlap intersection is correctly calculated
when there is no overlap.r   Tr   )C   r   r   r<  N)r
   r!   r   ra   r   r   r?  r.  assertIsNonerQ   r   )ry   r|   r5  r@  mask2_wmask2_hrA  r}   set_posr3  r/  r`   r7  s                r   test_overlap__no_overlap%MaskTypeTest.test_overlap__no_overlap  s*      t 4kkm^^%
 '
  ,Q;!,W))FF8$C--6Kk/ U[[]K=U[[]K=U^^-z?U^^-z?U\\'2As; *r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nUS   S4SUS   4US   * S4SUS   * 44nU H  nSU 3n	UR                  X(5      n
U R                  X5        U R                  UR                  5       X95        U R                  UR                  5       XI5        U R                  UR	                  5       XY5        U R                  UR	                  5       Xi5        M     g)	z9Ensures overlap handles offsets and boundaries correctly.)r   r   Tr   r   r   r   r   r<  N)r
   r!   r   ra   r   r.  rL  rQ   )ry   r|   r}   r5  r3  r@  rA  offsetsr/  r`   r7  s              r   test_overlap__offset_boundary*MaskTypeTest.test_overlap__offset_boundary  s/     t 4  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
 FF8$C--6Kk/ U[[]K=U[[]K=U^^-z?U^^-z? r   c                    [        SS5       GH8  n[        SS5       GH#  nX!4nX!-  n[        R                  R                  USS9n[        R                  R                  USS9nU R                   H  nSU SU 3n[        US   S5      [        US	   S5      4n	UR                  Xg5      n
U R                  XU5        U R                  UR                  5       XH5        U R                  UR                  5       XH5        U R                  UR                  5       X85        U R                  UR                  5       X85        M     GM&     GM;     g
)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.  rQ   ra   r   )ry   r:   r9   	mask_size
mask_countr|   r}   r/  r`   r6  r7  s              r   test_overlap__bit_boundaries)MaskTypeTest.test_overlap__bit_boundaries  s"    AqkFq""O	"^
(((>(((> #11F!)IfX>C$'q	1$5s6!9a7H#IL"'--">K$$[D $$U[[]JD$$U[[]JD$$U^^%5yF$$U^^%5yF 2 & "r   c                     SnSn[         R                  R                  U5      n[         R                  " U5      nU R	                  [
        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z8Ensure overlap handles invalid mask arguments correctly.r   r   r/   N)r
   r!   r   Surfacer   r   r.  )ry   r   r/  r!   invalid_maskr7  s         r   test_overlap__invalid_mask_arg+MaskTypeTest.test_overlap__invalid_mask_arg  sX     {{%~~d+y),,|<K *))   A**
A8c                    SnSn[         R                  R                  U5      n[         R                  R                  U5      nU R                  [        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z:Ensure overlap handles invalid offset arguments correctly.)r	   r   (0, 0)N)r
   r!   r   r   r   r.  )ry   r   r/  r|   r}   r7  s         r    test_overlap__invalid_offset_arg-MaskTypeTest.test_overlap__invalid_offset_arg  s\      &  &y)--6K *))   A33
Bc                 x   S=nu  p#SnSnSX#-  0nS GH#  n[         R                  R                  XS9nUR                  5       n	S H  n
X4nSU 3n[         R                  R                  XS9nUR                  5       nUR	                  X5      nUR                  X5      nU R                  UX5        U R                  UR                  5       X5        U R                  UR                  5       X5        U R                  UR                  5       X5        U R                  UR                  5       X5        M     GM&     g)	a4  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   ra   r-  rb   rQ   r   )ry   r{   r9   r:   r/  r0  expected_countsr2  r}   r3  r4  r"   r`   r|   r5  rz   overlap_counts                    r   test_overlap_areaMaskTypeTest.test_overlap_area  s    )/.'8"EKK$$]$?E++-K&nSEl(((C#kkm!0!4!4S!K % 2 25 A  D   A  A  !1=F  !1=F '	 #r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nUR                  5       nUR                  5       nU R                   H  n	SU	 3n
Xl        UR                  U5      nUR                  UR                  -  nUR                  X)S9nU R                  XU
5        U R                  UR                  5       X:5        U R                  UR                  5       XJ5        U R                  UR	                  5       XZ5        U R                  UR	                  5       Xj5        M     g)z6Ensure an offset overlap_area is correctly calculated.r   Tr   r;  r<  r=  N)r
   r!   r   ra   r   rO   r?  r   rN   r   r   rb   rQ   )ry   r|   r}   r5  r3  r@  rA  rect1rect2r/  r`   overlap_rectrz   rk  s                 r   test_overlap_area__offset&MaskTypeTest.test_overlap_area__offset  s>      t 4  t 4kkmkkm^^%
^^%
   ))FF8$C"M ::e,L)^^lnn<N!..U.JM]C@ U[[]K=U[[]K=U^^-z?U^^-z? *r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nSnUS   S4SUS   4US   * S4SUS   * 44nU H  n	SU	 3n
UR                  U[        U	5      5      nU R                  XU
5        U R                  UR                  5       X:5        U R                  UR                  5       XJ5        U R                  UR	                  5       XZ5        U R                  UR	                  5       Xj5        M     g)	z>Ensures overlap_area handles offsets and boundaries correctly.r  Tr   r  r   r   r<  N)r
   r!   r   ra   r   rb   r   rQ   )ry   r|   r}   r5  r3  r@  rA  rz   rT  r/  r`   rk  s               r   "test_overlap_area__offset_boundary/MaskTypeTest.test_overlap_area__offset_boundary9  s>     t 4  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
 FF8$C!..ugfoFM]C@ U[[]K=U[[]K=U^^-z?U^^-z? r   c                    [        SS5       GHj  n[        SS5       GHU  nX!4nX!-  n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  5       nUR	                  5       nU R
                   H  n	SU SU	 3n
Xl        UR                  U5      nUR                  UR                  -  nUR                  Xi5      nU R                  XU
5        U R                  UR                  5       XJ5        U R                  UR                  5       XJ5        U R                  UR                  5       X:5        U R                  UR                  5       X:5        M     GMX     GMm     g)	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   rX  N)r   r
   r!   r   rO   r?  r   rN   r   r   rb   rQ   ra   r   )ry   r:   r9   rY  rZ  r|   r}   ro  rp  r/  r`   rq  expected_overlap_countrk  s                 r   !test_overlap_area__bit_boundaries.MaskTypeTest.test_overlap_area__bit_boundariesX  sD    AqkFq""O	"^
(((>(((> (( #11F!)IfX>C$*M#(::e#4L-9^^lnn-L*$)$6$6u$EM$$]CP $$U[[]JD$$U[[]JD$$U^^%5yF$$U^^%5yF 2 & "r   c                     SnSn[         R                  R                  U5      n[         R                  " U5      nU R	                  [
        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z=Ensure overlap_area handles invalid mask arguments correctly.r   r   r/   N)r
   r!   r   r_  r   r   rb   )ry   r   r/  r!   r`  rk  s         r   #test_overlap_area__invalid_mask_arg0MaskTypeTest.test_overlap_area__invalid_mask_arg|  sX    {{%~~d+y) --lCM *))rc  c                    SnSn[         R                  R                  U5      n[         R                  R                  U5      nU R                  [        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z?Ensure overlap_area handles invalid offset arguments correctly.)r   r	   re  N)r
   r!   r   r   r   rb   )ry   r   r/  r|   r}   rk  s         r   %test_overlap_area__invalid_offset_arg2MaskTypeTest.test_overlap_area__invalid_offset_arg  s^      &  &y)!..u=M *))rh  c                 (   SnSn[         R                  R                  U5      nS[         R                  R                  USS90nS GHH  n[         R                  R                  XS9nUR                  5       nS GH  nX4n	SU	 3n
[         R                  R                  XS9nUR                  5       nUR	                  X5      nUR                  XbS9nU R                  U[         R                  R                  U
5        [        XX5        U R                  UR                  5       X5        U R                  UR                  5       Xz5        U R                  UR                  5       X5        U R                  UR                  5       X5        GM     GMK     g	)
a4  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   ra   r-  overlap_maskrx   rf   rQ   r   )ry   r{   r/  r0  expected_masksr2  r}   r3  r4  r"   r`   r|   r5  expected_maskr  s                  r   test_overlap_maskMaskTypeTest.test_overlap_mask  sP    !;;++M:&(8(8T(8(RS"EKK$$]$?E++-K&nSEl(((C#kkm . 2 23 I$111M%%lFKK4D4DcJMG   A  A  !1=F  !1=F! '	 #r   c                 Z   [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nUR                  US5      n[        S5       H?  n[        S5       H-  n	U R                  UR                  X45      SS	U S
U	 S35        M/     MA     [        S5       H@  n[        SS5       H-  n	U R                  UR                  X45      SS	U S
U	 S35        M/     MB     U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR	                  5       U5        U R                  UR	                  5       U5        g)z0Ensure overlap_mask's mask has correct bits set.2   r  Tr   )i,  
   rq   r  r  r   (, )ru   r   N)	r
   r!   r   ra   r   r  r   rQ   r   )
ry   r|   r}   r5  r3  r@  rA  mask3r   js
             r   test_overlap_mask__bits_set(MaskTypeTest.test_overlap_mask__bits_set  sd       5   6kkmkkm^^%
^^%
""5'2rA2Y  qf!5qAaS1#Q-H   rA2r]  qf!5qAaS1#Q-H # 
 	44):6):6r   c                    [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       n[         R                  " U5      nUR                  5       nUR                  5       n	U R                   GH1  n
SU
 3nXl        UR                  U	5      nUR                  5         UR                  [         R                  " UR                  SS9UR                  5        UR                  X*5      nU R                  U[         R                  R                  U5        [        XX{5        U R                  UR                  5       X;5        U R                  UR                  5       XK5        U R                  UR	                  5       X[5        U R                  UR	                  5       Xk5        GM4     g)z=Ensure an offset overlap_mask's mask is correctly calculated.r   Tr   r;  r<  N)r
   r!   r   ra   r   rO   r?  r   rN   cleardrawr   r  rx   rf   rQ   )ry   r|   r}   r5  r3  r@  rA  r  ro  rp  r/  r`   rq  r  s                 r   test_overlap_mask__offset&MaskTypeTest.test_overlap_mask__offset  s     t 4  t 4kkmkkm^^%
^^%
J/   ))FF8$C"M ::e,L!L--D9<;O;O !--e<L!!,0@0@#FDC U[[]K=U[[]K=U^^-z?U^^-z?% *r   c           	         [         R                  R                  SSS9n[         R                  R                  SSS9n[         R                  " UR                  5       5      nUR	                  5       nUR	                  5       nUR                  SS5      nS H  n[        XW[        Xg5      5        UR                  nSU 3n	UR                  U5      n
UR                  5         UR                  [         R                  " U
R                  SS9U
R                  5        UR                  X(5      nU R                  U[         R                  R                  U	5        [        XX95        M     g)	zEnsure 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   rO   inflater   getattrr   rN   r  r  r   r  rx   rf   )ry   r|   r}   r  ro  rp  corner_rectcornerr/  r`   rq  r  s               r   #test_overlap_mask__specific_offsets0MaskTypeTest.test_overlap_mask__specific_offsets  s"      t 4  t 4ENN$45    mmB+JFE7;#?@]]FF8$C ::e,L!L--D9<;O;O !--e<L!!,0@0@#FDC Kr   c                 T   [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nSnUnUS   S4SUS   4US   * S4SUS   * 44n	U	 GH  n
SU
 3nUR                  X*5      nU R                  U[         R                  R                  U5        U R                  UR                  5       X{5        U R                  UR	                  5       X5        U R                  UR                  5       X;5        U R                  UR                  5       XK5        U R                  UR	                  5       X[5        U R                  UR	                  5       Xk5        GM     g)	z>Ensures overlap_mask handles offsets and boundaries correctly.)	   r   Tr   )ru   r   r   r   r<  N)r
   r!   r   ra   r   r  rx   rQ   )ry   r|   r}   r5  r3  r@  rA  rz   r{   rT  r/  r`   r  s                r   "test_overlap_mask__offset_boundary/MaskTypeTest.test_overlap_mask__offset_boundary  s{     d 3  t 4kkmkkm^^%
^^%
" ]A
1m^QA	
 FF8$C --e<L!!,0@0@#F\//1>G\224mI U[[]K=U[[]K=U^^-z?U^^-z? r   c           
         [        SS5       GH  n[        SS5       GH  nX!4nX!-  n[        R                  R                  USS9n[        R                  R                  USS9n[        R                  " U5      nUR	                  5       nUR	                  5       n	U R
                   GH4  n
SU SU
 3nXl        UR                  U	5      nUR                  5         UR                  [        R                  " UR                  SS9UR                  5        UR                  Xj5      nU R                  U[        R                  R                  U5        [        XX{5        U R                  UR                  5       XK5        U R                  UR                  5       XK5        U R                  UR!                  5       X;5        U R                  UR!                  5       X;5        GM7     GM     GM     g)	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   rX  N)r   r
   r!   r   rO   r?  r   rN   r  r  r   r  rx   rf   rQ   ra   r   )ry   r:   r9   rY  rZ  r|   r}   r  ro  rp  r/  r`   rq  r  s                 r   !test_overlap_mask__bit_boundaries.MaskTypeTest.test_overlap_mask__bit_boundaries6  s    AqkFq""O	"^
(((>(((> &I 6 (( #11F!)IfX>C$*M#(::e#4L!'')!&&L$5$5DA<CWCW $)#5#5e#DL)),8H8H#N#DK $$U[[]JD$$U[[]JD$$U^^%5yF$$U^^%5yF% 2 & "r   c                     SnSn[         R                  R                  U5      n[         R                  " U5      nU R	                  [
        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z=Ensure overlap_mask handles invalid mask arguments correctly.r   r/   N)r
   r!   r   r_  r   r   r  )ry   r   r/  r!   r`  r  s         r   #test_overlap_mask__invalid_mask_arg0MaskTypeTest.test_overlap_mask__invalid_mask_arg_  sX    {{%~~d+y),,\BL *))rc  c                    SnSn[         R                  R                  U5      n[         R                  R                  U5      nU R                  [        5         UR                  XB5      nSSS5        g! , (       d  f       g= f)z?Ensure overlap_mask handles invalid offset arguments correctly.r   r	   re  N)r
   r!   r   r   r   r  )ry   r   r/  r|   r}   r  s         r   %test_overlap_mask__invalid_offset_arg2MaskTypeTest.test_overlap_mask__invalid_offset_argi  s^      &  &y) --e<L *))rh  c                   ^ [         R                  " S5      mTR                  SS5        U R                  TR	                  S5      S5        TR                  SS5        U R                  TR	                  S5      S5        U R                  [        U4S j5        U R                  [        U4S j5        U R                  [        U4S j5        U R                  [        U4S j5        g	)
z/do the set_at, and get_at parts work correctly?r  r  r/   r   )r  r   c                  &   > T R                  S5      $ )Nrq   )r   r   s   r   <lambda>/MaskTypeTest.test_mask_access.<locals>.<lambda>  s    ahhw.?r   c                  (   > T R                  SS5      $ )Nrq   r   r   r  s   r   r  r        ahhw.Br   c                  (   > T R                  SS5      $ )Nr  r   r   r  r  s   r   r  r    r  r   c                  (   > T R                  SS5      $ )Nr   r  r   r  r  s   r   r  r    r  r   N)r
   r   r   rQ   r   r   r  ry   r   s    @r   test_mask_accessMaskTypeTest.test_mask_accesss  s    KK!	&)1-	&)1- 	*&?@*&BC*&BC*&BCr   c                     Su  pX-  nX4n[         R                  R                  U5      nUR                  5         U R	                  UR                  5       U5        U R	                  UR                  5       U5        g)zEnsure a mask can be filled.rt   N)r
   r!   r   r   rQ   ra   r   )ry   r9   r:   rz   r{   r!   s         r   	test_fillMaskTypeTest.test_fill  s`    {{.		~6-8r   c                    [        SS5       Hr  n[        SS5       H_  n[        R                  R                  X!45      nX!-  nUR	                  5         U R                  UR                  5       USU SU S35        Ma     Mt     g)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=(r  r  N)r   r
   r!   r   r   rQ   ra   )ry   r:   r9   r!   rz   s        r   test_fill__bit_boundaries&MaskTypeTest.test_fill__bit_boundaries  st     AqkFq"{{''8!&		  JJL.F5'F812M & "r   c                     SnSn[         R                  R                  USS9nUR                  5         U R	                  UR                  5       U5        U R	                  UR                  5       U5        g)zEnsure a mask can be cleared.r   r      Tr   N)r
   r!   r   r  rQ   ra   r   ry   rz   r{   r!   s       r   
test_clearMaskTypeTest.test_clear  sZ     {{D9

~6-8r   c                    Sn[        SS5       Hm  n[        SS5       HZ  n[        R                  R                  X24SS9nUR	                  5         U R                  UR                  5       USU SU S	35        M\     Mo     g
)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  r  r  N)r   r
   r!   r   r  rQ   ra   )ry   rz   r:   r9   r!   s        r   test_clear__bit_boundaries'MaskTypeTest.test_clear__bit_boundaries  sw     AqkFq"{{''d'C

  JJL.F5'F812M & "r   c                    SnX4n[         R                  R                  U5      n[         R                  R                  USS9nX-  nSn[        U5       H3  nUS-  nUS-  nXw4nUR	                  U5        UR	                  US5        M5     UR                  5         UR                  5         U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        [        U5       HO  nXw4nSU 3n	U R                  UR                  U5      SU	5        U R                  UR                  U5      SU	5        MQ     g)zEnsure a mask can be inverted.r   Tr   r   r   zpos=N)
r
   r!   r   r   r   invertrQ   ra   r   r   )
ry   sider{   r|   r}   expected_count1expected_count2r   rW   r`   s
             r   test_invertMaskTypeTest.test_invert  sP      /  T :+tAq Oq O&CLLLLa   	88)=9)=9tA&C,CU\\#.37U\\#.37 r   c                     SnSn[         R                  R                  USS9nUR                  5         U R	                  UR                  5       U5        U R	                  UR                  5       U5        g)z#Ensure a full mask can be inverted.r   +   a   Tr   Nr
   r!   r   r  rQ   ra   r   r  s       r   test_invert__fullMaskTypeTest.test_invert__full  sZ     {{D9~6-8r   c                     Su  pX4nX-  n[         R                  R                  U5      nUR                  5         U R	                  UR                  5       U5        U R	                  UR                  5       U5        g)z%Ensure an empty mask can be inverted.r  Nr  )ry   r9   r:   r{   rz   r!   s         r   test_invert__emptyMaskTypeTest.test_invert__empty  s`    {{.~6-8r   c                 0   S H  n[        SS5       H}  n[        SS5       Hj  n[        R                  R                  X24US9nU(       a  SOX2-  nUR	                  5         U R                  UR                  5       USU SU S	U S
35        Ml     M     M     g)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=(r  r  N)r   r
   r!   r   r  rQ   ra   )ry   r   r:   r9   r!   rz   s         r   test_invert__bit_boundaries(MaskTypeTest.test_invert__bit_boundaries  s     "D1+"1b\E!;;++UO$+GD*.QENNKKM$$

&vXeWBvha@ * & "r   c                 ~   Su  pX4nS GH/  n[         R                  R                  X4S9nU(       a  X-  OSn[        US-
  US-   5       H  n[        US-
  US-   5       H  nXx4n	U(       a  Xx-  OSn
SU	 3nUR	                  U	S9nU R                  U[         R                  R                  U5        U R                  UR                  5       X5        U R                  UR                  5       U	5        U R                  UR                  5       Xk5        U R                  UR                  5       X;5        M     M     GM2     g)	zEnsure a mask can be scaled.)r  =   r   r   r   r  r   )scaleN)	r
   r!   r   r   r  rx   rQ   ra   r   )ry   r9   r:   original_sizer   original_maskoriginal_countnew_wnew_hr{   rz   r`   r!   s                r   
test_scaleMaskTypeTest.test_scale  s    !D"KK,,],FM/3U^N urz52:6"6B;<E%*NM6:U]N!-1C(..].CD))$0@0@#F$$TZZ\>G$$T]]_mD $$]%8%8%:NP$$]%;%;%=}R = 7 "r   c                    [         R                  " S5      nU R                  [        5         UR	                  S5        SSS5        U R                  [        5         UR	                  [        SS5      5        SSS5        U R                  [        5         UR	                  S5        SSS5        g! , (       d  f       Nw= f! , (       d  f       NO= f! , (       d  f       g= f)z.Ensure scale handles negative sizes correctly.d   r  rp   Nrn   r  )r  rn   )r
   r   r   r   r  r   ry   r!   s     r   test_scale__negative_size&MaskTypeTest.test_scale__negative_size,  s    {{:&z*JJx  + z*JJwr2' + z*JJx  +* +* +* +*s#   B/C C/
B= 
C
Cc                 .   SnSn[         R                  R                  USS9nS[         R                  R                  U5      0nS H  n[         R                  R                  XS9nUR                  5       nS H  nX4n	SU	 3n
[         R                  R                  XS9nUR	                  X5      nUR                  Xb5        [        XX5        U R                  UR                  5       Xz5        U R                  UR                  5       X5        M     M     g)	a  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   ra   r-  r  rf   rQ   r   ry   r{   r/  r0  r  r2  r}   r3  r4  r"   r`   r|   r  s                r   	test_drawMaskTypeTest.test_draw9  s     !;;++M+E(&++*:*:=*IJ"EKK$$]$?E++-K&nSEl(((C . 2 23 I

5)]@   A  !1=F '	 #r   c                 Z   [         R                  R                  S5      n[         R                  R                  SSS9nUR                  5       nUR	                  5       n[         R                  " UR	                  5       5      nUR                  5       nUR                  5       nU R                   H  nSU 3n	Xl        UR                  U5      n
UR                  5         [        U
R                  U
R                  5       H<  n[        U
R                  U
R                  5       H  nUR                  X45        M     M>     UR                  5         UR!                  X(S9  [#        XXY5        U R%                  UR                  5       X95        U R%                  UR	                  5       XI5        M     g)z5Ensure an offset mask can be drawn onto another mask.r   r;  Tr   r<  r=  N)r
   r!   r   ra   r   rO   r?  r   rN   r  r   r?   rA   r@   rB   r   r  rf   rQ   ry   r|   r}   r3  rA  r  ro  rp  r/  r`   rq  r   r   s                r   test_draw__offsetMaskTypeTest.test_draw__offsetY  sP     )  t 4kkm^^%
ENN$45   ))FF8$C"M ::e,L! <,,l.@.@A|//1D1DEA!((!0 F B KKMJJUJ2D< U[[]K=U^^-z?' *r   c           	         [         R                  R                  S5      n[         R                  R                  SSS9n[         R                  " UR                  5       5      nUR	                  5       nUR	                  5       nUR                  SS5      nS H  n[        XW[        Xg5      5        UR                  nSU 3n	UR                  U5      n
UR                  5         [        U
R                  U
R                  5       H<  n[        U
R                  U
R                  5       H  nUR!                  X45        M     M>     UR                  5         UR#                  X(5        [%        XX95        M     g)	zEnsure 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
r  r  Tr   r  r  r<  N)r
   r!   r   r   rO   r  r   r  r   rN   r  r   r?   rA   r@   rB   r   r  rf   ry   r|   r}   r  ro  rp  r  r  r/  r`   rq  r   r   s                r   test_draw__specific_offsets(MaskTypeTest.test_draw__specific_offsetsz  s*      )  t 4ENN$45    mmB+JFE7;#?@]]FF8$C ::e,L! <,,l.@.@A|//1D1DEA!((!0 F B KKMJJu%D<! Kr   c                 t   [         R                  R                  S5      n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nUS   S4SUS   4US   * S4SUS   * 44nU H  nSU 3n	UR                  X(5        U R                  UR                  5       X95        U R                  UR                  5       XI5        U R                  UR	                  5       XY5        U R                  UR	                  5       Xi5        M     g)	z6Ensures draw handles offsets and boundaries correctly.)r   r   r   Tr   r   r   r<  N)r
   r!   r   ra   r   r  rQ   
ry   r|   r}   r5  r3  r@  rA  rT  r/  r`   s
             r   test_draw__offset_boundary'MaskTypeTest.test_draw__offset_boundary  s     )  d 3kkmkkm^^%
^^%
 ]A
1m^QA	
 FF8$CJJu% U[[]K=U[[]K=U^^-z?U^^-z? r   c           	      n   [        SS5       GH  n[        SS5       GH  nX!4nX!-  n[        R                  R                  U5      n[        R                  R                  USS9n[        R                  " U5      nUR	                  5       nUR	                  5       n	U R
                   GH   n
SU SU
 3nXl        UR                  U	5      nUR                  5         [        UR                  UR                  5       H<  n[        UR                  UR                  5       H  nUR                  X45        M     M>     UR                  5         UR                  Xj5        [        XX{5        U R!                  UR#                  5       XK5        U R!                  UR%                  5       X;5        GM     GM     GM     g)	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   rX  N)r   r
   r!   r   rO   r?  r   rN   r  r?   rA   r@   rB   r   r  rf   rQ   ra   r   ry   r:   r9   rY  rZ  r|   r}   r  ro  rp  r/  r`   rq  r   r   s                  r   test_draw__bit_boundaries&MaskTypeTest.test_draw__bit_boundaries  sh    AqkFq""O	"^
((3(((> &I 6 (( #11F!)IfX>C$*M#(::e#4L!'')
 #<#4#4l6H6HI!&|'7'79L9L!MA)00!8 "N J KKMJJu-#DD $$U[[]JD$$U^^%5yF) 2 & "r   c                     SnSn[         R                  R                  U5      n[         R                  " U5      nU R	                  [
        5         UR                  XB5        SSS5        g! , (       d  f       g= f)z5Ensure draw handles invalid mask arguments correctly.r   r/   N)r
   r!   r   r_  r   r   r  ry   r   r/  r!   r`  s        r   test_draw__invalid_mask_arg(MaskTypeTest.test_draw__invalid_mask_arg  sT    {{%~~d+y)IIl+ *))rc  c                    SnSn[         R                  R                  U5      n[         R                  R                  U5      nU R                  [        5         UR                  XB5        SSS5        g! , (       d  f       g= f)z7Ensure draw handles invalid offset arguments correctly.r  re  N)r
   r!   r   r   r   r  ry   r   r/  r|   r}   s        r   test_draw__invalid_offset_arg*MaskTypeTest.test_draw__invalid_offset_arg  sZ      &  &y)JJu% *))rh  c                 .   SnSn[         R                  R                  U5      nS[         R                  R                  USS90nS H  n[         R                  R                  XS9nUR                  5       nS H  nX4n	SU	 3n
[         R                  R                  XS9nUR	                  X5      nUR                  Xb5        [        XX5        U R                  UR                  5       Xz5        U R                  UR                  5       X5        M     M     g)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   ra   r-  eraserf   rQ   r   r  s                r   
test_eraseMaskTypeTest.test_erase  s     !;;++M:')9)9-d)9)ST"EKK$$]$?E++-K&nSEl(((C . 2 23 IE*]@   A  !1=F '	 #r   c                 \   [         R                  R                  S5      n[         R                  R                  SSS9nUR                  5       nUR	                  5       n[         R                  " UR	                  5       5      nUR                  5       nUR                  5       nU R                   H  nSU 3n	Xl        UR                  U5      n
UR                  5         [        U
R                  U
R                  5       H=  n[        U
R                  U
R                  5       H  nUR                  X4S5        M     M?     UR                  5         UR!                  X(S9  [#        XXY5        U R%                  UR                  5       X95        U R%                  UR	                  5       XI5        M     g)	z-Ensure an offset mask can erase another mask.r   r;  Tr   r<  r   r=  N)r
   r!   r   ra   r   rO   r?  r   rN   r   r   r?   rA   r@   rB   r   r  rf   rQ   r  s                r   test_erase__offsetMaskTypeTest.test_erase__offset  sR     )  t 4kkm^^%
ENN$45   ))FF8$C"M ::e,L  <,,l.@.@A|//1D1DEA!((!3 F B JJLKKeK3D< U[[]K=U^^-z?' *r   c           	         [         R                  R                  S5      n[         R                  R                  SSS9n[         R                  " UR                  5       5      nUR	                  5       nUR	                  5       nUR                  SS5      nS H  n[        XW[        Xg5      5        UR                  nSU 3n	UR                  U5      n
UR                  5         [        U
R                  U
R                  5       H=  n[        U
R                  U
R                  5       H  nUR!                  X4S5        M     M?     UR                  5         UR#                  U[%        U5      5        ['        XX95        M     g	)
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
r  r  Tr   r  r  r<  r   N)r
   r!   r   r   rO   r  r   r  r   rN   r   r   r?   rA   r@   rB   r   r  r   rf   r  s                r   test_erase__specific_offsets)MaskTypeTest.test_erase__specific_offsets<  s2      )  t 4ENN$45    mmB+JFE7;#?@]]FF8$C ::e,L  <,,l.@.@A|//1D1DEA!((!3 F B JJLKKwv/D<! Kr   c                 r   [         R                  R                  SSS9n[         R                  R                  SSS9nUR                  5       nUR                  5       nUR	                  5       nUR	                  5       nUS   S4SUS   4US   * S4SUS   * 44nU H  nSU 3n	UR                  X(5        U R                  UR                  5       X95        U R                  UR                  5       XI5        U R                  UR	                  5       XY5        U R                  UR	                  5       Xi5        M     g)	z7Ensures erase handles offsets and boundaries correctly.r   ru   Tr   )r   r   r   r   r<  N)r
   r!   r   ra   r   r  rQ   r  s
             r   test_erase__offset_boundary(MaskTypeTest.test_erase__offset_boundaryb  s     t 4  t 4kkmkkm^^%
^^%
 ]A
1m^QA	
 FF8$CKK& U[[]K=U[[]K=U^^-z?U^^-z? r   c           	      p   [        SS5       GH  n[        SS5       GH  nX!4nX!-  n[        R                  R                  U5      n[        R                  R                  USS9n[        R                  " U5      nUR	                  5       nUR	                  5       n	U R
                   GH  n
SU SU
 3nXl        UR                  U	5      nUR                  5         [        UR                  UR                  5       H=  n[        UR                  UR                  5       H  nUR                  X4S5        M     M?     UR                  5         UR                  Xj5        [        XX{5        U R!                  UR#                  5       XK5        U R!                  UR%                  5       X;5        GM     GM     GM     g	)
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   rX  r   N)r   r
   r!   r   rO   r?  r   rN   r   r?   rA   r@   rB   r   r  rf   rQ   ra   r   r  s                  r   test_erase__bit_boundaries'MaskTypeTest.test_erase__bit_boundaries~  sj    AqkFq""O	"^
((3(((> &I 6 (( #11F!)IfX>C$*M#(::e#4L!&&(
 #<#4#4l6H6HI!&|'7'79L9L!MA)00!; "N J JJLKK.#DD $$U[[]JD$$U^^%5yF) 2 & "r   c                     SnSn[         R                  R                  U5      n[         R                  " U5      nU R	                  [
        5         UR                  XB5        SSS5        g! , (       d  f       g= f)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_arg)MaskTypeTest.test_erase__invalid_mask_arg  sT    {{%~~d+y)JJ|, *))rc  c                    SnSn[         R                  R                  U5      n[         R                  R                  U5      nU R                  [        5         UR                  XB5        SSS5        g! , (       d  f       g= f)z8Ensure erase handles invalid offset arguments correctly.rS  re  N)r
   r!   r   r   r   r  r  s        r   test_erase__invalid_offset_arg+MaskTypeTest.test_erase__invalid_offset_arg  sZ      &  &y)KK& *))rh  c                 $   SnX4nSn[         R                  R                  U5      n[        U5       H  nUS-  nUR	                  XU45        M     UR                  5       nU R                  Xc5        U R                  UR                  5       U5        g)z/Ensure a mask's set bits are correctly counted.rK  r   r   N)r
   r!   r   r   r   ra   rQ   r   )ry   r  r{   rz   r!   r   ra   s          r   
test_countMaskTypeTest.test_count  s~    {{.tAaNKK  

/-8r   c                   ^ S H  n[        SS5       H  n[        SS5       H  m[        R                  R                  TU4US9nU(       a  TU-  OSnU4S j[        U5       5        Hh  nU(       a  UR	                  US5        US-  nOUR	                  US5        US-  nUR                  5       nU R                  UUSU S	T S
U SU 35        Mj     M     M     M     g)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   P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7frG   r   r3   r   r   r9   s      r   r7   :MaskTypeTest.test_count__bit_boundaries.<locals>.<genexpr>  s     T1uU|!A|   #&r   r  r  z), pos=N)r   r
   r!   r   r   ra   rQ   )ry   r   r:   r!   rz   rW   ra   r9   s          @r   test_count__bit_boundaries'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  U * & "r   c                     Su  pX4nX-  n[         R                  R                  USS9nUR                  5       nU R	                  Xd5        U R	                  UR                  5       U5        g)z4Ensure a full mask's set bits are correctly counted.)r  r  Tr   Nr
   r!   r   ra   rQ   r   )ry   r9   r:   r{   rz   r!   ra   s          r   test_count__full_mask"MaskTypeTest.test_count__full_mask  s_    {{D9

/-8r   c                     SnSn[         R                  R                  U5      nUR                  5       nU R	                  XA5        U R	                  UR                  5       U5        g)z6Ensure an empty mask's set bits are correctly counted.r   r  Nr6  )ry   rz   r{   r!   ra   s        r   test_count__empty_mask#MaskTypeTest.test_count__empty_mask  sO     {{.

/-8r   c                     [         R                  R                  SSS9nUR                  5       R                  nUR                  5       nU R                  X25        g)z8Ensure a filled mask's centroid is correctly calculated.r  Tr   N)r
   r!   r   rO   r   centroidrQ   )ry   r!   expected_centroidr=  s       r   test_centroidMaskTypeTest.test_centroid  sF    {{T2 MMO22==?5r   c                     SnSn[         R                  R                  U5      nUR                  5       nU R	                  XA5        U R	                  UR                  5       U5        g)z8Ensure an empty mask's centroid is correctly calculated.r/   )r   g   N)r
   r!   r   r=  rQ   r   )ry   r>  r{   r!   r=  s        r   test_centroid__empty_mask&MaskTypeTest.test_centroid__empty_mask  sP    ""{{.==?5-8r   c                 (   Su  p[         R                  R                  X45      n[        U5       H_  nUR	                  5         [        U5       H=  nUR                  XT45        US-  U4nUR                  5       nU R                  Xv5        M?     Ma     g)zXEnsure a mask's centroid is correctly calculated
when setting points along a single row.r  r	   Nr
   r!   r   r   r  r   r=  rQ   ry   r9   r:   r!   r   r   r>  r=  s           r   test_centroid__single_row&MaskTypeTest.test_centroid__single_row  s{     {{0vAJJL5\QF#%&!VQK!==?  = " r   c                 V   Su  p[         R                  R                  X45      n[        SU5       Hu  nUR	                  5         [        U5       HS  nUR                  US45        UR                  XT45        US-  US-  4nUR                  5       nU R                  Xv5        MU     Mw     g)zTEnsure a mask's centroid is correctly calculated
when setting points along two rows.r  r   r   r	   NrF  rG  s           r   test_centroid__two_rows$MaskTypeTest.test_centroid__two_rows(  s     {{0 q&!AJJL5\QF#QF#%&!VQ!V$4!==?  = " "r   c                 &   Su  p[         R                  R                  X45      n[        U5       H^  nUR	                  5         [        U5       H<  nUR                  XE45        XES-  4nUR                  5       nU R                  Xv5        M>     M`     g)z[Ensure a mask's centroid is correctly calculated
when setting points along a single column.r  r	   NrF  ry   r9   r:   r!   r   r   r>  r=  s           r   test_centroid__single_column)MaskTypeTest.test_centroid__single_column;  sy     {{0uAJJL6]QF#%&QK!==?  = # r   c                 V   Su  p[         R                  R                  X45      n[        SU5       Hu  nUR	                  5         [        U5       HS  nUR                  SU45        UR                  XE45        US-  US-  4nUR                  5       nU R                  Xv5        MU     Mw     g)zWEnsure a mask's centroid is correctly calculated
when setting points along two columns.r  r   r   r	   NrF  rN  s           r   test_centroid__two_columns'MaskTypeTest.test_centroid__two_columnsL  s     {{0 q%AJJL6]QF#QF#%&!VQ!V$4!==?  = # !r   c                     [         R                  R                  S5      nUR                  5       R                  n[        U5       H  nUR                  U5        M     UR                  5       nU R                  XB5        g)zJEnsure a mask's centroid is correctly calculated
when its corners are set.r  N)	r
   r!   r   rO   r   r=   r   r=  rQ   )ry   r!   r>  r  r=  s        r   test_centroid__all_corners'MaskTypeTest.test_centroid__all_corners_  s_     {{' MMO22dmFKK $ ==?5r   c                    [         R                  R                  S5      nUR                  5       n[	        U5      n[        U5       H  u  pEX4S-   S  H  nUR                  5         UR                  U5        UR                  U5        US   US   :X  a  US   [        US   US   -
  5      S-  4nO5US   US   :X  a  [        US   US   -
  5      S-  US   4nOUR                  nUR                  5       nU R                  X5        M     M     g)zOEnsure a mask's centroid is correctly calculated
when only two corners are set.r  r   Nr   r	   )r
   r!   r   rO   r=   	enumerater  r   absr   r=  rQ   )	ry   r!   	mask_rectmask_cornersr   corner1corner2r>  r=  s	            r   test_centroid__two_corners'MaskTypeTest.test_centroid__two_cornersl  s    {{'MMO	t}#L1JA'A0

G$G$1:+)0Sgaj9P5QUV5V(W%QZ71:-),WQZ'!*-D)E)JGTUJ(W%(1(8(8%==?  = 1 2r   c                     SnSn[         R                  " U5      n[         R                  R                  U5      nUR	                  5       nU R                  U[        5        U R                  XQ5        g)z:Ensure a mask's orientation angle is correctly calculated.g     Fr  N)r
   r_  r!   from_surfaceanglerx   floatrQ   )ry   expected_angler{   r   r!   rb  s         r   
test_angleMaskTypeTest.test_angle  sW    "../{{''0

eU+/r   c                     SnSn[         R                  R                  U5      nUR                  5       nU R	                  U[
        5        U R                  XA5        U R                  UR                  5       U5        g)z5Ensure an empty mask's angle is correctly calculated.        )k   r  N)	r
   r!   r   rb  rx   rc  assertAlmostEqualrQ   r   )ry   rd  r{   r!   rb  s        r   test_angle__empty_mask#MaskTypeTest.test_angle__empty_mask  s_    !{{.

eU+u5-8r   c                    [         R                  " S5      nU R                  UR                  5       S5        UR	                  5         U R                  UR                  5       S5        [         R                  " SSS9nUR                  US5        U R                  UR                  5       S5        UR                  5         U R                  UR                  5       S	5        UR                  US
5        U R                  UR                  5       S5        UR                  5         U R                  UR                  5       S5        g)z%Test fill, clear, invert, draw, eraser  r   i'  r  Tr   r  i&  r  r/      N)	r
   r   rQ   ra   r   r  r  r  r  )ry   r   rd   s      r   test_drawingMaskTypeTest.test_drawing  s    KK
#A&	E*[[-	HD)	
C(	r6C(		A&r   c                    [         R                  " S5      nU R                  UR                  5       / 5        UR	                  SS5        U R                  UR                  5       S/5        UR	                  SS5        U R                  UR                  S5      S/5        UR	                  SS5        U R                  UR                  5       / SQ5        U R                  UR                  SS	9/ S
Q5        g) )   rs  r  r   r     r  ru   ru   )r  rv  rt  rv  r  r	   )every)r  rt  r  N)r
   r   rQ   outliner   r  s     r   test_outlineMaskTypeTest.test_outline  s     KK!b)	1xj1	12
3	1IIKK	
 	+-KLr   c           	         / SQnU H  n[         R                  " U5      nU H  n[         R                  " U5      nUR                  U5      nU R                  U[         R                  R                  5        S HN  nU R                  UR                  5       U   UR                  5       U   UR                  5       U   -   S-
  5        MP     M     M     g )N)rk   )r   r   )r   r   r  rj   r   )r
   r   convolverx   r!   rQ   r   )ry   r6   s1rc   s2rd   or   s           r   test_convolve__size MaskTypeTest.test_convolve__size  s    8BRB[[_KKO%%a)9)9:A$$

Qq)9BKKM!<L)Lq)P    r   c                    [        S5      n[        R                  " S5      nUR                  S5        UR	                  U5      nU R                  U[        R                  R                  5        [        XU5        UR	                  UR	                  U5      5      nU R                  U[        R                  R                  5        [        XU5        g)zaConvolving with a single point is the identity, while convolving a point with something flips it.r  rk   r/   N)r   r
   r   r   r|  rx   r!   rf   )ry   r   kconvolve_masks       r   test_convolve__point_identities,MaskTypeTest.test_convolve__point_identities  s    
#KK	

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

1::a=1mV[[-=-=>/r   c                 v   [        S5      n[        R                  " S5      nUR                  S5        [        R                  " S5      n[        R                  " S5      nUR	                  X#5        UR                  US5        U R                  U[        R                  R                  5        [        XU5        UR                  5         UR                  5         UR	                  X#[        SS5      S9  UR                  US5        U R                  U[        R                  R                  5        [        XU5        g	)
zGchecks that convolution modifies only the correct portion of the outputr  r	   r	   r/   r  rk   r  )r>  outputr/  rv  N)r   r
   r   r   r|  r  rx   r!   rf   r  r   )ry   r   r  r  tests        r   test_convolve__with_output'MaskTypeTest.test_convolve__with_output  s     !KK	KK!{{8$	

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

	

WR_
=		!Xa!1!12&r   c                    [         R                  " SSS9nSnU Hb  u  p4UR                  US U5      nU R                  U[         R                  R                  5        U R                  UR                  5       U5        Md     g )Nr  Tr   ))r   r   r   )r   r	   r   ))r  r  r   ))r  r   )r
   r   r|  rx   r!   rQ   ra   )ry   fullpts_dataptrz   r  s         r   test_convolve__out_of_range(MaskTypeTest.test_convolve__out_of_range  si    {{6-K"*B MM$b9M!!-1A1AB]002NC	 #+r   c                    [        S5      n[        S5      nUR                  U5      nU R                  U[        R                  R
                  5        [        UR                  5       S   5       Hd  n[        UR                  5       S   5       HA  nU R                  UR                  XE45      S:H  UR                  X$S-
  US-
  45      SL 5        MC     Mf     g)z#Tests the definition of convolutionr  r   r   c   N)r   r|  rx   r
   r!   r   r   r   rQ   r   r.  )ry   rc   rd   convr   r  s         r   test_convolveMaskTypeTest.test_convolve  s     $${{2dFKK$4$45t}}q)*A4==?1-.  KK'1,bjj"fa"f=M.NRV.V / +r   c                     [         R                  R                  X"4SS9nUR                  US-  US-  4S5        U(       a#  UR	                  XS5        UR                  5         U$ UR                  XS5        U$ )NTr   r	   r   )r
   r!   r   r   r  r  r  )ry   r!   r   rW   inversepatterns         r   _draw_component_pattern_box(MaskTypeTest._draw_component_pattern_box  sm     ++""D<d";	419-q1JJw$NN  IIg#r   c                 H   [         R                  R                  X"45      nUS-
  n[        U5       H2  n[        U5       H   nXXg-
  4;   d  M  UR	                  X45        M"     M4     U(       a#  UR                  XS5        UR                  5         U$ UR                  XS5        U$ )Nr   r
   r!   r   r   r   r  r  r  )	ry   r!   r   rW   r  r  r,   r   r   s	            r   _draw_component_pattern_x&MaskTypeTest._draw_component_pattern_x'  s     ++""D<0axtA4[DH%NNA6* ! 
 JJw$NN  IIg#r   c                 L   [         R                  R                  X"45      nUS-  =pg[        U5       H3  n[        U5       H!  n	X:X  d  X:X  d  M  UR	                  X45        M#     M5     U(       a#  UR                  XS5        UR                  5         U$ UR                  XS5        U$ )Nr	   r  )
ry   r!   r   rW   r  r  xmidymidr   r   s
             r   _draw_component_pattern_plus)MaskTypeTest._draw_component_pattern_plus=  s     ++""D<0aitA4[9	NNA6* ! 
 JJw$NN  IIg#r   c                    Su  pX4n[         R                  R                  U5      n/ nSnU R                  USU5      nUR	                  Xv45        SnX-
  S4nU R                  XHU5      nUR	                  Xv45        US-  US-  4nU R                  USU5      nUR	                  Xv45        US   u  pU	R                  5       n[        S	 U 5       5      nUR                  5       nU R                  U[         R                  R                  5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  X5      U5        U R                  UR                  5       U5        U R                  UR                  5       U5        U H4  u  pvU R                  UR                  Xv5      UR                  5       5        M6     g
)z<Ensure a mask's connected component is correctly calculated.))   r  r/   r   r   r   r	   r   rn   c              3   F   #    U  H  u  pUR                  5       v   M     g 7frG   )ra   )r3   p_s      r   r7   8MaskTypeTest.test_connected_component.<locals>.<genexpr>k  s     <841QWWYY8s   !N)r
   r!   r   r  appendr  r  ra   sumconnected_componentrx   rQ   r   rb   )ry   r9   r:   r{   r  patternsr/  r  r   expected_patternexpected_offsetrz   r  r!   s                 r   test_connected_component%MaskTypeTest.test_connected_componentS  s   ((7 006J)*,"33MP)* 1*fk*22=!VL)*,4RL))//1<8<<002dFKK$4$45~6-8.@.	

 	,,.?//1=A'OG**7;W]]_  (r   c                    Sn[         R                  R                  USS9nUR                  5       nUR	                  5       nU R                  U[         R                  R                  5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        g)zSEnsure a mask's connected component is correctly calculated
when the mask is full.
)rv   r   Tr   Nr
   r!   r   ra   r  rx   rQ   r   )ry   r{   r  rz   r!   s        r   #test_connected_component__full_mask0MaskTypeTest.test_connected_component__full_mask  s     !((T(B&,,.002dFKK$4$45~6-8 	,,.?//1=Ar   c                    Sn[         R                  R                  U5      nUR                  5       nSnUR	                  5       nU R                  U[         R                  R                  5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  5       U5        g)zTEnsure a mask's connected component is correctly calculated
when the mask is empty.
)r   r  r   Nr  )ry   r{   r  r  rz   r!   s         r   $test_connected_component__empty_mask1MaskTypeTest.test_connected_component__empty_mask  s     !((7&,,.002dFKK$4$45~6-8 	,,.?//1=Ar   c                    Su  pX4n[         R                  R                  USS9nUS-  US-  peXV4nUS-
  US-
  4nU R                  USUSS9n	Sn
UR	                  5       nUR                  U5      nU R                  U[         R                  R                  5        U R                  UR	                  5       U
5        U R                  UR                  5       U5        U R                  UR                  X5      U
5        U R                  UR	                  5       U5        U R                  UR                  5       U5        U R                  UR                  X5      U
5        g)	zEnsure a mask's connected component is correctly calculated
when the coordinate's bit is set with a connected component of 1 bit.
)r   rK  Tr   r	   r   r   )r  N)
r
   r!   r   r  ra   r  rx   rQ   r   rb   )ry   r9   r:   r{   r  xsetysetrO  r  r  rz   r  r!   s                r   %test_connected_component__one_set_bit2MaskTypeTest.test_connected_component__one_set_bit  sR    ((T(BaZ1d,!8TAX.  ;;1ot < 
 &,,.009dFKK$4$45~6-8.@.	

 	,,.?//1=A&&'7I	
r   c                 z   Sn[         R                  R                  U5      nSu  p4S=nu  pgUS-
  US-
  4n[         R                  R                  X44SS9n	[        SU5       H9  n
[        SU5       H&  nXU
S-
  US-
  4;   d  M  U	R	                  X4S	5        M(     M;     U	R                  5       nUR                  X5        UR                  U5      nU R                  U[         R                  R                  5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  X5      U5        U R                  UR                  5       U5        U R                  UR                  5       U5        U R                  UR                  X5      U5        g
)zEnsure a mask's connected component is correctly calculated
when the coordinate's bit is set with a connected component of > 1 bit.
)q   rK  r   )ru   r"  r   Tr   r   r   r   N)r
   r!   r   r   r   ra   r  r  rx   rQ   r   rb   )ry   r{   r  p_widthp_heightrO  r  r  r  r  r   r   rz   r!   s                 r   (test_connected_component__multi_set_bits5MaskTypeTest.test_connected_component__multi_set_bits  s    "((7"%%*$!8TAX.!;;++W,?d+K q(#A1g&AE7Q;//$++QFA6 ' $
 *//1+=009dFKK$4$45~6-8.@.	

 	,,.?//1=A&&'7I	
r   c                 b   Su  pX4n[         R                  R                  USS9nUS-  US-  4nUR                  US5        UR	                  5       nSnUR                  U5      nU R                  U[         R                  R                  5        U R                  UR	                  5       U5        U R                  UR                  5       U5        U R                  UR	                  5       U5        U R                  UR                  5       U5        U R                  UR                  U5      S5        g)z`Ensure 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   ra   r  rx   rQ   r   r   )	ry   r9   r:   r{   r  rE  r  rz   r!   s	            r   #test_connected_component__unset_bit0MaskTypeTest.test_connected_component__unset_bit  s    !((T(BaZ1-	Y*&,,.00;dFKK$4$45~6-8 	,,.?//1=A--i8!<r   c                    Su  pX4n[         R                  R                  USS9nUR                  5       nSSSUS-   4US-   S44 Hr  nU R	                  [
        5         UR                  U5      nSSS5        U R                  UR                  5       U5        U R                  UR                  5       U5        Mt     g! , (       d  f       NS= f)	z+Ensure connected_component() checks bounds.)   ru   Tr   ro   rq   r   r   N)	r
   r!   r   ra   r   r  r  rQ   r   )ry   r9   r:   r  r  r  rW   r!   s           r   'test_connected_component__out_of_bounds4MaskTypeTest.test_connected_component__out_of_bounds	  s    ((T(B&,,.Wq&1*o	1~FC"":.$88= / ]002NC]335}E G..s   B==
C	c                    [         R                  " S5      nU R                  UR                  5       / 5        UR	                  5       nU R                  UR                  5       UR                  5       5        UR                  SS5        UR                  SS5        UR	                  5       nUR                  5       nUR                  S5      nUR                  S5      nUR                  S5      nU R                  UR                  5       US   R                  5       5        U R                  US   R                  5       S5        U R                  US   R                  5       S5        U R                  U/ 5        UR                  SS5        UR	                  5       nUR	                  S5      nUR	                  S	5      nUR                  5       nUR                  S5      nUR                  SS
9nUR                  S5      nU R                  UR                  5       S5        U R                  UR                  5       S5        U R                  UR                  5       S5        U R                  [        U5      S5        U R                  [        U5      S5        U R                  [        U5      S5        U R                  [        U5      S5        U H-  n	U R                  U	[         R                  R                  5        M/     g)rr  r  r/   r   rk   r	   r   r   )r  r  r  )minimumN)r
   r   assertListEqualconnected_componentsr  rQ   ra   r   lenrx   r!   )
ry   r   compcompscomps1comps2comps3comp1comp2r!   s
             r   test_connected_components&MaskTypeTest.test_connected_components	  sU   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                    / nSnSn[         R                  R                  U5      nUR                  S5      nU R	                  XQ5        U R                  UR                  5       U5        U R                  UR                  5       U5        g)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   rn   N)r
   r!   r   r  r  rQ   ra   r   )ry   expected_compsrZ  rY  r!   connected_compss         r   7test_connected_components__negative_min_with_empty_maskDMaskTypeTest.test_connected_components__negative_min_with_empty_mask>	  ss     
	{{	*33B7_= 	z2)4r   c                 ^   Sn[         R                  R                  USS9nUR                  5       nSnUR	                  S5      nU R                  [        U5      U5        [        XS   U5        U R                  UR                  5       U5        U R                  UR                  5       U5        g)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   ru   Tr   r   r  r   N)	r
   r!   r   ra   r  rQ   r  rf   r   )ry   rY  r!   rZ  expected_lenr  s         r   6test_connected_components__negative_min_with_full_maskCMaskTypeTest.test_connected_components__negative_min_with_full_maskR	  s     	{{	5ZZ\
33B7_-|<a0$7 	z2)4r   c                    Sn[         R                  R                  U5      n0 n[        U5       HH  nUR	                  U5        [         R                  R                  U5      nUR	                  U5        XSU'   MJ     US   S-  US   S-  4nUR	                  U5        [         R                  R                  U5      nUR	                  U5        XSU'   UR                  5       nUR                  S5      nU R                  [        U5      [        U5      5        U Hd  n	Sn
[        UR                  5       5       H-  nU	R                  U5      (       d  M  Sn
[        X	X;   5        X;	   O   U R                  U
SW 35        Mf     U R                  UR                  5       U5        U R                  UR                  5       U5        g	)
zEnsures 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   ru  r   r	   r   r  FTzmissing component for pt=N)r
   r!   r   r=   r   ra   r  rQ   r  tuplekeysr   rf   
assertTruer   )ry   rY  r!   r  r  new_maskr   rZ  r  r  foundr  s               r   :test_connected_components__negative_min_with_some_bits_setGMaskTypeTest.test_connected_components__negative_min_with_some_bits_setg	  s    	{{	* dmFKK{{''	2HOOF#%-6" $ A,!#Yq\Q%67F;;##I.!)vZZ\
33B7_-s>/BC#D EN//12;;r?? E#D0BC&* 3 OOE%>rd#CD $ 	z2)4r   c                 0   / nUR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        U H  u  p#/ n[        R                  " U5      nU H7  nUR                  [        U5      5        U H  nUR	                  U5        M     M9     [        U[        S9nUR                  5       nU R                  [        UR                  5       [        S9USU 35        M     g	)
z+Ensures get_bounding_rects works correctly.)r  ))r/   rl   rj   )r  ))r   r   )r   r	   ))r/   rl   rj   rk   r	   r   r   r   )r^  )))r	   r   rk   r  r  r  )r^  ))r   r   r  r   )r  ))r  r   r   rj   rk   r  r  )r^  ))r/   )r  )r  )r  )r  )r"   r   N)	r  r
   r   r-   r   sortedr  get_bounding_rectsr  )	ry   	mask_datar   rect_point_tuplesrectsr!   rect_pointsr  expected_rectss	            r   test_get_bounding_rects$MaskTypeTest.test_get_bounding_rects	  s#    	 		
 		
 		
 		
 		
 	
	
 (1#DE;;t$D01+>?%BKKO &  1
 $Eu5N++-E  t..0e<v (1r   c                 @   SnSn[         R                  " U[        S5      n[         R                  " S5      n[         R                  " S5      S4[         R                  " S5      S44nU H  u  pgUR	                  U5        [         R
                  R                  X'S	9nUR                  U5      n	U R                  X5        [        (       d&  U R                  [        R                  " U	5      U5        U R                  U	R                  5       U5        [        X	U5        M     g
)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_PYPYrQ   sysgetrefcountr   rX   )
ry   expected_ref_countr   r   surface_color
test_fillsrT   r   r!   r  s
             r   test_to_surfaceMaskTypeTest.test_to_surface
  s     ..x4U+||G,d3fll76KU5ST
$. NLL';;##D#4D1JMM*.7  !<>PQZ002D9.A %/r   c                    Sn[         nSnSn[        R                  " S5      S4[        R                  " S5      S44nU GH  u  pg[        R                  R	                  XGS9nS	 H  n	U	(       a  UR                  S
5      n
OUR                  5       n
U R                  U
[        R                  5        [        (       d&  U R                  [        R                  " U
5      U5        U R                  U
R                  5       U-  5        U R                  U
R                  5       U5        U R                  U
R                  5       U5        [!        X
U5        M     GM     g
)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  rx   r_  r  rQ   r	  r
  r  	get_flagsget_bitsizer   rX   )ry   r  expected_flagexpected_depthr   r  rT   r   r!   use_argr  s              r   test_to_surface__create_surface,MaskTypeTest.test_to_surface__create_surface(
  s    ||G,d3fll76KU5ST
$. N;;##D#4D(!%!6J!%!2J%%j&..Aw$$S__Z%@BTU
 4 4 6 FG  !7!7!9>J  !4!4!6=#DnE ) %/r   c                 @   Sn[         R                  " S5      n[         R                  " S5      nSn[         R                  R                  USS9n[         R                  " U5      nSU0nS H  nUR                  U5        U(       a  UR                  " S
0 UD6n	OUR                  US   5      n	U R                  X5        [        (       d&  U R                  [        R                  " U	5      U5        U R                  U	R                  5       U5        [        X	U5        M     g	)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  rQ   r	  r
  r   rX   )
ry   r  rT   r  r   r!   r   r   
use_kwargsr  s
             r   test_to_surface__surface_param+MaskTypeTest.test_to_surface__surface_paramA
  s    g.U+{{40..&W%'JLL'!__6v6
!__VI->?
MM*.7  !<>PQZ002D9.A (r   c                    Sn[         nSn[        R                  " S5      nSn[        R                  R	                  USS9n[        R
                  " XRU5      nUR                  U5        SU0nS H  n	U	(       a  UR                  " S
0 UD6n
OUR                  S	US   5      n
U R                  U
[        R
                  5        [        (       d&  U R                  [        R                  " U
5      U5        U R                  U
R                  5       U-  5        U R                  U
R                  5       U5        U R                  U
R!                  5       U5        [#        X
U5        M     g	)z2Ensures to_surface accepts a setsurface arg/kwarg.r	   r   r  r^  Tr   
setsurfacer   Nr2   r  r
   r  r!   r   r_  r   r  rx   r  rQ   r	  r
  r  r  r  r   rX   )ry   r  r  r  rT   r   r!   r  r   r  r  s              r   !test_to_surface__setsurface_param.MaskTypeTest.test_to_surface__setsurface_paramY
  s     e,{{40^^DH
'
+'J!__6v6
!__T6,3GH
!!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A (r   c                    Sn[         nSn[        R                  " S5      nSn[        R                  R	                  U5      n[        R
                  " XRU5      nUR                  U5        SU0nS H  n	U	(       a  UR                  " S0 UD6n
OUR                  SSUS   5      n
U R                  U
[        R
                  5        [        (       d&  U R                  [        R                  " U
5      U5        U R                  U
R                  5       U-  5        U R                  U
R                  5       U5        U R                  U
R!                  5       U5        [#        X
U5        M     g)	z4Ensures to_surface accepts a unsetsurface arg/kwarg.r	   r   r  r^  unsetsurfacer   Nr2   r  )ry   r  r  r  rT   r   r!   r#  r   r  r  s              r   #test_to_surface__unsetsurface_param0MaskTypeTest.test_to_surface__unsetsurface_paramt
  s    e,{{%~~d>J.) ,/'J!__6v6
!__T49OP
!!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A (r   c                 ~   Sn[         nSn[        R                  " S5      nSn[        R                  R	                  USS9nSU0nS H  nU(       a  UR
                  " S
0 UD6n	OUR                  S	S	S	US   5      n	U R                  U	[        R                  5        [        (       d&  U R                  [        R                  " U	5      U5        U R                  U	R                  5       U-  5        U R                  U	R                  5       U5        U R                  U	R                  5       U5        [!        X	U5        M     g	)z0Ensures to_surface accepts a setcolor arg/kwarg.r	   r   r  r^  Tr   setcolorr   Nr2   r  
ry   r  r  r  rT   r   r!   r   r  r  s
             r   test_to_surface__setcolor_param,MaskTypeTest.test_to_surface__setcolor_param
  s    e,{{40n-'J!__6v6
!__T4vj?QR
!!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A (r   c                     [         R                  " S5      nSn[         R                  R                  USS9nUR	                  SSSSS9nU R                  UR                  5       U5        [        XU5        g)z(Ensures the default setcolor is correct.r  r$  Tr   N)r   r  r#  
unsetcolorr
   r  r!   r   r  rQ   r   rX   ry   rT   r   r!   r  s        r   !test_to_surface__setcolor_default.MaskTypeTest.test_to_surface__setcolor_default
  so    g.{{40__T % 

 	,,.5Dn=r   c           	         Sn[         nSn[        R                  " S5      nSn[        R                  R	                  U5      nSU0nS H  nU(       a  UR
                  " S0 UD6n	OUR                  SSSSUS   5      n	U R                  U	[        R                  5        [        (       d&  U R                  [        R                  " U	5      U5        U R                  U	R                  5       U-  5        U R                  U	R                  5       U5        U R                  U	R                  5       U5        [!        X	U5        M     g)	z2Ensures to_surface accepts a unsetcolor arg/kwarg.r	   r   r  r^  r,  r   Nr2   r  r(  s
             r   !test_to_surface__unsetcolor_param.MaskTypeTest.test_to_surface__unsetcolor_param
  s
    e,{{%/'J!__6v6
!__$dF<,@
 !!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A (r   c                     [         R                  " S5      nSn[         R                  R                  U5      nUR	                  SSSSS9nU R                  UR                  5       U5        [        XU5        g)z*Ensures the default unsetcolor is correct.r  r$  N)r   r  r#  r'  r-  r.  s        r   #test_to_surface__unsetcolor_default0MaskTypeTest.test_to_surface__unsetcolor_default
  sj    g.{{%__Tt % 

 	,,.5Dn=r   c           
         Sn[         nSnSn[        R                  " S5      nSnSn[        R                  R	                  U5      nSU0n	S H  n
U
(       a  UnUR
                  " S
0 U	D6nOUnUR                  S	S	S	S	S	U	S   5      nU R                  U[        R                  5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR                  5       U-  5        U R                  UR                  5       U5        U R                  UR                  5       U5        [!        XU5        M     g	)z,Ensures to_surface accepts a dest arg/kwarg.r	   r   r   r   r   r   r  r/   r^  destr   Nr2   r  )ry   r  r  r  default_surface_colordefault_unsetcolorr9  r   r!   r   r  rT   r  s                r   test_to_surface__dest_param(MaskTypeTest.test_to_surface__dest_param
  s      ,#\\'2{{%$'J!3!__6v6
!6!__$dD&.
 !!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A% (r   c                    [         R                  " S5      n[         R                  " S5      nSn[         R                  R                  USS9nUR	                  5       nUS   S-   US   S-   4n[         R
                  " U[        S	5      nUR                  U5        UR                  US
S
S
S9nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XX%5        g
)z$Ensures the default dest is correct.r  r  r   Tr   r   r	   r   r   Nr  r#  r,  r
   r  r!   r   rO   r_  r  r   r  r  rQ   r   rX   r^   	ry   rT   r  rY  r!   rZ  	surf_sizer   r  s	            r   test_to_surface__dest_default*MaskTypeTest.test_to_surface__dest_default
  s    g.U+	{{	5MMO	 q\A%y|a'78	..Hb9]#__4D % 

 	j*,,.	:DnH%dQr   c                    Sn[         nSnSn[        R                  " S5      nSn[        R                  R	                  U5      nSUR                  5       0nS H  n	U	(       a  Un
UR                  " S
0 UD6nOUn
UR                  SSSSSS	US   5      nU R                  U[        R                  5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR                  5       U-  5        U R                  UR                  5       U5        U R                  UR!                  5       U5        [#        XU
5        M     g)z-Ensures to_surface accepts an area arg/kwarg.r	   r   r8  r  r^  arear   Nr/   r2   )r  r
   r  r!   r   rO   r  rx   r_  r  rQ   r	  r
  r  r  r  r   rX   )ry   r  r  r  r:  r;  r   r!   r   r  rT   r  s               r   test_to_surface__area_param(MaskTypeTest.test_to_surface__area_param  s&      ,#\\'2{{%$--/*'J!3!__6v6
!6!__$dD&&.
 !!*fnn=7  !<>PQOOJ002]BCZ335~FZ002D9.A% (r   c                    [         R                  " S5      n[         R                  " S5      nSn[         R                  R                  USS9nUR	                  5       nUS   S-   US   S-   4n[         R
                  " U[        S	5      nUR                  U5        UR                  US
S
S
S9nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XX%5        g
)z$Ensures the default area is correct.r  r  r   Tr   r   r	   r   r   Nr?  r@  rA  s	            r   test_to_surface__area_default*MaskTypeTest.test_to_surface__area_default1  s    g.U+	{{	5MMO	 q\A%y|a'78	..Hb9]#__4D % 

 	j*,,.	:DnH%dQr   c                 `   [         R                  " S5      nSn[         R                  R                  USS9n[         R                  " U5      n[         R                  " S5      nUR                  5       nUR                  U5        SSS[         R                  " S	5      4S
U4SUR                  5       4SU4SU44n[        U5      nU He  u  pUR                  U	5        UR                  U5        UR                  " S0 UD6nU R                  UR                  5       U5        [        XU5        Mg     g)z.Ensures to_surface accepts the correct kwargs.r  r^  Tr   r  NNr9  r/   r,  yellowr'  r#  r  r   Nr2   )r
   r  r!   r   r_  r   r   dictpopr  rQ   r   rX   )ry   rT   r   r!   r   r  r  	test_datar   namer  r  s               r   test_to_surface__kwargs$MaskTypeTest.test_to_surface__kwargsI  s
   g.{{40..&U+\\^
' 6<<12(W\\^,:& 
	 i GDJJtLL'262JZ002D9.A !r   c                    [         R                  " S5      nSn[         R                  R                  U5      n[         R                  " U[
        S5      n[         R                  " S5      nUR                  U5        UR                  5       nUR                  U5        SSSU4S[         R                  " S	5      4S
U4SU4S4n[        U5      nU Ht  u  pUR                  U	5        UR                  " S0 UD6nU R                  U[         R                  5        U R                  UR                  5       U5        [        XU5        Mv     g)zGEnsures to_surface accepts the correct kwargs
when creating a surface.
r  r^  r   r  rM  rN  r,  r'  rO  r#  r  )r   NNr2   )r
   r  r!   r   r_  r  r   r   rP  rQ  r  rx   rQ   r   rX   )ry   rT   r   r!   r  setsurface_colorr#  rR  r   rS  r  r  s               r   &test_to_surface__kwargs_create_surface3MaskTypeTest.test_to_surface__kwargs_create_surfaceh  s     g.{{%^^D(B7
!<<.()!(.) >*h/0\*:&
	 i GDJJt262J!!*fnn=Z002D9.A !r   c           	      f   [         R                  " S5      nSn[         R                  R                  USS9n[         R                  " U5      nUR                  SUSU[         R                  " U5      SS9nU R                  XT5        U R                  UR                  5       U5        [        XU5        g)z2Ensures to_surface kwargs are not order dependent.bluer   Tr   r/   N)r9  r'  r,  r   r#  r  )
r
   r  r!   r   r_  r  r  rQ   r   rX   ry   rT   r   r!   r   r  s         r   )test_to_surface__kwargs_order_independent6MaskTypeTest.test_to_surface__kwargs_order_independent  s    f-{{40..&__#- % 

 	j*,,.5Dn=r   c           	         Sn[         R                  R                  USS9n[         R                  " S5      n[         R                  " U5      nU R                  [        5         UR                  SSSSSS5        SSS5        U R                  [        5         UR                  SSSSU5        SSS5        U R                  [        5         UR                  SSSUS5        SSS5        U R                  [        5         UR                  SSUSS5        SSS5        U R                  [        5         UR                  SUSSS5        SSS5        U R                  [        5         UR                  USSSS5        SSS5        g! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)/Ensures to_surface detects invalid kwarg types.r   Tr   greenNr   )r
   r!   r   r  r_  r   r   r  )ry   r   r!   invalid_surfinvalid_colors        r   #test_to_surface__args_invalid_types0MaskTypeTest.test_to_surface__args_invalid_types  sk   {{40||G,t,y)OOD$dD$? * y)OOD$dMB * y)OOD$mTB * y)OOD$dDA * y)OOD,dDA * y)OOL$dDA *)) *) *) *) *) *) *)sH   "FF	F$<F5/G"G
F
F!$
F25
G
G
G%c                 f   Sn[         R                  R                  U5      n[         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " S5      [         R                  " S5      SS.nS[         R                  " S5      S[         R                  " S5      [         R                  " S5      S	S.nSnU HD  n[        U5      nXF   Xv'   U R                  [        5         UR                  " S0 UD6  S
S
S
5        MF     g
! , (       d  f       MX  = f)r`  r   ra  r/   r   r  r#  r'  r,  r9  )r   r	   r   r   )r   r  r   r  r   r   r   Nr2   )	r
   r!   r   r_  r  rP  r   r   r  )ry   r   r!   valid_kwargsinvalid_kwargskwarg_orderkwargr   s           r   %test_to_surface__kwargs_invalid_types2MaskTypeTest.test_to_surface__kwargs_invalid_types  s    {{% ~~d+ ..."NN40W- ,,w/
 $ ,,w/,F+ ..0

 !E,'F*1FM""9-)&) .-	 ! .-s   D!!
D0	c                     [         R                  R                  S5      nS[         R                  " S5      0nU R	                  [
        5         UR                  " S0 UD6  SSS5        g! , (       d  f       g= f)z/Ensures to_surface detects invalid kwarg names.r   	setcolourr  Nr2   )r
   r!   r   r  r   r   r  )ry   r!   r   s      r   $test_to_surface__kwargs_invalid_name1MaskTypeTest.test_to_surface__kwargs_invalid_name  sR    {{'v||E23y)OO%f% *))s   A))
A7c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " U[        S5      nUR	                  5       nUR	                  5       n	UR                  U5        U	R                  U5        [         R                  R                  USS	9n
UnS
SU4SU4SU	4SU4SU4S4n/ n[        U5      nU H[  u  nnUb  UR                  U5        UR                  U5        UR                  U5        U
R                  " U0 UD6n[        U UU5        M]     g)z7Ensures to_surface accepts a combination of args/kwargsr^  r  rO  r[  ra  cyanr   Tr   rM  r   r  r#  r'  r,  rN  N)r
   r  r_  r  r   r   r!   r   rP  r  rQ  r  rX   )ry   r   r  rW  unsetsurface_colorr'  r,  r   r  r#  r!   rT   rR  argsr   rS  r   r  s                     r    test_to_surface__args_and_kwargs-MaskTypeTest.test_to_surface__args_and_kwargs  sQ   U+!<<1#\\&1<<(\\&)
..x4\\^
||~(),-{{40)  :&\*":&
	 i %KD%E"JJtLL'$9&9Jj.A %r   c                     Sn[         R                  R                  USS9n[         R                  " U[        S5      n[         R
                  " S5      nSSUR                  U5      USSS	4nU H  nUR                  US
9n[        XU5        M      g)z<Ensures to_surface handles valid setcolor formats correctly.r^  Tr   r   ra  r      r   r   r|  r   r|  	#00FF00FF
0x00FF00FFr'  N	r
   r!   r   r_  r  r  map_rgbr  rX   )ry   r   r!   r   rT   test_colorsr'  r  s           r   'test_to_surface__valid_setcolor_formats4MaskTypeTest.test_to_surface__valid_setcolor_formats  s    {{40..x4g.OON+
 $H(;J.A $r   c                 "   Sn[         R                  R                  U5      n[         R                  " U[        S5      n[         R
                  " S5      nSSUR                  U5      USSS4nU H  nUR                  US9n[        XU5        M      g	)
z>Ensures to_surface handles valid unsetcolor formats correctly.r^  r   ra  r{  r}  r~  r  r,  Nr  )ry   r   r!   r   rT   r  r,  r  s           r   )test_to_surface__valid_unsetcolor_formats6MaskTypeTest.test_to_surface__valid_unsetcolor_formats-  s    {{%..x4g.OON+
 &JJ?J.A &r   c                    [         R                  R                  S5      nS H0  nU R                  [        5         UR                  US9  SSS5        M2     [         R                  " S5      [         R                  " S5      S4 H0  nU R                  [        5         UR                  US9  SSS5        M2     g! , (       d  f       M  = f! , (       d  f       MV  = f)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   )ry   r!   r'  s      r   )test_to_surface__invalid_setcolor_formats6MaskTypeTest.test_to_surface__invalid_setcolor_formatsB  s    {{'LH"":.2 /. M  /V1DcJH""9-2 .- K /. .-   B8C
8
C	

C	c                    [         R                  R                  S5      nS H0  nU R                  [        5         UR                  US9  SSS5        M2     [         R                  " S5      [         R                  " S5      S4 H0  nU R                  [        5         UR                  US9  SSS5        M2     g! , (       d  f       M  = f! , (       d  f       MV  = f)z@Ensures to_surface handles invalid unsetcolor formats correctly.r^  r  r  Nr   r  r  r  )ry   r!   r,  s      r   +test_to_surface__invalid_unsetcolor_formats8MaskTypeTest.test_to_surface__invalid_unsetcolor_formatsN  s    {{'NJ"":.:6 /. O ">>&16;;v3FLJ""9-:6 .- M /. .-r  c                    [         R                  " S5      n[         R                  R                  SSS9nSSS/[	        SS5      S[         R
                  " SS5      4nU H  nUR                  US	9n[        XU5        M      g
)z8Ensures to_surface handles valid dest formats correctly.r  r|  Tr   r/   r   )r   r   r  r  r  r9  N)r
   r  r!   r   r   r'   r  rX   ry   rT   r!   destsr9  r  s         r   #test_to_surface__valid_dest_formats0MaskTypeTest.test_to_surface__valid_dest_formatsZ  sz    g.{{T2FAqMKK)
 Dd3J.A r   c                     [         R                  R                  S5      nSSSS1SS0[        4nU H0  nU R	                  [
        5         UR                  US9  SSS5        M2     g! , (       d  f       MD  = f)z:Ensures to_surface handles invalid dest formats correctly.r|  rb  ri  r   r   r  N)r
   r!   r   r'   r   r   r  )ry   r!   invalid_destsr9  s       r   %test_to_surface__invalid_dest_formats2MaskTypeTest.test_to_surface__invalid_dest_formatsk  sk    {{'FF
 "D""9-T* .- "--s   	A&&
A5	c                 <   [         R                  " S5      n[         R                  R                  SSS9n[         R                  " SS5      [         R                  " SS5      [         R                  " SS5      4nU H  nUR                  US	9n[        XU5        M      g
)z?Ensures to_surface correctly handles negative sized dest rects.r  r|  Tr   r/   )r  )r  r  )r  r  r  Nr
   r  r!   r   r'   r  rX   r  s         r   )test_to_surface__negative_sized_dest_rect6MaskTypeTest.test_to_surface__negative_sized_dest_rectz  s    g.{{T2KK	*KK	*KK
+
 Dd3J.A r   c                 <   [         R                  " S5      n[         R                  R                  SSS9n[         R                  " SS5      [         R                  " SS5      [         R                  " SS5      4nU H  nUR                  US9n[        XU5        M      g	)
z;Ensures to_surface correctly handles zero sized dest rects.r  r|  Tr   r/   r  r  r  Nr  r  s         r   %test_to_surface__zero_sized_dest_rect2MaskTypeTest.test_to_surface__zero_sized_dest_rect  s    g.{{T2KK(KK(KK'
 Dd3J.A r   c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " U5      n[         R                  R	                  USS9nSnSnUS   US	   US   US	   4Xg4U[        U5      4[        U5      U4[        U5      [        U5      4US   US	   US   US	   /Xg/U[        U5      /[        U5      U/[        U5      [        U5      /[         R                  " Xg5      4nU HQ  n	UR                  U5        [         R                  " U	5      n
UR                  XIS
9n[        XX:5        [        XX*5        MS     g)z8Ensures to_surface handles valid area formats correctly.r|  r  r  Tr   r/   r  r   r   rF  N)r
   r  r_  r!   r   listr'   r   r  rX   r^   )ry   r   r  rT   r   r!   area_pos	area_sizeareasrF  rU   r  s               r   #test_to_surface__valid_area_formats0MaskTypeTest.test_to_surface__valid_area_formats  sG    U+g...&{{40	a[(1+y|Yq\B!tI'(^Y'(^T)_-a[(1+y|Yq\B!tI'(^Y'(^T)_-KK,
 DLL'D)I<J.L)$MU r   c           	          [         R                  R                  S5      nSSSSS1 SkSS	S
.[        4nU H1  nU R	                  [
        S5         UR                  US9nSSS5        M3     g! , (       d  f       ME  = f)z:Ensures to_surface handles invalid area formats correctly.r|  rb  r/   )r   r   r   )r/   r   )rb  rk   >   r   r   r	   r   r   r   r  zinvalid area argumentr  N)r
   r!   r   r'   assertRaisesRegexr   r  )ry   r!   invalid_areasrF  unused_to_surfaces        r   %test_to_surface__invalid_area_formats2MaskTypeTest.test_to_surface__invalid_area_formats  sy     {{'aL	
 "D''	3JK$(OOO$>! LK "KKs   A++
A:	c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " U5      n[         R                  R	                  U5      nUR                  S5        [         R                  " SS5      [         R                  " SS5      [         R                  " S	S
5      4nU H;  nUR                  U5        UR                  XGS9n[        XX75        [        XX'5        M=     g)z?Ensures to_surface correctly handles negative sized area rects.r|  r  r  r/   rj   rm   rl   rr   rk   rp   r  N)r
   r  r_  r!   r   r   r'   r   r  rX   r^   )	ry   r   r  rT   r   r!   r  rF  r  s	            r   )test_to_surface__negative_sized_area_rect6MaskTypeTest.test_to_surface__negative_sized_area_rect  s     U+g...&{{%F KK(KK(KK)
 DLL'<J.G)$MP r   c                    Sn[         R                  " S5      n[         R                  " U5      n[         R                  R	                  USS9n[         R
                  " SS5      [         R
                  " SS5      [         R
                  " SS5      4nU H/  nUR                  U5        UR                  X6S9n[        XU5        M1     g	)
z;Ensures to_surface correctly handles zero sized area rects.r|  r  Tr   r/   rj   rl   r  N)	r
   r  r_  r!   r   r'   r   r  rX   )ry   r   rT   r   r!   r  rF  r  s           r   %test_to_surface__zero_sized_area_rect2MaskTypeTest.test_to_surface__zero_sized_area_rect  s     e,..&{{40 KK'KK'KK'
 DLL(<J.A r   c                    Sn[         nSnSnSnSn[        R                  " S5      n[        R                  " S5      n[        R                  " S5      n	[        R                  " S	5      n
[        R                  " XBU5      nUR	                  5       nUR                  U5        UR                  U5        S
S
S
S
S
S.nS GH  n[        R                  R                  XNS9nUS
4 GH]  nUUS'   US
4 GHK  nUUS'   U	S
4 GH9  nUUS'   U
S
4 GH'  nUUS'   US
4 GH  nUc  UR                  SS
5        OUUS'   U(       a  Ub  UnOUb  U	nOUnOUb  UnOUb  U
nOUnUR                  " S0 UD6nU R                  U[        R                  5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR!                  5       U-  5        U R                  UR#                  5       U5        U R                  UR%                  5       U5        ['        U UU5        GM     GM*     GM<     GMN     GM`     GM     g
)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/   r8  rO  r[  ra  ru  N)r  r#  r'  r,  r9  r   r   r  r#  r'  r,  r9  r2   )r  r
   r  r_  r   r   r!   r   rQ  r  rx   r  rQ   r	  r
  r  r  r  r   rX   )ry   r  r  r  r   r9  r:  rW  rv  r'  r,  r  r#  r   r   r!   setsurface_paramunsetsurface_paramsetcolor_paramunsetcolor_param
dest_paramrT   r  s                          r   8test_to_surface__default_surface_with_param_combinationsEMaskTypeTest.test_to_surface__default_surface_with_param_combinations  sF      ,!<<1#\\&1<<(\\&)
^^DH
!((),-  
 "D;;##D#4D &0$6 '7|$+7*>&-?F>*+3T*:-;z*1;T0B,3CF<0/3Tl
#-#5$*JJvt$<5?F6N#''7'C9I)7)C9A9N'9'E9K)9)E9C9N-1__-Fv-F
 $ 5 5j&.. Q'.w$($4$4(+
(CEW%& !%
0D0D0F0V W $ 0 0$.$:$:$<n!" !% 0 01D1D1F M 3D*n UC /; 1C +; +? %7	 "r   c                    Sn[         nSnSnSn[        R                  " S5      n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      n	[        R                  " S	5      n
[        R                  " XBU5      nUR	                  5       nUR	                  5       nUR                  U5        UR                  U5        US
S
S
S
S
S.nS GH  n[        R                  R                  XOS9nUS
4 GH`  nUUS'   US
4 GHN  nUUS'   U	S
4 GH<  nUUS'   U
S
4 GH*  nUUS'   UR                  U5        US
4 GH  nUc  UR                  SS
5        OUUS'   U(       a  Ub  UnOUb  U	nOUnOUb  UnOUb  U
nOUnUR                  " S0 UD6nU R                  UU5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR!                  5       U-  5        U R                  UR#                  5       U5        U R                  UR%                  5       U5        ['        U UU5        GM
     GM-     GM?     GMQ     GMc     GM     g
)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  rO  r[  ra  ru  Nrh  r   r   r  r#  r'  r,  r9  r2   )r  r
   r  r_  r   r   r!   r   rQ  r  r  r  rQ   r	  r
  r  r  r  r   rX   )ry   r  r  r  r   r9  r  rW  rv  r'  r,  r   r  r#  r   r   r!   r  r  r  r  r  rT   r  s                           r   0test_to_surface__surface_with_param_combinations=MaskTypeTest.test_to_surface__surface_with_param_combinationsO  sa     U+!<<1#\\&1<<(\\&)
..nE\\^
||~(),-  
 "D;;##D#4D &0$6 '7|$+7*>&-?F>*+3T*:-;z*1;T0B,3CF<0#LL7/3Tl
#-#5$*JJvt$<5?F6N#''7'C9I)7)C9A9F'9'E9K)9)E9C9F-1__-Fv-F
 $j' B'.w$($4$4(+
(CEW%& !%
0D0D0F0V W $ 0 0$.$:$:$<n!" !% 0 01D1D1F M 3D*n UC /;	 1C +; +? %7	 "r   c                 @  ^ [         R                  " S5      n[         R                  " S5      nS=u  nmn[         R                  R                  U5      nUR	                  5       n[         R
                  " U5      n[         R                  " S5      nU4S j[        U5       5        H  n	UR                  U	5        M     U R                   H  n
Xl	        UR                  U5        UR                  XzS9nUR                  5         U4S j[        U5       5        Hp  n	U	S   U
S   -
  U	S	   U
S	   -
  4nUR                  U	5      (       d  UnOUR                  U5      (       a  UnOUnU R                  UR                  U	5      XU	45        Mr     UR!                  5         M     g
)zvEnsures that to_surface works correctly with with set/unset bits
when using the defaults for setcolor and unsetcolor.
r  r  r  rs  r  c              3   Z   >#    U  H   n[        US -  TS5        H  o!U4v   M
     M"     g7fr   r	   Nr/  r3   r   r   r:   s      r   r7   CMaskTypeTest.test_to_surface__set_and_unset_bits.<locals>.<genexpr>  )     RLq%Avq:QQF:QFL   (+r  c              3   P   >#    U  H  n[        T5        H  o!U4v   M
     M     g 7frG   r/  r  s      r   r7   r         L1eFmAmr2  r   r   N)r
   r  r!   r   rO   r_  r   r   r?  r   r   r  rP   r\   r   rQ   rR   )ry   default_setcolorr;  r9   r   r!   rZ  r   r  rW   r9  r  mask_posrT   r:   s                 @r   #test_to_surface__set_and_unset_bits0MaskTypeTest.test_to_surface__set_and_unset_bits  sb    "<<0#\\'2''v{{%MMO	..&U+ SE%LRCKK S ''D $LL'<JOOLeLFT!W,c!ftAw.>? --c22%2N[[**%5N%7N  !2!23!7PSU M # (r   c                   ^ S=u  nmn[         R                  R                  U5      nUR                  5       n[         R                  " U5      n[         R
                  " S5      nUR                  5       n[         R
                  " S5      nUR                  U5        UR                  5       n	[         R
                  " S5      n
U	R                  U
5        U4S j[        U5       5        H  nUR                  U5        M     U R                   H  nXl        S H  nUR                  U5        U(       a  UR                  UUUU	SSS9nOUR                  UUUU	S	9nUR                  5         U4S
 j[        U5       5        Hn  nUS   US   -
  US   US   -
  4nUR                  U5      (       d  UnOUR                  U5      (       a  UnOU
nU R!                  UR                  U5      U5        Mp     UR#                  5         M     M     g)ziEnsures that to_surface works correctly with with set/unset bits
when using setsurface and unsetsurface.
r  r  ra  r[  c              3   Z   >#    U  H   n[        US -  TS5        H  o!U4v   M
     M"     g7fr  r/  r  s      r   r7   `MaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface.<locals>.<genexpr>  r  r  r   N)r9  r  r#  r'  r,  )r9  r  r#  c              3   P   >#    U  H  n[        T5        H  o!U4v   M
     M     g 7frG   r/  r  s      r   r7   r    s     PLq%-QF-FLr2  r   r   )r
   r!   r   rO   r_  r  r   r   r   r   r?  r   r  rP   r\   r   rQ   rR   )ry   r9   r   r!   rZ  r   r  r  rW  r#  rv  rW   r9  disable_color_paramsr  r  rT   r:   s                    @r   @test_to_surface__set_and_unset_bits_with_setsurface_unsetsurfaceMMaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface  s     ('v{{%MMO	..&U+\\^
!<<0()||~#\\&1,- SE%LRCKK S ''D $
 )6$]+'!%!#-%1!%#' "1 "J "&!#-%1	 "1 "J !PE%LPC #Aa 0#a&472BCH$11#66)6X..)9);$$Z%6%6s%;^L Q !!#C )6 (r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  U5        U(       a  UOUn	UR                  U5      n
U R                  X5        U R                  U
R                  5       U5        [        X
U	5        M     g)	zEnsures that surfaces narrower than the mask work correctly.

For this test the surface's width is less than the mask's width.
r  r  r     rs  r  r   r   Nr
   r  r_  r!   r   r   r  r  rQ   r   rX   )ry   r  r;  rY  narrow_sizer   r  r   r!   rT   r  s              r   +test_to_surface__surface_narrower_than_mask8MaskTypeTest.test_to_surface__surface_narrower_than_mask  s    
 "<<0#\\'2	..-U+!D;;##I#9DLL'15-;MN1JMM*.Z002K@.A "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
Xg5        [        X
X5        M  [        X
U5        M     g
)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  r  r  r   r  r   r   r  Nr
   r  r_  r  r   rO   r!   r   r  rx   rQ   r   rX   r^   )ry   r  r;  rY  r  r  rW  setsurface_rectr   r!   r  s              r   .test_to_surface__setsurface_narrower_than_mask;MaskTypeTest.test_to_surface__setsurface_narrower_than_mask$  s    
 "<<0#\\'2	^^K2>
!<<.()$--/!D;;##I#9DJ?J!!*fnn=Z002I> #D6FX-&6 $D6HI "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
U5        M  [        X
Xg5        [        X
X'5        M     g
)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  r  r  r   r  r   r   r#  Nr  )ry   r  r;  rY  r  r#  rv  unsetsurface_rectr   r!   r  s              r   0test_to_surface__unsetsurface_narrower_than_mask=MaskTypeTest.test_to_surface__unsetsurface_narrower_than_maskD  s    
 "<<0#\\'2	~~k8R@#\\%0,-(113!D;;##I#9DlCJ!!*fnn=Z002I> #D6FG#&8 .&8 "r   c                    SnSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X'S9nUR                  USSS	9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        U(       a  [        X	XV5        [        X	X5        M  [        X	U5        M     g)
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.
r8  r  r  r   r  r   r   Nr  r'  r,  r
   r_  r  r  r   rO   r!   r   r  rx   rQ   r   rX   r^   )
ry   r:  rY  r  r  rW  r  r   r!   r  s
             r   >test_to_surface__setsurface_narrower_than_mask_and_colors_noneKMaskTypeTest.test_to_surface__setsurface_narrower_than_mask_and_colors_nonef  s     !-	^^K2>
!<<.()$--/!D;;##I#9D% ) J !!*fnn=Z002I> #D6FX-&; $D6KL# "r   c                    SnSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X'S9nUR                  USSS	9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        U(       a  [        X	U5        M  [        X	XV5        [        X	X5        M     g)
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.
r8  r  r  r   r  r   r   Nr#  r'  r,  r  )
ry   r:  rY  r  r#  rv  r  r   r!   r  s
             r   @test_to_surface__unsetsurface_narrower_than_mask_and_colors_noneMMaskTypeTest.test_to_surface__unsetsurface_narrower_than_mask_and_colors_none  s     !-	~~k8R@#\\%0,-(113!D;;##I#9D)DT ) J !!*fnn=Z002I> #D6KL#&8 .&;# "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	zEnsures that surfaces wider than the mask work correctly.

For this test the surface's width is greater than the mask's width.
r  r  r     ru   r  r  r   r   Nr
   r  r_  r!   r   rO   r   r  r  rQ   r   rX   r^   )ry   r  r;  rY  	wide_sizer   r  r   r!   rZ  rT   r  s               r   (test_to_surface__surface_wider_than_mask5MaskTypeTest.test_to_surface__surface_wider_than_mask      
 "<<0#\\'2		..+U+!D;;##I#9DILL'15-;MN1JMM*.Z002I>.L)$MU "r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
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   r  Nr
   r  r_  r  r   r!   r   r  rx   rQ   r   rX   )
ry   r;  rY  r  r  rW  r   r!   rT   r  s
             r   +test_to_surface__setsurface_wider_than_mask8MaskTypeTest.test_to_surface__setsurface_wider_than_mask  s    
 $\\'2		^^Ix<
!<<.()!D;;##I#9D15-;MNJ?J!!*fnn=Z002I>.A "r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
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   r  Nr   )
ry   r  rY  r  r#  rv  r   r!   rT   r  s
             r   -test_to_surface__unsetsurface_wider_than_mask:MaskTypeTest.test_to_surface__unsetsurface_wider_than_mask       "<<0		~~i2>#\\%0,-!D;;##I#9D15-;MNlCJ!!*fnn=Z002I>.A "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  U5        U(       a  UOUn	UR                  U5      n
U R                  X5        U R                  U
R                  5       U5        [        X
U	5        M     g)	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  r  ru   r  r  r  r   r   Nr  )ry   r  r;  rY  
short_sizer   r  r   r!   rT   r  s              r   *test_to_surface__surface_shorter_than_mask7MaskTypeTest.test_to_surface__surface_shorter_than_mask  s    
 "<<0#\\'2	
..,U+!D;;##I#9DLL'15-;MN1JMM*.Z002J?.A "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
Xg5        [        X
X5        M  [        X
U5        M     g
)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  r  r	  r   r  r   r   r  Nr  )ry   r  r;  rY  r
  r  rW  r  r   r!   r  s              r   -test_to_surface__setsurface_shorter_than_mask:MaskTypeTest.test_to_surface__setsurface_shorter_than_mask  s    
 "<<0#\\'2	
^^J"=
!<<.()$--/!D;;##I#9DJ?J!!*fnn=Z002I> #D6FX-&6 $D6HI "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
U5        M  [        X
Xg5        [        X
X'5        M     g
)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  r  r	  r   r  r   r   r  Nr  )ry   r  r;  rY  r
  r#  rv  r  r   r!   r  s              r   /test_to_surface__unsetsurface_shorter_than_mask<MaskTypeTest.test_to_surface__unsetsurface_shorter_than_mask-  s    
 "<<0#\\'2	
~~j(B?#\\%0,-(113!D;;##I#9DlCJ!!*fnn=Z002I> #D6FG#&8 .&8 "r   c                    SnSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X'S9nUR                  USSS	9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        U(       a  [        X	XV5        [        X	X5        M  [        X	U5        M     g)
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.
r8  r  r	  r   r  r   r   Nr  r  )
ry   r:  rY  r
  r  rW  r  r   r!   r  s
             r   =test_to_surface__setsurface_shorter_than_mask_and_colors_noneJMaskTypeTest.test_to_surface__setsurface_shorter_than_mask_and_colors_noneO  s     !-	
^^J"=
!<<.()$--/!D;;##I#9D% ) J !!*fnn=Z002I> #D6FX-&; $D6KL# "r   c                    SnSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X'S9nUR                  USSS	9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        U(       a  [        X	U5        M  [        X	XV5        [        X	X5        M     g)
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.
r8  r  r	  r   r  r   r   Nr  r  )
ry   r:  rY  r
  r#  rv  r  r   r!   r  s
             r   ?test_to_surface__unsetsurface_shorter_than_mask_and_colors_noneLMaskTypeTest.test_to_surface__unsetsurface_shorter_than_mask_and_colors_noneq  s     !-	
~~j(B?#\\%0,-(113!D;;##I#9D)DT ) J !!*fnn=Z002I> #D6KL#&8 .&;# "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	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  r	  r  r  r   r   Nr  )ry   r  r;  rY  	tall_sizer   r  r   r!   rZ  rT   r  s               r   )test_to_surface__surface_taller_than_mask6MaskTypeTest.test_to_surface__surface_taller_than_mask  r  r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
zEnsures that setsurfaces taller than the mask work correctly.

For this test the setsurface's height is greater than the mask's
height.
r  r	  r  r   r  r   r   r  Nr   )
ry   r;  rY  r  r  rW  r   r!   rT   r  s
             r   ,test_to_surface__setsurface_taller_than_mask9MaskTypeTest.test_to_surface__setsurface_taller_than_mask  s     $\\'2		^^Ix<
!<<.()!D;;##I#9D15-;MNJ?J!!*fnn=Z002I>.A "r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
zEnsures that unsetsurfaces taller than the mask work correctly.

For this test the unsetsurface's height is greater than the mask's
height.
r  r	  r  r   r  r   r   r  Nr   )
ry   r  rY  r  r#  rv  r   r!   rT   r  s
             r   .test_to_surface__unsetsurface_taller_than_mask;MaskTypeTest.test_to_surface__unsetsurface_taller_than_mask  r  r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	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  r     r  r  r   r   Nr  )ry   r  r;  rY  wide_tall_sizer   r  r   r!   rZ  rT   r  s               r   3test_to_surface__surface_wider_and_taller_than_mask@MaskTypeTest.test_to_surface__surface_wider_and_taller_than_mask  s     "<<0#\\'2	!..0U+!D;;##I#9DILL'15-;MN1JMM*.Z002NC.L)$MU "r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
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   r  Nr   )
ry   r;  rY  r&  r  rW  r   r!   rT   r  s
             r   6test_to_surface__setsurface_wider_and_taller_than_maskCMaskTypeTest.test_to_surface__setsurface_wider_and_taller_than_mask  s     $\\'2	!^^NHbA
!<<.()!D;;##I#9D15-;MNJ?J!!*fnn=Z002I>.A "r   c                    [         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        S H  n[         R
                  R                  X&S9nU(       a  UOUnUR                  US9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g	)
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   r  Nr   )
ry   r  rY  r&  r#  rv  r   r!   rT   r  s
             r   8test_to_surface__unsetsurface_wider_and_taller_than_maskEMaskTypeTest.test_to_surface__unsetsurface_wider_and_taller_than_mask  s     "<<0	!~~nhC#\\%0,-!D;;##I#9D15-;MNlCJ!!*fnn=Z002I>.A "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	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   r  r  r   r   Nr  )ry   r  r;  rY  wide_short_sizer   r  r   r!   rZ  rT   r  s               r   4test_to_surface__surface_wider_and_shorter_than_maskAMaskTypeTest.test_to_surface__surface_wider_and_shorter_than_mask,  s     "<<0#\\'2	!..1U+!D;;##I#9DILL'15-;MN1JMM*.Z002OD.L)$MU "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
Xg5        [        X
X5        M  [        X
U5        M     g
)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  r	  r   r  r   r   r  Nr  )ry   r  r;  rY  r0  r  rW  r  r   r!   r  s              r   7test_to_surface__setsurface_wider_and_shorter_than_maskDMaskTypeTest.test_to_surface__setsurface_wider_and_shorter_than_maskH  s     "<<0#\\'2	!^^OXrB
!<<.()$--/!D;;##I#9DJ?J!!*fnn=Z002I> #D6FX-&6 $D6HI "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
U5        M  [        X
Xg5        [        X
X'5        M     g
)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  r	  r   r  r   r   r  Nr  )ry   r  r;  rY  r0  r#  rv  r  r   r!   r  s              r   9test_to_surface__unsetsurface_wider_and_shorter_than_maskFMaskTypeTest.test_to_surface__unsetsurface_wider_and_shorter_than_maskj  s     "<<0#\\'2	!~~oxD#\\%0,-(113!D;;##I#9DlCJ!!*fnn=Z002I> #D6FG#&8 .&8 "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	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  r  r%  r  r  r   r   Nr  )ry   r  r;  rY  narrow_tall_sizer   r  r   r!   rZ  rT   r  s               r   6test_to_surface__surface_narrower_and_taller_than_maskCMaskTypeTest.test_to_surface__surface_narrower_and_taller_than_mask  s     "<<0#\\'2	"..!12U+!D;;##I#9DILL'15-;MN1JMM*.Z0024DE.L)$MU "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
Xg5        [        X
X5        M  [        X
U5        M     g
)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   r  Nr  )ry   r  r;  rY  r;  r  rW  r  r   r!   r  s              r   9test_to_surface__setsurface_narrower_and_taller_than_maskFMaskTypeTest.test_to_surface__setsurface_narrower_and_taller_than_mask  s     "<<0#\\'2	"^^$4hC
!<<.()$--/!D;;##I#9DJ?J!!*fnn=Z002I> #D6FX-&6 $D6HI "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
U5        M  [        X
Xg5        [        X
X'5        M     g
)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   r  Nr  )ry   r  r;  rY  r;  r#  rv  r  r   r!   r  s              r   ;test_to_surface__unsetsurface_narrower_and_taller_than_maskHMaskTypeTest.test_to_surface__unsetsurface_narrower_and_taller_than_mask  s     "<<0#\\'2	"~~&6"E#\\%0,-(113!D;;##I#9DlCJ!!*fnn=Z002I> #D6FG#&8 .&8 "r   c                    [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U5      n[         R                  " S5      nS H  n[         R                  R	                  X7S9nUR                  5       n	UR                  U5        U(       a  UOUn
UR                  U5      nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        M     g)	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  r     r  r  r   r   Nr  )ry   r  r;  rY  narrow_short_sizer   r  r   r!   rZ  rT   r  s               r   7test_to_surface__surface_narrower_and_shorter_than_maskDMaskTypeTest.test_to_surface__surface_narrower_and_shorter_than_mask  s     "<<0#\\'2	#..!23U+!D;;##I#9DILL'15-;MN1JMM*.Z0024EF.L)$MU "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
Xg5        [        X
X5        M  [        X
U5        M     g
)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  rE  r  r   r  r   r   r  Nr  )ry   r  r;  rY  rG  r  rW  r  r   r!   r  s              r   :test_to_surface__setsurface_narrower_and_shorter_than_maskGMaskTypeTest.test_to_surface__setsurface_narrower_and_shorter_than_mask  s     "<<0#\\'2	#^^$5xD
!<<.()$--/!D;;##I#9DJ?J!!*fnn=Z002I> #D6FX-&6 $D6HI "r   c                 N   [         R                  " S5      n[         R                  " S5      nSnSn[         R                  " U[        S5      n[         R                  " S5      nUR	                  U5        UR                  5       nS H  n[         R                  R                  X8S9n	U	R                  US	9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        U(       a  [        X
U5        M  [        X
Xg5        [        X
X'5        M     g
)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  rE  r  r   r  r   r   r  Nr  )ry   r  r;  rY  rG  r#  rv  r  r   r!   r  s              r   <test_to_surface__unsetsurface_narrower_and_shorter_than_maskIMaskTypeTest.test_to_surface__unsetsurface_narrower_and_shorter_than_mask.  s     "<<0#\\'2	#~~&72F#\\%0,-(113!D;;##I#9DlCJ!!*fnn=Z002I> #D6FG#&8 .&8 "r   c                   ^^ [         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nSnSnSnS	n	[         R                  " U5      n
[         R                  " U5      n[         R                  " U	5      nU
R                  U5        UR                  U5        UR                  U5        U
R	                  5       mUR	                  5       nUR	                  5       n[         R
                  R                  US
S9nUR	                  5       n[         R                  " SS5      mUR                  Tl        U4S j[        TR                  TR                  5       5        H  nUR                  US5        M     UR                  XU5      nU R                  UU
5        U R                  UR!                  5       U5        UR#                  5         U4S j[        TR                  5       5        H  nUR%                  U5      (       d  UnOMUR'                  U5      (       a  UR%                  U5      (       a  UnOUnOUR%                  U5      (       a  UnOUnU R                  UR'                  U5      U5        M     UR)                  5         g)zBEnsures that all the surface parameters can be of different sizes.r  r  r  ra  r[  )r  r  )ru      )r  r%  )ru     Tr   r/   r   c              3   z   >#    U  H0  n[        TR                  TR                  5        H  nX4v   M
     M2     g 7frG   )r   r   r   )r3   r   r   unfilled_rects      r   r7   WMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_mask.<locals>.<genexpr>r  s6      
<=??MOO< F< <s   8;r   c              3   d   >#    U  H%  n[        TR                  5        H  o!U4v   M
     M'     g 7frG   )r   r   )r3   r   r   surface_rects      r   r7   rU    s)      
1q5;PaF;PF1s   -0N)r
   r  r_  r   rO   r!   r   r'   r   r   r   r   r   r  r  rQ   r   rP   r\   r   rR   )ry   r  r;  r  rW  rv  rY  surface_sizesetsurface_sizeunsetsurface_sizer   r  r#  r  r  r!   rZ  rW   r  rT   rW  rT  s                       @@r   7test_to_surface__all_surfaces_different_sizes_than_maskDMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_maskR  sC    "<<0#\\'2U+!<<0#\\&1	 $...^^O4
~~&78]#(),-'')$--/(113 {{	5MMO	FF3(//
=??MOO<
C
 KKQ
 __W,G
j'*,,.= 	
!,..1
C ))#..!.S!!"//44%5N%5N %11#66%7N%7NZ..s3^D%
( 	r   c           	         Sn[         R                  " X45      nUR                  5       nUR                  5       n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nS [        U* US-   5       5       S [        U* US-   5       5       S [        U* US-   5       5       S	 [        U* US-   5       5       4nS
 H  n	[         R                  R                  X4U	S9n
U	(       a  UOUnU H[  nU HR  nXl        UR                  U5      nUR                  U5        U
R                  X$S9n[        XX5        [        XX^5        MT     M]     M     g)zBEnsures dest values can be different locations on/off the surface.r   r  r  r  c              3   (   #    U  H  oS 4v   M
     g7fr1   r2   r3   ss     r   r7   ?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>       43V3   r   c              3   *   #    U  H	  nS U4v   M     g7fr1   r2   r_  s     r   r7   ra         43aV3   c              3   (   #    U  H  oU4v   M
     g 7frG   r2   r_  s     r   r7   ra    rb  rc  c              3   *   #    U  H	  o* U4v   M     g 7frG   r2   r_  s     r   r7   ra         54b!W4rf  r   r   r  N)r
   r_  rO   r   r  r   r!   r   r   rN   r   r  rX   r^   )ry   SIDEr   rW  	dest_rectr  r  r;  
directionsr   r!   rT   	directionrW   rq  r  s                   r   test_to_surface__dest_locations,MaskTypeTest.test_to_surface__dest_locations  sI   ..$.'') %%'	U+!<<0#\\'2 5UD5$(344UD5$(344UD5$(345eTE4!845	

 "D;;##TLt#<D15-;MN'	$C(+%#,>>,#?LLL/!%!IJ'.W1- % (	 "r   c           	         Sn[         R                  " X45      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nS [        U* US-   5       5       S [        U* US-   5       5       S [        U* US-   5       5       S	 [        U* US-   5       5       4nS
 H  n[         R                  R                  X4US9nUR                  5       n	U	R                  5       n
U(       a  UOUnU Hb  nU HY  nXl        U
R                  U	5      nSUl        UR                  U5        UR                  X*S9n[        XX5        [        XX>5        M[     Md     M     g)z>Ensures area rects can be different locations on/off the mask.r   r  r  r  c              3   (   #    U  H  oS 4v   M
     g7fr1   r2   r_  s     r   r7   ?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>  rb  rc  r   c              3   *   #    U  H	  nS U4v   M     g7fr1   r2   r_  s     r   r7   rr    re  rf  c              3   (   #    U  H  oU4v   M
     g 7frG   r2   r_  s     r   r7   rr    rb  rc  c              3   *   #    U  H	  o* U4v   M     g 7frG   r2   r_  s     r   r7   rr    ri  rf  r   r   r/   r  N)r
   r_  r  r   r!   r   rO   r   r   rN   r   r  rX   r^   )ry   rj  r   r  r  r;  rl  r   r!   rZ  rU   rT   rm  rW   rq  r  s                   r   test_to_surface__area_locations,MaskTypeTest.test_to_surface__area_locations  sN    ..$.U+!<<0#\\'2 5UD5$(344UD5$(344UD5$(345eTE4!845	

 "D;;##TLt#<DI!(I15-;MN'	$C(+%#,>>)#<L+1L(LL/!%!IJ'.W1- % ( "r   c           
         Sn[         R                  " X45      nUR                  5       nUR                  5       n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nS [        U* US-   5       5       S [        U* US-   5       5       S [        U* US-   5       5       S	 [        U* US-   5       5       4n[        US
   5      n	S H  n
[         R                  R                  X4U
S9nUR                  5       nUR                  5       nU
(       a  UOUnU H  nU H  nUUl	        U	 Hz  nUUl	        UR                  U5      nUR                  Ul	        UR                  U5      nUR                  U5        UR                  X$US9n[        U UUU5        [        U UUU5        M|     M     M     M     g)zMEnsures dest/area values can be different locations on/off the
surface/mask.
r   r  r  r  c              3   (   #    U  H  oS 4v   M
     g7fr1   r2   r_  s     r   r7   HMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>  rb  rc  r   c              3   *   #    U  H	  nS U4v   M     g7fr1   r2   r_  s     r   r7   rz    re  rf  c              3   (   #    U  H  oU4v   M
     g 7frG   r2   r_  s     r   r7   rz    rb  rc  c              3   *   #    U  H	  o* U4v   M     g 7frG   r2   r_  s     r   r7   rz    ri  rf  r	   r   r   )r9  rF  N)r
   r_  rO   r   r  r   r  r!   r   r   rN   r   r  rX   r^   )ry   rj  r   rW  rk  r  r  r;  dest_directionsarea_positionsr   r!   rZ  rU   rT   dest_directiondest_posr  area_overlap_rectdest_overlap_rectr  s                        r   (test_to_surface__dest_and_area_locations5MaskTypeTest.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;;##TLt#<DI!(I15-;MN"1 .H(0I%$2,4	),5NN9,E)4=4E4E)1,5NN;L,M)]3%)__#) &5 &
 , *n>O 6 *m=N %3 !/ #2 "r   c                    SnSSSSUS-
  US-
  4US-
  U4XS-
  4X4US-   U4XS-   4US-   US-   44n[         R                  " X45      n[         R                  " S5      n[         R                  " S5      n[         R                  " S	5      nS
 H  n[         R                  R	                  X4US9nUR                  5       n	U(       a  UOUn
U H  n[         R                  " SU5      nU R                   HY  nXl        UR                  U	5      nSUl        UR                  U5        UR                  X<S9n[        XX5        [        XXN5        M[     M     M     g)z*Ensures area rects can be different sizes.r   r/   rj   rl   rk   r   r  r  r  r   r   r  N)r
   r_  r  r!   r   rO   r'   r?  r   rN   r   r  rX   r^   )ry   rj  SIZESr   r  r  r;  r   r!   rZ  rT   r   rU   rW   rq  r  s                   r   test_to_surface__area_sizes(MaskTypeTest.test_to_surface__area_sizes  s_    AXtax AXt!8LAXt!8AXtax 
 ..$.U+!<<0#\\'2!D;;##TLt#<DI15-;MN"KK5	..C(+%#,>>)#<L+1L(LL/!%!IJ'.W1- /  "r   c                 @   Sn[         R                  " S5      nSUl        [         R                  " S5      nSUl        [         R                  " U[        SS9n[         R                  " U[        SS9nUR                  U5        UR                  U5        S H  n[         R                  R                  XS	9nU(       a  UOUnUR                  XES
9n	U R                  U	[         R                  5        U R                  U	R                  5       U5        [        X	U5        M     g)zEEnsures the setsurface/unsetsurface color alpha values are respected.r  ra  5   r[  r  r   flagsdepthr   r   r  r#  N)r
   r  r4   r_  r  r   r!   r   r  rx   rQ   r   rX   )
ry   r   rW  rv  r  r#  r   r!   rT   r  s
             r   %test_to_surface__surface_color_alphas2MaskTypeTest.test_to_surface__surface_color_alphasB  s    !<<0#\\&1"^^DC
~~d("E(),-!D;;##D#4D15-;MN% ) J !!*fnn=Z002D9.A "r   c                    Sn[         R                  " S5      nSUl        [         R                  " S5      nSUl        S H  n[         R                  R	                  XS9nU(       a  UOUnUR                  X#S9nU R                  U[         R                  5        U R                  UR                  5       U5        [        XU5        M     g	)
z;Ensures the setcolor/unsetcolor alpha values are respected.r  ra  #   r[     r   r   )r'  r,  N)r
   r  r4   r!   r   r  rx   r_  rQ   r   rX   )ry   r   r'  r,  r   r!   rT   r  s           r   test_to_surface__color_alphas*MaskTypeTest.test_to_surface__color_alphas\  s    <<(
\\&)

!D;;##D#4D)-X:N(RJ!!*fnn=Z002D9.A "r   c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nS GH   n[         R                  " XS9n[         R                  " XS9n[         R                  " XS9nUR                  U5        UR                  U5        UR                  U5        S H  n	[         R                  R                  XS9n
U	(       a  UR                  S	5      OUR                  S	5      nU
R                  XgU5      nU R                  U[         R                  5        U R                  UR                  5       U5        [        XU5        M     GM#     g
)zAEnsures to_surface works correctly with supported surface depths.r  r  ra  r[  r%  rR     r   r  r   r   r/   N)r
   r  r_  r   r!   r   r   r  rx   rQ   r   rX   )ry   r   r  rW  rv  r  r   r  r#  r   r!   rT   r  s                r   test_to_surface__depths$MaskTypeTest.test_to_surface__depthsn  s   U+!<<0#\\&1$EnnT7G:J!>>$<LLL'OO,-01%{{'''8
 26J%%f-<;N;Nv;V  "__W,O
%%j&..A  !4!4!6=#DnE & %r   c                 T   Sn[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  R                  U5      nSnU H  n[         R                  " XS   S9n[         R                  " XS   S9n	[         R                  " XS	   S9n
UR                  U5        U	R                  U5        U
R                  U5        U R                  [        5         UR                  XU
5        S
S
S
5        M     g
! , (       d  f       M  = f)zCEnsures an exception is raised when surfaces have different depths.r  r  ra  r[  )	)r%  r%  rR  )r%  r%  r  )r%  r%  r   )rR  rR  r  )rR  rR  r   )r  rR  r%  )r   rR  rR  )r   r   rR  )r   r  r   r   r  r   r	   N	r
   r  r!   r   r_  r   r   r   r  )ry   r   r  rW  rv  r!   test_depthsdepthsr   r  r#  s              r   !test_to_surface__different_depths.MaskTypeTest.test_to_surface__different_depths  s    U+!<<0#\\&1{{%

 "FnnT;G1I>J!>>$Qi@LLL'OO,-01"":.\B /. " /.s   8D
D'	c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  R                  U5      nSnU H|  u  pg[         R                  " XS9n[         R                  " XS9n	UR                  U5        U	R                  U5        U R                  [        5         UR                  XS9  SSS5        M~     g! , (       d  f       M  = f)z]Ensures an exception is raised when surfaces have different depths
than the created surface.
r  ra  r[  ))r%  r%  )rR  rR  )r  r  )r  rR  )r   r%  )r   rR  )r   r  rR  r   r  r  Nr  )
ry   r   rW  rv  r!   r  	set_depthunset_depthr  r#  s
             r   7test_to_surface__different_depths_with_created_surfacesDMaskTypeTest.test_to_surface__different_depths_with_created_surfaces  s     !<<0#\\&1{{%	
 '2"I>J!>>$BLOO,-01"":.:Q /. '2 /.s   6C
C"	c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " S5      nS GHA  nS[        4 GH0  n[         R                  " XUS9n[         R                  " XUS9n[         R                  " XUS9n	UR	                  U5        UR	                  U5        U	R	                  U5        S H  n
[         R
                  R                  XS	9nU
(       a  UOUnUR                  XxU	5      nU R                  U[         R                  5        U R                  UR                  5       U5        [        XU5        U(       d  M  U R                  UR                  5       U-  5        M     GM3     GMD     g
)zHEnsures to_surface works correctly when the SRCALPHA flag is set or not.r  r  ra  r[  r  r   r  r   r   Nr
   r  r  r_  r   r!   r   r  rx   rQ   r   rX   r  r  )ry   r   r  rW  rv  r  r  r   r  r#  r   r!   rT   r  s                 r   test_to_surface__same_srcalphas,MaskTypeTest.test_to_surface__same_srcalphas  s5   U+!<<0#\\&1EX ..%H#^^DUK
%~~duM]+ 01!!"45)D!;;++D+<D9=%5CUN!%l!SJ))*fnnE$$Z%8%8%:DA'.Iu
(<(<(>(FG * ' r   c                 `   Sn[         R                  " S5      n[         R                  " S5      n[        n[         R                  " XSS9n[         R                  " XSS9nUR	                  U5        UR	                  U5        S H  n[         R
                  R                  XS9nU(       a  UOUn	UR                  XVS9n
U R                  U
[         R                  5        U R                  U
R                  5       U5        [        X
U	5        U R                  U
R                  5       U-  5        M     g	)
zEnsures to_surface works correctly when it creates a surface
and the SRCALPHA flag is set on both setsurface and unsetsurface.
r  ra  r[  r   r  r   r   r  Nr  )ry   r   rW  rv  expected_flagsr  r#  r   r!   rT   r  s              r   5test_to_surface__same_srcalphas_with_created_surfacesBMaskTypeTest.test_to_surface__same_srcalphas_with_created_surfaces  s     !<<0#\\&1!^^DbI
~~dK(),-!D;;##D#4D15-;MN% ) J !!*fnn=Z002D9.AOOJ002^CD "r   c                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  R                  U5      n[        SS4[        [        S4S[        [        4SS[        44nS H  nU H  n[         R
                  " XS   US9n	[         R
                  " XS   US9n
[         R
                  " XS	   US9nU	R                  U5        U
R                  U5        UR                  U5        U R                  [        5         UR                  XU5        S
S
S
5        M     M     g
! , (       d  f       M  = f)zTEnsures an exception is raised when surfaces have different SRCALPHA
flag settings.
r  r  ra  r[  r   r  r  r   r	   N
r
   r  r!   r   r  r_  r   r   r   r  )ry   r   r  rW  rv  r!   
test_flagsr  r  r   r  r#  s               r   $test_to_surface__different_srcalphas1MaskTypeTest.test_to_surface__different_srcalphas  s!    U+!<<0#\\&1{{% q!x#(#8	

 E# ..1XUK#^^DaN
%~~d(%P]+ 01!!"45&&z2OOGF 32 $  32s   (E
Ec                    Sn[         R                  " S5      n[         R                  " S5      n[         R                  R                  U5      nS H  nS[        S4S[        44 H  n[         R
                  " XS   US9n[         R
                  " XS   US9nUR                  U5        UR                  U5        U R                  [        5         UR                  XxS	9  S
S
S
5        M     M     g
! , (       d  f       M  = f)zmEnsures an exception is raised when surfaces have different SRCALPHA
flag settings than the created surface.
r  ra  r[  r  r/   r   r  r   r  Nr  )	ry   r   rW  rv  r!   r  r  r  r#  s	            r   :test_to_surface__different_srcalphas_with_created_surfacesGMaskTypeTest.test_to_surface__different_srcalphas_with_created_surfaces'  s     !<<0#\\&1{{%E !8Q-!X?#^^DaN
%~~d(%P 01!!"45&&z2OOzOU 32 @  32s   C//
C>c                 f  ^ [         R                  " S5      n[         R                  " S5      nS=u  mp4[         R                  " U[        S5      n[         R                  " S5      nS H  n[         R                  R                  XGS9nUR                  5       n	U(       a  UOUn
U4S j[        U5       5        Hr  nUR                  U5        Xl	        UR                  X[S	9nU R                  X5        U R                  UR                  5       U5        [        XX5        [        XXi5        Mt     M     g
)zgEnsures dest values on the surface work correctly
when using the defaults for setcolor and unsetcolor.
r  r  r   r  r   r  r   r   c              3   P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7frG   r/  r0  s      r   r7   @MaskTypeTest.test_to_surface__dest_on_surface.<locals>.<genexpr>M       MAe1Qr2  r  N)r
   r  r_  r  r!   r   rO   r   r   r   r  r  rQ   r   rX   r^   )ry   r  r;  r:   r   r   r  r   r!   rZ  rT   r9  r  r9   s                @r    test_to_surface__dest_on_surface-MaskTypeTest.test_to_surface__dest_on_surface=  s     "<<0#\\'2%%v..x4U+!D;;##D#4DI15-;MN NvM]+$(!!__W_@
j2  !4!4!6=#DnP-m N "r   c           	      n  ^ S=u  mp[         R                  " U[        S5      n[         R                  " S5      nUR	                  5       n[         R                  " S5      nUR                  U5        UR	                  5       n[         R                  " S5      nUR                  U5        UUUSS.n	[        U	5      n
U
R                  S5        S	 H  n[         R                  R                  X+S
9nUR                  5       nU(       a  UOUnU4S j[        U5       5        H  nXl        S	 H  nUR                  U5        U(       a  U
OU	nUUS'   UR                  " S0 UD6nU R                  UU5        U R                  UR!                  5       U5        [#        U UX5        [%        U UXM5        M     M     M     g)zZEnsures dest values on the surface work correctly
when using setsurface and unsetsurface.
r  r   r  ra  r[  Nr   r  r#  r9  )r'  N)r,  Nr   r   c              3   P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7frG   r/  r0  s      r   r7   ]MaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurface.<locals>.<genexpr>|  r  r2  r9  r2   )r
   r_  r  r  r   r   rP  updater!   r   rO   r   r   r  r  rQ   r   rX   r^   )ry   r:   r   r   r  r  rW  r#  rv  r   color_kwargsr   r!   rZ  rT   r9  use_color_paramstest_kwargsr  r9   s                      @r   =test_to_surface__dest_on_surface_with_setsurface_unsetsurfaceJMaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurfaceZ  s     &%v..x4U+\\^
!<<0()||~#\\&1,-
 $(	
 F|FG!D;;##D#4DI15-;MN NvM$(!(5$LL/2B,K*.K'!%!?;!?JMM*g6$$Z%8%8%:DA'j.T1j- )6 N "r   c                    [         R                  " S5      n[         R                  " S5      nS=u  p4n[         R                  " U[        S5      n[         R                  " S5      nU* U* 4U* S4SU* 4/nUR	                  [        UR                  5       5      5        S H  n	[         R                  R                  XYS9n
U
R                  5       nU	(       a  UOUnU Hr  nUR                  U5        Xl
        U
R                  XmS	9nU R                  X5        U R                  UR                  5       U5        [        XX5        [!        XX{5        Mt     M     g
)zhEnsures 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  extendrD   rO   r!   r   r   r   r  r  rQ   r   rX   r^   )ry   r  r;  r9   r:   r   r   r  r  r   r!   rZ  rT   r9  r  s                  r   !test_to_surface__dest_off_surface.MaskTypeTest.test_to_surface__dest_off_surface  s*    "<<0#\\'2%%..x4U+ &6'"eVQK!fW>[!1!1!345!D;;##D#4DI15-;MN]+$(!!__W_@
j2  !4!4!6=#DnP-m  "r   c           	         S=u  pn[         R                  " U[        S5      n[         R                  " S5      nUR	                  5       n[         R                  " S5      nUR                  U5        UR	                  5       n[         R                  " S5      n	UR                  U	5        U* U* 4U* S4SU* 4/n
U
R                  [        UR                  5       5      5        UUUSS.n[        U5      nUR                  S	5        S
 H  n[         R                  R                  X=S9nUR                  5       nU(       a  UOU	nU
 H  nUUl        S
 H  nUR                  U5        U(       a  UOUnUUS'   UR                  " S0 UD6nU R                  UU5        U R!                  UR#                  5       U5        [%        U UUU5        ['        U UX_5        M     M     M     g)z[Ensures dest values off the surface work correctly
when using setsurface and unsetsurface.
r  r   r  ra  r[  r   Nr  r  r   r   r9  r2   )r
   r_  r  r  r   r   r  rD   rO   rP  r  r!   r   r   r  r  rQ   r   rX   r^   )ry   r9   r:   r   r   r  r  rW  r#  rv  r  r   r  r   r!   rZ  rT   r9  r  r  r  s                        r   >test_to_surface__dest_off_surface_with_setsurface_unsetsurfaceKMaskTypeTest.test_to_surface__dest_off_surface_with_setsurface_unsetsurface  s     &%..x4U+\\^
!<<0()||~#\\&1,- &6'"eVQK!fW>[!1!1!345
 $(	
 F|FG!D;;##D#4DI15-;MN$(	!(5$LL/2B,K*.K'!%!?;!?JMM*g6$$Z%8%8%:DA'j.)T1j- )6  "r   c                   ^ [         R                  " S5      n[         R                  " S5      nS=u  mp4[         R                  " U[        S5      n[         R                  " S5      nS H  n[         R                  R                  XGS9nUR                  5       n	U	R                  5       n
U(       a  UOUnU4S j[        U5       5        H  nUR                  U5        Xl
        U	R                  U
5      nS	Ul
        UR                  XZS
9nU R                  X5        U R                  UR                  5       U5        [!        XX5        [#        XXm5        M     M     g)zdEnsures area values on the mask work correctly
when using the defaults for setcolor and unsetcolor.
r  r  r  r   r  r   r   c              3   P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7frG   r/  r0  s      r   r7   =MaskTypeTest.test_to_surface__area_on_mask.<locals>.<genexpr>       L1uU|!A|r2  r/   r  N)r
   r  r_  r  r!   r   rO   r   r   r   r   rN   r  r  rQ   r   rX   r^   )ry   r  r;  r:   r   r   r  r   r!   rZ  rU   rT   rW   rq  r  r9   s                  @r   test_to_surface__area_on_mask*MaskTypeTest.test_to_surface__area_on_mask  s    "<<0#\\'2%%v..x4U+!D;;##D#4DI!(I15-;MN MfL]+$'!(~~i8'-$!__W_E
j2  !4!4!6=#DnS-m M "r   c           	      2  ^ S=u  mp[         R                  " U[        S5      n[         R                  " S5      nUR	                  5       n[         R                  " S5      nUR                  U5        UR	                  5       n[         R                  " S5      nUR                  U5        UUU[         R                  " SU5      S.n	[        U	5      n
U
R                  S5        S	 GH1  n[         R                  R                  X+S
9nUR                  5       nUR	                  5       nU(       a  UOUnU4S j[        U5       5        H  nUUl        UR                  U5      nSUl        S	 H  nUR                  U5        U(       a  U
OU	nUUS   l        UR                  US   5      nSUl        UR                  " S0 UD6nU R!                  UU5        U R#                  UR%                  5       U5        ['        U UUU5        [)        U UUU5        M     M     GM4     g)zWEnsures area values on the mask work correctly
when using setsurface and unsetsurface.
r  r   r  ra  r[  r/   r   r  r#  rF  r  r   r   c              3   P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7frG   r/  r0  s      r   r7   ZMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurface.<locals>.<genexpr>(  r  r2  rF  Nr2   )r
   r_  r  r  r   r   r'   rP  r  r!   r   rO   r   r   rN   r  r  rQ   r   rX   r^   )ry   r:   r   r   r  r  rW  r#  rv  r   r  r   r!   rZ  rU   rT   rW   rq  r  r  r  r9   s                        @r   :test_to_surface__area_on_mask_with_setsurface_unsetsurfaceGMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurface  s   
  &%v..x4U+\\^
!<<0()||~#\\&1,-
 $(KK-	
 F|FG!D;;##D#4DI!(I15-;MN MfL$'	!(~~i8'-$(5$LL/2B,K25K'/#,>>+f2E#FL+1L(!%!?;!?JMM*g6$$Z%8%8%:DA'j.,W1j- )6 M "r   c           	         [         R                  " S5      n[         R                  " S5      nS=u  p4n[         R                  " U[        S5      n[         R                  " S5      nU* U* 4U* S4SU* 4/nUR	                  [        [         R                  " SX445      5      5        S H  n	[         R                  R                  XYS	9n
U
R                  5       nUR                  5       nU	(       a  UOUnU H  nUR                  U5        Xl        UR                  U5      nSUl        U
R                  XlS
9nU R                  UU5        U R!                  UR#                  5       U5        [%        U UX5        ['        U UX5        M     M     g)zeEnsures 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  rD   r'   r!   r   rO   r   r   r   rN   r  r  rQ   r   rX   r^   )ry   r  r;  r9   r:   r   r   r  	positionsr   r!   rZ  rU   rT   rW   rq  r  s                    r   test_to_surface__area_off_mask+MaskTypeTest.test_to_surface__area_off_mask=  sX    "<<0#\\'2%%..x4U+ fvg&%a&\B	V[[%%IJK!D;;##D#4DI!(I15-;MN ]+$'!(~~i8'-$!__W_E
j'2  !4!4!6=#D*nS-*m ! "r   c           	      &   S=u  pn[         R                  " U[        S5      n[         R                  " S5      nUR	                  5       n[         R                  " S5      nUR                  U5        UR	                  5       n[         R                  " S5      n	UR                  U	5        U* U* 4U* S4SU* 4/n
U
R                  [        [         R                  " SX45      5      5        UUU[         R                  " SU5      S.n[        U5      nUR                  S	5        S
 H  n[         R                  R                  X=S9nUR                  5       nU(       a  UOU	nU
 H  nS
 H  nUR                  U5        U(       a  UOUnUUS   l        UR                  US   5      nSUl        UR                   " S0 UD6nU R#                  UU5        U R%                  UR'                  5       U5        [)        U UUU5        [+        U UUU5        M     M     M     g)zXEnsures area values off the mask work correctly
when using setsurface and unsetsurface.
r  r   r  ra  r[  r   r/   r  r  r   r   rF  Nr2   )r
   r_  r  r  r   r   r  rD   r'   rP  r  r!   r   rO   r   rN   r  r  rQ   r   rX   r^   )ry   r9   r:   r   r   r  r  rW  r#  rv  r  r   r  r   r!   rZ  rT   rW   r  r  rq  r  s                         r   ;test_to_surface__area_off_mask_with_setsurface_unsetsurfaceHMaskTypeTest.test_to_surface__area_off_mask_with_setsurface_unsetsurfaceb  s     &%..x4U+\\^
!<<0()||~#\\&1,- fvg&%a&\B	V[[%%IJK
 $(KK-	
 F|FG!D;;##D#4DI15-;MN (5$LL/2B,K25K'/#,>>+f2E#FL+1L(!%!?;!?JMM*g6$$Z%8%8%:DA'j.,W1j- )6 ! "r   c                 Z   SnSn[         R                  " U5      n[         R                  R                  SSS9nUR	                  U5      nU R                  XS5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR                  5       U5        g)z2Ensures zero sized surfaces are handled correctly.r   r/   r   r   Tr   N)r
   r_  r!   r   r  r  r  rQ   r	  r
  r   )ry   r  r   r   r!   r  s         r   'test_to_surface__surface_with_zero_size4MaskTypeTest.test_to_surface__surface_with_zero_size  s    ..&{{T2__W-
j*wS__Z8:LM,,.5r   c                 N   Sn[         nSn[        R                  " S5      nSn[        R                  R	                  USS9n[        R
                  " SX#5      nUR                  US9nU R                  U[        R
                  5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR                  5       U-  5        U R                  UR                  5       U5        U R                  UR                  5       U5        [!        XU5        g	)
z5Ensures zero sized setsurfaces are handled correctly.r	   r   r  r	   r   Tr   r/   r  Nr  r
   r  r!   r   r_  r  rx   r  rQ   r	  r
  r  r  r  r   rX   )	ry   r  r  r  rT   rY  r!   r  r  s	            r   *test_to_surface__setsurface_with_zero_size7MaskTypeTest.test_to_surface__setsurface_with_zero_size  s     g.	{{	5^^FMJ
__
_;
j&..9wS__Z8:LM
,,.>?//1>B,,.	:Dn=r   c                 P   Sn[         nSn[        R                  " S5      nSn[        R                  R	                  U5      n[        R
                  " SX#5      nUR                  US9nU R                  U[        R
                  5        [        (       d&  U R                  [        R                  " U5      U5        U R                  UR                  5       U-  5        U R                  UR                  5       U5        U R                  UR                  5       U5        [!        XU5        g)z7Ensures zero sized unsetsurfaces are handled correctly.r	   r   r  r  r/   r  Nr  )	ry   r  r  r  rT   rY  r!   r#  r  s	            r   ,test_to_surface__unsetsurface_with_zero_size9MaskTypeTest.test_to_surface__unsetsurface_with_zero_size  s     g.	{{	*~~fmL__,_?
j&..9wS__Z8:LM
,,.>?//1>B,,.	:Dn=r   c                    S H|  nS Hs  nSU SU 3n[         R                  R                  XS9nU R                  U[         R                  R                  U5        U R	                  UR                  5       X5        Mu     M~     g)z-Ensures masks can be created with zero sizes.)r  r   )r   r  r/   r   r   z, fill=r   N)r
   r!   r   rx   rQ   r   )ry   r   r   r`   r!   s        r   test_zero_maskMaskTypeTest.test_zero_mask  sq    0D%dV74&1{{'''8%%dFKK,<,<cB  $< & 1r   c                    S Hy  n[         R                  R                  U5      nUR                  5       nU R	                  U[         R                  R                  5        U R                  X25        [        XU5        M{     g)z0Ensures copy correctly handles zero sized masks.)ru   r   )r   ru   r/   Nr   )ry   r{   r!   r   s       r   test_zero_mask_copy MaskTypeTest.test_zero_mask_copy  s]    7M;;##M2D		I!!)V[[-=-=>Y-DT2 8r   c                     S HC  n[         R                  R                  U5      nUR                  5       nU R	                  X15        ME     g)z4Ensures get_size correctly handles zero sized masks.))r  r   )r   (   r/   N)r
   r!   r   r   rQ   ry   r{   r!   r   s       r   test_zero_mask_get_size$MaskTypeTest.test_zero_mask_get_size  s9    7M;;##M2D==?DT1 8r   c                     S HZ  n[         R                  " SU5      n[         R                  R                  U5      nUR	                  5       nU R                  XB5        M\     g)z4Ensures get_rect correctly handles zero sized masks.)r  )r   r   r/   r/   N)r
   r'   r!   r   rO   rQ   )ry   r{   r   r!   rC   s        r   test_zero_mask_get_rect$MaskTypeTest.test_zero_mask_get_rect  sI    5M"KK>M;;##M2D==?DT1 6r   c                     S HQ  n[         R                  R                  U5      nU R                  [        5         UR                  S5      nSSS5        MS     g! , (       d  f       Me  = f)z2Ensures get_at correctly handles zero sized masks.))3   r   )r   r  r/   r/   Nr  )ry   r   r!   r   s       r   test_zero_mask_get_at"MaskTypeTest.test_zero_mask_get_at  sM    .D;;##D)D"":.F+ /. / /.   A
A(	c                     S HQ  n[         R                  R                  U5      nU R                  [        5         UR                  S5        SSS5        MS     g! , (       d  f       Me  = f)z2Ensures set_at correctly handles zero sized masks.))r   r   )r      r/   r/   Nr&  r   s      r   test_zero_mask_set_at"MaskTypeTest.test_zero_mask_set_at  sK    .D;;##D)D"":.F# /. / /.r  c                     Sn[        SS5       Hk  u  p#SU SU 3n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  Xa5      nU R                  Xt5        Mm     g)	zgEnsures 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.  rL  )ry   r/  size1size2r`   r|   r}   r7  s           r   test_zero_mask_overlap#MaskTypeTest.test_zero_mask_overlap	  s|    
 +B3LE5'%1CKK$$U$6EKK$$U$6E--6Kk/ 4r   c                    SnSn[        SS5       Hl  u  p4SU SU 3n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  Xq5      nU R                  XU5        Mn     g	)
zlEnsures overlap_area correctly handles zero sized masks.

Tests combinations of sized and zero sized masks.
r/   r   r  4   r  r  Tr   N)r;   r
   r!   r   rb   rQ   )	ry   r/  rz   r  r  r`   r|   r}   rk  s	            r   test_zero_mask_overlap_area(MaskTypeTest.test_zero_mask_overlap_area  s    
 +B3LE5'%1CKK$$U$6EKK$$U$6E!..u=M]C@ 4r   c                    SnSn[        SS5       H  u  p4SU SU 3n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  Xq5      nU R                  U[        R                  R                  U5        U R                  UR                  5       X%5        U R                  UR                  5       X55        M     g	)
zlEnsures overlap_mask correctly handles zero sized masks.

Tests combinations of sized and zero sized masks.
r/   r   r  r  r  r  Tr   N)	r;   r
   r!   r   r  rx   rQ   ra   r   )	ry   r/  rz   r  r  r`   r|   r}   r  s	            r   test_zero_mask_overlap_mask(MaskTypeTest.test_zero_mask_overlap_mask*  s    
 +B3LE5'%1CKK$$U$6EKK$$U$6E --e<L!!,0@0@#F\//1>G\224eA 4r   c                     SnS HV  n[         R                  R                  U5      nUR                  5         U R	                  UR                  5       USU 35        MX     g)z0Ensures fill correctly handles zero sized masks.r   r  r   N)r
   r!   r   r   rQ   ra   )ry   rz   r   r!   s       r   test_zero_mask_fill MaskTypeTest.test_zero_mask_fill=  sL    0D;;##D)DIIKTZZ\>U4&>J 1r   c                     SnU HR  n[         R                  R                  U5      nUR                  5         U R	                  UR                  5       S5        MT     g Nr  r   )r
   r!   r   r  rQ   ra   ry   r6   r   r!   s       r   test_zero_mask_clear!MaskTypeTest.test_zero_mask_clearH  sD    ,D;;##D)DJJLTZZ\1- r   c                     SnU HR  n[         R                  R                  U5      nUR                  5         U R	                  UR                  5       S5        MT     g r  )r
   r!   r   r  rQ   ra   r  s       r   test_zero_mask_flip MaskTypeTest.test_zero_mask_flipP  sD    ,D;;##D)DKKMTZZ\1- r   c                    SnU H}  n[         R                  R                  U5      nUR                  S5      nU R	                  U[         R                  R                  5        U R                  UR                  5       S5        M     g )Nr  r	   r   )r
   r!   r   r  rx   rQ   r   )ry   r6   r   r!   r}   s        r   test_zero_mask_scale!MaskTypeTest.test_zero_mask_scaleX  sd    ,D;;##D)DJJv&E!!%)9)9:U^^-v6 r   c                 |   Sn[        SS5       H  u  p#SU SU 3n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  5       nUR                  Xa5        U R                  UR	                  5       Xt5        U R                  UR                  5       X$5        M     g)	zdEnsures draw correctly handles zero sized masks.

Tests combinations of sized and zero sized masks.
r/   r   r   r  r  Tr   N)r;   r
   r!   r   ra   r  rQ   r   ry   r/  r  r  r`   r|   r}   rz   s           r   test_zero_mask_draw MaskTypeTest.test_zero_mask_drawb  s    
 +B3LE5'%1CKK$$U$6EKK$$U$6E"[[]NJJu%U[[]N@U^^-u: 4r   c                 |   Sn[        SS5       H  u  p#SU SU 3n[        R                  R                  USS9n[        R                  R                  USS9nUR	                  5       nUR                  Xa5        U R                  UR	                  5       Xt5        U R                  UR                  5       X$5        M     g)	zeEnsures erase correctly handles zero sized masks.

Tests combinations of sized and zero sized masks.
r/      rv   r  r  Tr   N)r;   r
   r!   r   ra   r  rQ   r   r)  s           r   test_zero_mask_erase!MaskTypeTest.test_zero_mask_eraset  s    
 +B3LE5'%1CKK$$U$6EKK$$U$6E"[[]NKK&U[[]N@U^^-u: 4r   c                     SnU HA  n[         R                  R                  USS9nU R                  UR	                  5       S5        MC     g )Nr  Tr   r   )r
   r!   r   rQ   ra   r  s       r   test_zero_mask_count!MaskTypeTest.test_zero_mask_count  s@    ,D;;##Dt#4DTZZ\1- r   c                     SnU HB  n[         R                  R                  U5      nU R                  UR	                  5       S5        MD     g )Nr  r/   )r
   r!   r   rQ   r=  r  s       r   test_zero_mask_centroid$MaskTypeTest.test_zero_mask_centroid  s;    ,D;;##D)DT]]_f5 r   c                     SnU HB  n[         R                  R                  U5      nU R                  UR	                  5       S5        MD     g )Nr  rh  )r
   r!   r   rQ   rb  r  s       r   test_zero_mask_angle!MaskTypeTest.test_zero_mask_angle  s;    ,D;;##D)DTZZ\3/ r   c                     / nS HG  n[         R                  R                  U5      nUR                  5       nU R	                  XASU 35        MI     g)z3Ensures outline correctly handles zero sized masks.))r  r   r   <   r/   r   Nr
   r!   r   rx  r  ry   expected_pointsr   r!   r(   s        r   test_zero_mask_outline#MaskTypeTest.test_zero_mask_outline  sF    .D;;##D)D\\^F  E$.I /r   c                     / nS HH  n[         R                  R                  U5      nUR                  S5      nU R	                  XASU 35        MJ     g)zWEnsures outline correctly handles zero sized masks
when using the skip pixels argument.))r   r   )r   r   r/   r  r   Nr<  r=  s        r    test_zero_mask_outline__with_arg-MaskTypeTest.test_zero_mask_outline__with_arg  sK     .D;;##D)D\\"%F  E$.I /r   c           	         S H  n[         R                  R                  USS9nS H  nSU SU 3n[         R                  R                  USS9n[        SUS   US   -   S-
  5      [        SUS   US   -   S-
  5      4nUR	                  U5      nU R                  U[         R                  R                  U5        U R                  XuU5        U R                  UR                  5       Xd5        M     M     g	)
zvEnsures 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   r:  r/   sizes=r  r   r   N)	r
   r!   r   r&   r|  rx   r   rQ   r   )ry   r  r|   r  r`   r}   r{   r!   s           r   test_zero_mask_convolve$MaskTypeTest.test_zero_mask_convolve  s    
 :EKK$$U$6E<ugRw/((T(:58eAh.2358eAh.23!
 ~~e,%%dFKK,<,<cB  c2  -E = :r   c           	         S H  n[         R                  R                  USS9nS H  n[         R                  R                  USS9nS H  nSU SU SU 3n[         R                  R                  U5      nUR                  XG5      nU R	                  U[         R                  R                  U5        U R                  XU5        U R                  UR                  5       XV5        M     M     M     g)	zEnsures convolve correctly handles zero sized masks
when using an output mask argument.

Tests the different combinations of sized and zero sized masks.
))ru   r  [   r   r   Z   r/   Tr   ))r   ru   )r   r   )r   >   r/   )rS  rE  rF  r/   rJ  r  N)r
   r!   r   r|  rx   r  rQ   r   )	ry   r  r|   r  r}   output_sizer`   output_maskr!   s	            r   )test_zero_mask_convolve__with_output_mask6MaskTypeTest.test_zero_mask_convolve__with_output_mask  s     :EKK$$U$6E=((T(:#EK"5'E7"[MBC"(++"2"2;"?K >>%=D))$0@0@#FMM$S9$$T]]_kG $F > :r   c                 X   SnS H  nSU 3n[         R                  R                  U5      nUR                  5       nU R	                  U[         R                  R                  U5        U R                  UR                  5       U5        U R                  UR                  5       X5        M     g)z?Ensures connected_component correctly handles zero sized masks.r   )rH  )r   P   r/   r   N)r
   r!   r   r  rx   rQ   r   ra   )ry   rz   r   r`   r!   cc_masks         r   "test_zero_mask_connected_component/MaskTypeTest.test_zero_mask_connected_component  s    .D$.C;;##D)D..0G!!'6;;+;+;SAW--/6W]]_nB /r   c                     S HQ  n[         R                  R                  U5      nU R                  [        5         UR                  S5      nSSS5        MS     g! , (       d  f       Me  = f)z\Ensures connected_component correctly handles zero sized masks
when using an index argument.)rN  rP  r/   r/   N)r
   r!   r   r   r  r  )ry   r   r!   rY  s       r   +test_zero_mask_connected_component__indexed8MaskTypeTest.test_zero_mask_connected_component__indexed  sQ     /D;;##D)D"":.226: /. / /.r  c                     / nS HG  n[         R                  R                  U5      nUR                  5       nU R	                  XASU 35        MI     g)z@Ensures connected_components correctly handles zero sized masks.)r  r  r/   r   N)r
   r!   r   r  r  )ry   expected_cc_masksr   r!   cc_maskss        r   #test_zero_mask_connected_components0MaskTypeTest.test_zero_mask_connected_components  sJ    .D;;##D)D002H  dVnM /r   c                     / nS HG  n[         R                  R                  U5      nUR                  5       nU R	                  XASU 35        MI     g)z>Ensures get_bounding_rects correctly handles zero sized masks.))r"  r   )r   rs  r/   r   N)r
   r!   r   r  r  )ry   expected_bounding_rectsr   r!   bounding_rectss        r   !test_zero_mask_get_bounding_rects.MaskTypeTest.test_zero_mask_get_bounding_rects   sM    "$.D;;##D)D!446N  5 /r   c                    [         R                  " S5      n[         R                  " S5      nS H  n[         R                  " U[        S5      nUR	                  U5        S Hu  n[         R
                  R                  USS9nUR                  XAS9nU R                  Xt5        U R                  UR                  5       U5        S	U;  d  Mi  [        XU5        Mw     M     g
)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  rQ   r   rX   )ry   
mask_color
surf_colorrB  r   rY  r!   r  s           r   test_zero_mask_to_surface&MaskTypeTest.test_zero_mask_to_surface  s    \\&)
\\%(
9InnY"=GLL$5	{{''	'=!__W_J
j2  !4!4!6	BI%'*E 6	 :r   c                    [         R                  " S5      nS Hp  n[         R                  R                  USS9nUR	                  US9nU R                  U[         R                  5        U R                  UR                  5       U5        Mr     g)zlEnsures 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  rx   r_  rQ   r   )ry   rj  rY  r!   r  s        r   )test_zero_mask_to_surface__create_surface6MaskTypeTest.test_zero_mask_to_surface__create_surface!  sr     \\&)
1I;;##ID#9D*=J!!*fnn=Z002I> 2r   r2   N)F)__name__
__module____qualname____firstlineno__r?  unittestskipIfr  r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r#  r'  r8  rB  rH  rP  rU  r[  ra  rf  rl  rr  ru  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+  r3  r7  r:  r?  rC  rH  rK  rO  rR  rU  r^  re  rk  ro  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/  r2  r5  r<  rC  expectedFailurerG  rJ  rT  rX  r]  re  rn  rr  rx  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-  r1  r4  r7  r<  r?  rB  rH  rK  rN  r[  rn  rv  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.  r1  r4  r7  r?  rB  rK  rU  rZ  r]  rb  rg  rl  ro  __static_attributes__r2   r   r   rh   rh      s   
N __W12: 3: )B __W12F 3F(BC&;$;
;*9
2 __W125: 35:n.) __W12. 3..2M!">$>$>$!"!GF@.">H<8@< __W12G 3G: __W12= 3=7 __W12!G 3!GF __W12@ 3@:@> __W12!G 3!GFD>"GH __W127 372 @D __W12!D 3!DF @D __W12&G 3&GPC=D&
9 __W12 3$	9& __W128 38>	9
9 __W12 3* __W12S 3S6!G@@B$=L@8 __W12(G 3(GT,&G@@B$=L@8 __W12(G 3(GT-'9  __W12 3<
9	96	9>">&>">&6>0
0
9'*M(0 '2	D __W12 3",,*XB$B&!
F$
L=.F):V5(5*05d __W12w 3wr __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 __W12B 3BH!F __W12" 3 "H 3 3j ) )VB4B$F>CBR@H:E:G>V,:1f@3j __W12 3 @ 6 6p __W12! 3 !F __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   rh   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SubMaski0  z4Subclass of the Mask class to help test subclassing.c                 4   > [         TU ]  " U0 UD6  SU l        g )NT)super__init__test_attribute)ry   rw  r   	__class__s      r   r}  SubMask.__init__3  s    $)&)"r   )r~  )rq  rr  rs  rt  __doc__r}  rx  __classcell__r  s   @r   rz  rz  0  s    ># #r   rz  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SubMaskCopyi8  ;Subclass of the Mask class to help test copying subclasses.c                 F   > [         TU ]  5       nU R                  Ul        U$ rG   )r|  r   r~  ry   r   r  s     r   r   SubMaskCopy.copy;  s"    GLN	#'#6#6	 r   r2   rq  rr  rs  rt  r  r   rx  r  r  s   @r   r  r  8      E r   r  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SubMaskDunderCopyiA  r  c                 F   > [         TU ]  5       nU R                  Ul        U$ rG   )r|  __copy__r~  r  s     r   r  SubMaskDunderCopy.__copy__D  s$    G$&	#'#6#6	 r   r2   )rq  rr  rs  rt  r  r  rx  r  r  s   @r   r  r  A  r  r   r  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SubMaskCopyAndDunderCopyiJ  r  c                     > [         TU ]  5       $ rG   )r|  r   )ry   r  s    r   r   SubMaskCopyAndDunderCopy.copyM  s    w|~r   r2   r  r  s   @r   r  r  J  s    E r   r  c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSr g) MaskSubclassTestiQ  zTest subclassed Masks.c                     [        SSS9nU R                  U[        R                  R                  5        U R                  U[         5        U R                  UR                  5        g)z)Ensures the Mask class can be subclassed.r^  Tr   N)rz  rx   r
   r!   r   r  r~  r  s     r   test_subclass_mask#MaskSubclassTest.test_subclass_maskT  sJ    vD)dFKK$4$45dG,++,r   c                 b   [        SSS9nUR                  5       [        R                  " U5      4 H{  nU R                  U[        R                  R
                  5        U R                  U[         5        U R                  X!5        [        XU5        U R                  [        US5      5        M}     g)z(Ensures copy works for subclassed Masks.r   r	   Tr   r~  N)
rz  r   rx   r
   r!   r   r   rf   assertFalsehasattrry   r!   r   s      r   test_subclass_copy#MaskSubclassTest.test_subclass_copy\  s    wT* ))+tyy7I!!)V[[-=-=>!!)W5Y-DT2WY0@AB 8r   c                    [        SSS9n[        UR                  5       [        R                  " U5      45       H  u  p#U R                  U[        R
                  R                  5        U R                  U[         5        U R                  X15        [        XU5        SU:X  a  U R                  [        US5      5        M  U R                  UR                  5        M     g)z8Ensures copy works for subclassed Masks overriding copy.r  Tr   r   r~  N)r  rX  r   rx   r
   r!   r   r   rf   r  r  r  r~  )ry   r!   r   r   s       r   !test_subclass_copy__override_copy2MaskSubclassTest.test_subclass_copy__override_copyi  s    7. &tyy{DIIdO&DELA!!)V[[-=-=>!!)[9Y-DT2Av  4D!EF	 8 89 Fr   c                 b   [        SSS9nUR                  5       [        R                  " U5      4 H{  nU R                  U[        R                  R
                  5        U R                  U[         5        U R                  X!5        [        XU5        U R                  UR                  5        M}     g)z<Ensures copy works for subclassed Masks overriding __copy__.r  Tr   N)
r  r   rx   r
   r!   r   r   rf   r  r~  r  s      r   (test_subclass_copy__override_dunder_copy9MaskSubclassTest.test_subclass_copy__override_dunder_copyz  s     t4 ))+tyy7I!!)V[[-=-=>!!)->?Y-DT2 OOI445 8r   c                 b   [        SSS9nUR                  5       [        R                  " U5      4 H{  nU R                  U[        R                  R
                  5        U R                  U[         5        U R                  X!5        [        XU5        U R                  UR                  5        M}     g)zAEnsures copy works for subclassed Masks overriding copy/__copy__.r  Tr   N)
r  r   rx   r
   r!   r   r   rf   r  r~  r  s      r   .test_subclass_copy__override_both_copy_methods?MaskSubclassTest.test_subclass_copy__override_both_copy_methods  s    'd; ))+tyy7I!!)V[[-=-=>!!)-EFY-DT2OOI445 8r   c                 `    Sn[        U5      nUR                  5       nU R                  X15        g)z,Ensures get_size works for subclassed Masks.r%  N)rz  r   rQ   r  s       r   test_subclass_get_size'MaskSubclassTest.test_subclass_get_size  s*    }%}}-r   c                     [         R                  " SS5      n[        UR                  SS9nUR	                  5       nU R                  X15        g)z,Ensures get_rect works for subclassed Masks.r/   )r   r   Tr   N)r
   r'   rz  r   rO   rQ   )ry   r   r!   rC   s       r   test_subclass_mask_get_rect,MaskSubclassTest.test_subclass_mask_get_rect  s=    FH5}))5}}-r   c                 `    Sn[        SSS9nUR                  S5      nU R                  X15        g)z*Ensures get_at works for subclassed Masks.r   r   Tr   r/   N)rz  r   rQ   )ry   r  r!   bits       r   test_subclass_get_at%MaskSubclassTest.test_subclass_get_at  s/    vD)kk&!+r   c                     SnSnSn[        SSS9nUR                  U5        U R                  UR                  U5      U5        U R                  UR	                  5       U5        g)z*Ensures set_at works for subclassed Masks.r   r/   Fr  r   N)rz  r   rQ   r   ra   )ry   r  rz   rW   r!   s        r   test_subclass_set_at%MaskSubclassTest.test_subclass_set_at  sX    E/CS)<8~6r   c                    SnSn[         R                  R                  SUS9[        US5      4n[         R                  R                  SUS9[        US5      4nU H/  nU H&  nUR	                  US5      nU R                  Xq5        M(     M1     g)z+Ensures overlap works for subclassed Masks.r/   r%  Tr   N)r
   r!   r   rz  r.  rQ   )ry   r6  rY  masks	arg_masksr!   arg_maskr7  s           r   test_subclass_overlap&MaskSubclassTest.test_subclass_overlap  s    	!!t)!<giQU>VWKK$Y7It$
	 D%"ll8V<  ; & r   c                 0   SnUS   US   -  n[         R                  R                  SUS9[        US5      4n[         R                  R                  SUS9[        US5      4nU H/  nU H&  nUR	                  US5      nU R                  Xr5        M(     M1     g)z0Ensures overlap_area works for subclassed Masks.r   r   r   Tr   r/   N)r
   r!   r   rz  rb   rQ   )ry   rY  rz   r  r  r!   r  rk  s           r   test_subclass_overlap_area+MaskSubclassTest.test_subclass_overlap_area  s    	"1	!4!!t)!<giQU>VWKK$Y7It$
	 D% $ 1 1(F C  ? & r   c                    SnUS   US   -  n[         R                  R                  SUS9[        US5      4n[         R                  R                  SUS9[        US5      4nU H  nU H  nUR	                  US5      nU R                  U[         R                  R                  5        U R                  U[        5        U R                  UR                  5       U5        U R                  UR                  5       U5        M     M     g)z0Ensures overlap_mask works for subclassed Masks.r   r   r   Tr   r/   N)
r
   r!   r   rz  r  rx   assertNotIsInstancerQ   ra   r   )ry   r{   rz   r  r  r!   r  r  s           r   test_subclass_overlap_mask+MaskSubclassTest.test_subclass_overlap_mask  s    &q)M!,<<KK$];M4(

 KK$];M4(
	 D%#006B%%lFKK4D4DE((w?  !3!3!5~F  !6!6!8-H & r   c                     SnUS   US   -  n[        SUS9nUR                  5         U R                  UR                  5       U5        g)z(Ensures fill works for subclassed Masks.r  r   r   Fr   N)rz  r   rQ   ra   ry   rY  rz   r!   s       r   test_subclass_fill#MaskSubclassTest.test_subclass_fill  sD    	"1	!4E	2		~6r   c                     SnSn[        US5      nUR                  5         U R                  UR                  5       U5        g)z)Ensures clear works for subclassed Masks.)r   r   r   TN)rz  r  rQ   ra   r  s       r   test_subclass_clear$MaskSubclassTest.test_subclass_clear  s7    	y$'

~6r   c                     SnUS   US   -  n[        SUS9nUR                  5         U R                  UR                  5       U5        g)z*Ensures invert works for subclassed Masks.r   r   r   r   Fr   N)rz  r  rQ   ra   r  s       r   test_subclass_invert%MaskSubclassTest.test_subclass_invert  sD    	"1	!4E	2~6r   c                     Sn[        S5      nUR                  U5      nU R                  U[        R                  R
                  5        U R                  U[         5        U R                  UR                  5       U5        g)z)Ensures scale works for subclassed Masks.r  r  N)	rz  r  rx   r
   r!   r   r  rQ   r   )ry   r{   r!   scaled_masks       r   test_subclass_scale$MaskSubclassTest.test_subclass_scale  sa    vjj/k6;;+;+;<  g6--/?r   c                 j   SnUS   US   -  n[         R                  R                  SUS9[        US5      4n[         R                  R                  U5      [        U5      4 HN  nU HE  nUR	                  5         UR                  US5        U R                  UR                  5       U5        MG     MP     g)z(Ensures draw works for subclassed Masks.r   r   r   Tr   r/   N)r
   r!   r   rz  r  r  rQ   ra   )ry   rY  rz   r  r!   r  s         r   test_subclass_draw#MaskSubclassTest.test_subclass_draw  s    	"1	!4KK$Y7It$
	 [[%%i0')2DED%

		(F+  ~> & Fr   c                 d   SnSn[         R                  R                  US5      [        US5      4n[         R                  R                  US5      [        US5      4nU HN  nU HE  nUR	                  5         UR                  US5        U R                  UR                  5       U5        MG     MP     g)z)Ensures erase works for subclassed Masks.r  r   Tr/   N)r
   r!   r   rz  r   r  rQ   ra   )ry   rY  rz   r  r  r!   r  s          r   test_subclass_erase$MaskSubclassTest.test_subclass_erase/  s    	!!)T2GIt4LM[[%%i6	48PQ	 D%		

8V,  ~> & r   c                     SnUS   US   -  S-
  n[        SUS9nUR                  SS5        UR                  5       nU R                  XB5        g)z)Ensures count works for subclassed Masks.r  r   r   Tr   rk   N)rz  r   ra   rQ   )ry   rY  rz   r!   ra   s        r   test_subclass_count$MaskSubclassTest.test_subclass_count?  sQ    	"1	!4q8Dy1FA

/r   c                 d    SnSn[        S5      nUR                  5       nU R                  XA5        g)z,Ensures centroid works for subclassed Masks.r/   r   N)rz  r=  rQ   )ry   r>  rY  r!   r=  s        r   test_subclass_centroid'MaskSubclassTest.test_subclass_centroidJ  s/    "	v==?5r   c                 \    Sn[        SS9nUR                  5       nU R                  X15        g)z)Ensures angle works for subclassed Masks.rh  r   rw   N)rz  rb  rj  )ry   rd  r!   rb  s       r   test_subclass_angle$MaskSubclassTest.test_subclass_angleT  s*    F#

u5r   c                 `    / n[        S5      nUR                  5       nU R                  X15        g)z+Ensures outline works for subclassed Masks.r  N)rz  rx  r  )ry   expected_outliner!   rx  s       r   test_subclass_outline&MaskSubclassTest.test_subclass_outline]  s*    v,,.W7r   c                 2   Su  pX4nSn[        SUS-  S-
  5      [        SUS-  S-
  5      4n[        R                  R                  U5      [	        U5      4n[        R                  R                  U5      [	        U5      4n[        R                  R                  U5      [	        U5      4 GHg  nU GH\  n	UR                  U	5      n
U R                  U
[        R                  R                  5        U R                  U
[        5        U R                  U
R                  5       U5        U R                  U
R                  5       U5        U H  nUR                  X5      n
U R                  U
[        R                  R                  5        U R                  U
R                  5       U5        U R                  U
R                  5       U5        [        U[        5      (       a  U R                  U
[        5        M  U R                  U
[        5        M     GM_     GMj     g)z,Ensures convolve works for subclassed Masks.rS  r   r	   r   N)r&   r
   r!   r   rz  r|  rx   r  rQ   ra   r   
isinstance)ry   r9   r:   rY  rz   r{   r  output_masksr!   r  r  rT  s               r   test_subclass_convolve'MaskSubclassTest.test_subclass_convolvef  s   O	Q	A.AvzA~0FG[[%%i0')2DE	((3WY5GH [[%%i0')2DED% $h 7%%mV[[5E5EF((@  !4!4!6G  !7!7!9=I $0K$(MM($HM))-9I9IJ$$]%8%8%:NK$$]%;%;%=yI!+w77--mWE00H $0 & Fr   c                 B   SnSn[        U5      nUR                  5       nU R                  U[        R                  R
                  5        U R                  U[         5        U R                  UR                  5       U5        U R                  UR                  5       U5        g)z7Ensures connected_component works for subclassed Masks.r   r  N)
rz  r  rx   r
   r!   r   r  rQ   ra   r   )ry   rz   r{   r!   rY  s        r   !test_subclass_connected_component2MaskSubclassTest.test_subclass_connected_component  s}    }%**,gv{{'7'78  '2.9))+];r   c                 `    / n[        S5      nUR                  5       nU R                  X15        g)z8Ensures connected_components works for subclassed Masks.r   N)rz  r  r  )ry   expected_ccsr!   ccss       r   "test_subclass_connected_components3MaskSubclassTest.test_subclass_connected_components  s,    v'')S/r   c                 `    / n[        S5      nUR                  5       nU R                  X15        g)z6Ensures get_bounding_rects works for subclassed Masks.r   N)rz  r  r  )ry   re  r!   rf  s       r    test_subclass_get_bounding_rects1MaskSubclassTest.test_subclass_get_bounding_rects  s-    "$v002^Er   c                 b   [         R                  " S5      nSn[        USS9n[         R                  " U[        S5      nUR                  [         R                  " S5      5        UR                  XAS9nU R                  XT5        U R                  UR                  5       U5        [        XU5        g)	z.Ensures to_surface works for subclassed Masks.r[  r^  Tr   r   r  r  N)r
   r  rz  r_  r  r   r  r  rQ   r   rX   r\  s         r   test_subclass_to_surface)MaskSubclassTest.test_subclass_to_surface  s    f-t$'..x4V\\%()__W_F
j*,,.5Dn=r   r2   N)!rq  rr  rs  rt  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  rx  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                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)MaskModuleTesti  c           	      f   Sn/ SQnSnUS   US   -  nSnS GH  n[         R                  " U[        U5      n[        U5       H  nXS'   UR	                  U5        US:  a  UR                  S	5      S   nS
SUS-
  XS-   SS1n	U	 H  n
SU SU SU
 3nX:  a  UnOUn[         R                  R                  XzS9nU R                  U[         R                  R                  U5        U R                  UR                  5       X;5        U R                  UR                  5       X5        M     M     GM     g)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   )ru   r  r   r   r  r   r   r/   rn   r|  depth=z, alpha=z, threshold=)r   r    N)r
   r_  r  r   r   r   r!   ra  rx   r   rQ   r   ra   )ry   threshold_countr  r{   all_set_countnone_set_countr  r   alphathreshold_test_valuesr    r`   rz   r!   s                 r   test_from_surface MaskModuleTest.test_from_surface  s=    )%a(=+;;Enn]HeDG/#(a ]+2: $NN6215E *,Q	5!)SRU(V%!6I"5'%YKPC()6)7!;;33 ' 4 D ))$0@0@#F$$T]]_mI$$TZZ\>G "7 0 r   c                    SnSn/ SQnUS4n[         R                  " USS9n[         R                  " U[        S5      nUR	                  5         [        U5       H  nXsS'   UR                  US	4U5        M     UR                  5         [        U5       H  nS
U 3n	UR                  US	4S	5        UR                  5       n
[         R                  R                  Xh5      nU R                  U[         R                  R                  U	5        U R                  UR                  5       XI5        U R                  UR                  5       X5        U R                  UR                  XQ5      X5        M     g)ac  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  )r  rs  r  r   r   Tr   r   r   r   
threshold=N)r
   r   r_  r  rP   r   r   rR   ra   r!   ra  rx   rQ   r   rb   )ry   r/  r   r  r{   r  r   r4   r    r`   rz   r!   s               r   )test_from_surface__different_alphas_32bit8MaskModuleTest.test_from_surface__different_alphas_32bit  s8    '(!,M=.."= 	'A !NNAq6=1 ( 	 /Iyk*C  )Q3*002N;;++G?D!!$(8(8#>T]]_mATZZ\>?!!-8. 0r   c                 8   Sn/ SQnUS4n[         R                  " U[        S5      nUR                  5         [	        U5       H  nXRS'   UR                  US4U5        M     UR                  5         [        5       n[        5       n[	        U5       HO  nUR                  US45      S   n	X;  a  U/Xi'   OXi   R                  U5        X:  d  M>  UR                  U5        MQ     / n
Sn[         R                  " U5      n[         R                  " USS	9nUR                  5        H  nU H  nX;   a  U
R                  XS-   U45        M   US
   S-   n[	        U5       H  nUR                  US4S5        M     [         R                  " USS	9nUR                  X5        U
R                  XU45          M     M     U
 H  u  nnnUR                  5       n[	        UU5       H  nSU 3n[         R                   R#                  XH5      nU R%                  U[         R                   R                  U5        U R'                  UR)                  5       UU5        U R'                  UR                  5       UU5        U R'                  UR+                  UU5      UU5        M     M     g)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   rR  r   r   r/   Tr   rn   r  N)r
   r_  r  rP   r   r   rR   r   setr   r  addr   r   r  ra   r!   ra  rx   rQ   r   rb   )ry   r   r  r{   r   r4   alpha_thresholdsspecial_thresholdsr    r  rR  r/  
erase_maskexp_mask
thresholdsto_thresholdthresfrom_thresholdr  rz   r`   r!   s                         r   )test_from_surface__different_alphas_16bit8MaskModuleTest.test_from_surface__different_alphas_16bit  sh    *(!,.."= 	'A !NNAq6=1 ( 	&= U /I NNIq>215E,+4+ ' '..y9 "&&y1 0 	[[/
;;}48*113J'	2$$iQ%IJ#-b>A#5L "'|!4"))5!*a8 "5  &{{=tDHNN:6$$ix%HI ( 4& <E7NL-*002N"><@	"9+.{{//C%%dFKK,<,<cB  -E  ~sC  %%mV<nc A <Er   c                    SnSnSnS H  nSU 3n[         R                  " USU5      nU H  nUR                  U5        UR                  UR	                  5       5        [         R
                  R                  U5      nU R                  U[         R
                  R                  U5        U R                  UR                  5       X%5        U R                  UR                  5       X55        M     M     g)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.
)ri  r   r  r  rn  r|  r|  r|  r  r   r  r  N)r
   r_  set_colorkeyr   r   r!   ra  rx   r   rQ   r   ra   )	ry   	colorkeysr{   rz   r  r`   r   colorkeyr!   s	            r   -test_from_surface__with_colorkey_mask_cleared<MaskModuleTest.test_from_surface__with_colorkey_mask_cleareda  s     L	$E5'"Cnn]Au=G%$$X. W1134{{//8%%dFKK,<,<cB  -E  ~C &	 %r   c                    SnSnSnUS   US   -  nS H  nSU 3n[         R                  " USU5      nUR                  U5        U H  nUR                  U5        [         R                  R                  U5      n	U R                  U	[         R                  R                  U5        U R                  U	R                  5       X65        U R                  U	R                  5       XF5        M     M     g)	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.
)ri  r   )r  r  rn  r  r  r  r   r   r  r  N)r
   r_  r   r  r!   ra  rx   r   rQ   r   ra   )
ry   r  r  r{   rz   r  r`   r   r   r!   s
             r   ,test_from_surface__with_colorkey_mask_filled;MaskModuleTest.test_from_surface__with_colorkey_mask_filled|  s     L	&&q)M!,<<$E5'"Cnn]Au=GLL'%$$X.{{//8%%dFKK,<,<cB  -E  ~C & %r   c                    S nSnSnSn[         R                  R                  U5      nU" UR                  SS/UQ76   UR	                  5       nSnS H  nS	U 3n	[         R
                  " USU5      n
U" U
R                  X#/UQ76   U
R                  U5        [         R                  R                  U
5      nU R                  U[         R                  R                  U	5        U R                  UR                  5       XI5        U R                  UR	                  5       Xi5        U R                  UR                  XW5      Xi5        M     g
)zEnsures 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                 r   ^ SnU4S j[        U5       5        H  nU " Xe(       a  UOU5        U(       + nM     g )NFc              3   P   >#    U  H  n[        T5        H  o!U4v   M
     M     g 7frG   r/  r  s      r   r7   bMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate.<locals>.<genexpr>  r  r2  r/  )func	set_valueunset_valuer9   r:   setbitrW   s       `  r   	alternateOMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate  s1    FLeLSv);?# Mr   )r   r  rs  )r  r;  rG  )ru   r	   r   r   r/   r  r  N)r
   r!   r   r   ra   r_  r  ra  rx   rQ   r   rb   )ry   r.  r  r   r{   r  rz   r/  r  r`   r   r!   s               r   -test_from_surface__with_colorkey_mask_pattern<MaskModuleTest.test_from_surface__with_colorkey_mask_pattern  s   	$ $((7-&&1=}=&,,.$E5'"Cnn]Au=GgnnmNN  *;;++G4D!!$(8(8#>T]]_mATZZ\>?!!-8. %r   c                    / SQnU H  n[         R                  R                  SSU5      nUR                  SS5        [         R                  R                  USS5      nUR                  5       nU R                  UR                  5       S5        U R                  UR                  5       [         R                  " S5      /5        M     U GH  n[         R                  R                  SSU5      n[         R                  R                  SSU5      nUR                  S	5        UR                  S
5        UR                  S	S5        [         R                  R                  USSUS9nU R                  U[         R                  R                  5        U R                  UR                  5       S5        U R                  UR                  5       [         R                  " S5      /5        GM     g)z*Does mask.from_threshold() work correctly?rR  r  r   )rG  rG  r   r  r  rn  rs  rs  rs  rs  r  r  rn  r|  r  r  r  r|  i  r  r  r     r:  r:  r  r  r  r  r8  )r   colorr    othersurfacer  N)r
   r   r_  r   r!   r  r  rQ   ra   r'   rx   r   )ry   r4   r   surfr!   r  surf2s          r   test_from_threshold"MaskModuleTest.test_from_threshold  s    A>>))(Aq9DIIn&67;;--)+<D ++-ETZZ\3/T446EU9V8WX  A>>))(Aq9DNN**8Q:EIIo&JJ'JJ(89;;--"+"	 . D !!$(8(89TZZ\3/T446EU9V8WX r   c                    S H  n[         R                  R                  [         R                  " U5      5      nU R	                  U[         R                  R
                  SU 35        U R                  UR                  5       U5        M     g)z?Ensures from_surface can create masks from zero sized surfaces.r  r   N)r
   r!   ra  r_  rx   MaskTyperQ   r   r   s      r   test_zero_size_from_surface*MaskModuleTest.test_zero_size_from_surface  sa    0D;;++FNN4,@AD!!$(<(<dVnMT]]_d3	 1r   c                    / SQnSnU GH  nU H  n[         R                  R                  USU5      nUR                  SS5        [         R                  R                  USS5      nU R                  UR                  5       S5        UR                  5       nU R                  U/ 5        M     U GH  n[         R                  R                  USU5      n[         R                  R                  USU5      nUR                  S5        UR                  S	5        UR                  SS
5        [         R                  R                  USSU5      nU R                  U[         R                  R                  5        U R                  UR                  5       S5        UR                  5       nU R                  U/ 5        GM     GM     g )Nr3  r  r   r4  r5  r6  r7  r8  r9  r;  r8  )r
   r   r_  r   r!   r  rQ   ra   r  rx   r   )	ry   r4   r6   r   r   r>  r!   r  r?  s	            r   test_zero_size_from_threshold,MaskModuleTest.test_zero_size_from_threshold  sk   ,D~~--dAq9		.*:;{{11-/@   q1//1  +  ~~--dAq9..tQ:		/*

?+

?,<={{11,(95 %%dFKK,<,<=  q1//1  +  r   c                 |   SnSnSn[         R                  " U5      nU H  nUR                  US5        M     [        U5      nSUR                  S   -  nU H.  nUu  pX-  n
U R                  XjU	4   X-  -	  S-  SSU S35        M0     U H.  nUu  pX-  n
U R                  XjU	4   X-  -	  S-  SSU S	35        M0     g )
N)i  r  )rj   )r  r  )   rQ  )r/   )r   r  )rJ  rO  r   r%  zthe pixel at z is not set to 1r   z is not set to 0)r
   r   r   
memoryviewstridesrQ   )ry   r   
pixels_setpixels_unsetr!   pointviewintwidthr   r   cols              r   test_buffer_interface$MaskModuleTest.test_buffer_interface	  s    3
5{{4 EKKq!   $t||A&EDA-C1f!,/14w&67   "EDA-C1f!,/14w&67 "r   r2   N)rq  rr  rs  rt  r  r	  r  r!  r$  r0  r@  rD  rG  rS  rx  r2   r   r   r  r    s?    .H`$LRhD6D4&P YD4,Br   r  __main__)r  )   rG   )#collectionsr   r   platformr   ru  r	  r
   pygame.localspygame.mathr   python_implementationr  r   r#   r-   r;   r=   rD   rX   r^   rf   TestCaserh   r!   r   rz  r  r  r  r  rv  r  rq  mainr2   r   r   <module>r^     s   #     
    H224
4 IFN*(I[V?8$$ [V?|l#fkk #'  0 a>x(( a>H 
:;oX&& o <od zMMO r   