o
    OZhx                    @   sJ  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlT d dl	m
Z
 de kZd*ddZd+d
dZdd Zdd Zdd Zdd Zd,ddZdd Zd,ddZG dd dejZG dd dejjZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%ejZeed&G d'd( d(ejZ e!d)kre"  dS dS )-    )OrderedDictN)*)Vector2PyPyd   r   c                 C   sd   t | }t| d | d  d D ]}td| d d td| d d }}|||f q|S )zwrandom_mask(size=(100,100)): return Mask
    Create a mask of the given size, with roughly half the bits set at random.r         )pygameMaskrangerandomrandintset_at)sizemixy r   E/var/www/auris/lib/python3.10/site-packages/pygame/tests/mask_test.pyrandom_mask   s
   
*r      c                 C   s   t |  }|  }|r6t|  D ] }t|  D ]}| |d |d f|kr2|||fd qq|S t|  D ]}t|  D ]}| ||fd |krY|||fd qDq<|S )Ng?r      )	r
   r   get_sizeget_colorkeyr   
get_height	get_widthget_atr   )surface	thresholdmaskkeyr   r   r   r   r   maskFromSurface   s"   r#   c                 C   s   | d d  }}| d d  }}| dd D ]\}}t ||}t||}t ||}t||}qt||f|| d || d fS )z.Creates a bounding rect from the given points.r   r   N)minmaxr
   Rect)pointsZxminZxmaxZyminymaxr   r   r   r   r   create_bounding_rect*   s   


$r)   c                    s*   | |f| dfd|fdf  fdd D S )zCreates a generator which yields pairs of sizes.

    For each pair of sizes at least one of the sizes will have a 0 in it.
    r   r   r   c                 3   s2    | ]} D ]}d |v sd |v r||fV  qqdS r   Nr   ).0absizesr   r   	<genexpr>?   s   0 z"zero_size_pairs.<locals>.<genexpr>r   )widthheightr   r/   r   zero_size_pairs8   s   r4   c                 C   s4   |   \}}d|d df|d |d fd|d ffS )zjReturns a tuple with the corner positions of the given mask.

    Clockwise from the top left corner.
    r*   r   r   )r   )r!   r2   r3   r   r   r   cornersB   s   (r5   c                 C   s   | j d | jf| j d | jd f| j | jd f| jd | jd f| j| jd f| j| jf| j| jd f| j| jf| jd | jf| j | jf| j d | jf| j d | jd ffS )zvReturns a tuple with the positions off of the corners of the given rect.

    Clockwise from the top left corner.
    r   )lefttoprightbottom)rectr   r   r   off_cornersK   s   


r;   c                    s   |du rt |  t | }n|  || }t |j|j t |j|j	}|
   fdd|D D ]}| |||| q7|  dS )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   "    | ]} D ]}||fV  qqd S Nr   r,   r   r   Zx_ranger   r   r1   o        z&assertSurfaceFilled.<locals>.<genexpr>)r   r   r   	normalizeclipget_rectr6   r8   r7   r9   lockassertEqualr   unlock)testcaser   expected_color	area_recty_rangeposr   r?   r   assertSurfaceFilled`   s   rL   c                    sj   t |  t | }|  |   fdd|D D ]}||s.| |||| q|  dS )zcChecks if the surface is filled with the given color. The
    ignore_rect area is not checked.
    c                 3   r<   r=   r   r>   r?   r   r   r1   }   r@   z0assertSurfaceFilledIgnoreArea.<locals>.<genexpr>N)	r   r   r   rA   rD   collidepointrE   r   rF   )rG   r   rH   Zignore_rectrJ   rK   r   r?   r   assertSurfaceFilledIgnoreAreat   s   
rN   c                 C   sP   |  }| j| | |d | j||  |d | j|||d|d dS )z-Checks to see if the 2 given masks are equal.)msgr*   N)countrE   r   overlap_area)rG   m1m2rO   Zm1_countr   r   r   assertMaskEqual   s   rT   c                   @   s&
  e Zd ZdZeeddd Zdd Zdd Z	eedd	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zeeddd Zdd Zdd  Zeedd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"eedd;d< Z#eedd=d> Z$d?d@ Z%eeddAdB Z&eeddCdD Z'dEdF Z(eeddGdH Z)dIdJ Z*dKdL Z+dMdN Z,eeddOdP Z-dQdR Z.eeddSdT Z/dUdV Z0eeddWdX Z1dYdZ Z2d[d\ Z3d]d^ Z4d_d` Z5eeddadb Z6dcdd Z7dedf Z8eeddgdh Z9didj Z:dkdl Z;eeddmdn Z<eeddodp Z=dqdr Z>dsdt Z?dudv Z@dwdx ZAdydz ZBeedd{d| ZCd}d~ ZDdd ZEdd ZFdd ZGdd ZHdd ZIeeddd ZJdd ZKdd ZLdd ZMeeddd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`eeddd ZadddZbdddZcdddZddd ZeddÄ Zfddń ZgddǄ ZhddɄ Zidd˄ Zjdd̈́ Zkddτ Zlddф Zmddӄ ZnddՄ Zoeedddׄ Zpeedddل Zqddۄ Zrdd݄ Zsdd߄ Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{ej|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d Zdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Zej|dd Zej|dd Zej|dd Zej|dd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZdTdU ZdVdW ZeeddXdY ZdZd[ Zej|eedd\d] Zej|d^d_ Zej|d`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq Zdrds Zdtdu Zdvdw Zdxdy Zdzd{ Zej|eedd|d} Zej|d~d Zej|eeddd Zej|eeddd Zǐdd ZȐdd Zɐdd Zʐdd Zːdd Z̐dd Z͐dd Zΐdd Zϐdd ZАdd Zѐdd ZҐdd ZӐdd ZԐdd ZՐdd Z֐dd Zאdd Zؐdd Zِdd Zڐdd Zېdd Zܐdd Zݐdd Zސdd Zߐdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS (  MaskTypeTest)	r*   r   r   r   r   r   r   r   r   rZ   rZ   rZ   rZ   r   rZ   r   zSegfaults on pypyc                 C   s   d}d}t j|}t jj|d}| |t jj | | | | | | | |t jj | | | | | | dS )z:Ensure masks are created correctly without fill parameter.r         r   N)r
   r!   r   assertIsInstancerE   rP   r   )selfexpected_countexpected_sizemask1mask2r   r   r   	test_mask   s   zMaskTypeTest.test_maskc              	   C   sB   dD ]}|  t t|}W d   n1 sw   Y  qdS )z=Ensure the mask constructor handles negative sizes correctly.)rY   r^   r\   N)assertRaises
ValueErrorr
   r   rd   r   r!   r   r   r   test_mask__negative_size   s   z%MaskTypeTest.test_mask__negative_sizec           	      C   s   d\}}||f}|| dd}|  D ],\}}d| }tjj||d}| |tjj| | | || | | || qdS )z:Ensure masks are created correctly using the fill keyword.)%   /   r   TFfill=fillNitemsr
   r!   r   rc   rE   rP   r   	rd   r2   r3   rf   fill_countsrs   re   rO   r!   r   r   r   test_mask__fill_kwarg   s   
z"MaskTypeTest.test_mask__fill_kwargc                 C   s   t ddD ]:}t ddD ]2}|| }||f}d| }tjj|dd}| |tjj| | | || | | || qqdS )a  Ensures masks are created correctly using the fill keyword
        over a range of sizes.

        Tests masks of different sizes, including:
           -masks 31 to 33 bits wide (32 bit boundaries)
           -masks 63 to 65 bits wide (64 bit boundaries)
        r      B   size=Trr   N)r   r
   r!   r   rc   rE   rP   r   )rd   r3   r2   re   rf   rO   r!   r   r   r   $test_mask__fill_kwarg_bit_boundaries   s   	
z1MaskTypeTest.test_mask__fill_kwarg_bit_boundariesc           	      C   s   d\}}||f}|| dd}|  D ]+\}}d| }tj||}| |tjj| | | || | | || qdS )z4Ensure masks are created correctly using a fill arg.);   G   r   rp   rq   Nrt   rv   r   r   r   test_mask__fill_arg   s   
z MaskTypeTest.test_mask__fill_argc           
      C   s   d\}}||f}|| dd}|  D ]O\}}d| }tjj||d}tjj||d}	| |tjj| | |	tjj| | | || | |	 || | | || | |	 || qdS )z:Ensure masks are created correctly using the size keyword.)I   S   r   rp   rq   rs   r   )r   rs   Nrt   )
rd   r2   r3   rf   rw   rs   re   rO   rg   rh   r   r   r   test_mask__size_kwarg   s   
z"MaskTypeTest.test_mask__size_kwargc                 C   s   dD ]H}dD ]C}t j||f}t|D ]}t|d@ |dD ]	}|||f qq| t|fD ]}| |t jj | || t| || q2qqdS )z:Ensures copy works correctly with some bits set and unset.       !   ?   @   A   r   r	   N)	r
   r!   r   r   r   copyrc   assertIsNotrT   )rd   r2   r3   r!   r   r   	mask_copyr   r   r   	test_copy   s   zMaskTypeTest.test_copyc                 C   sl   dD ]1}dD ],}t jj||fdd}| t|fD ]}| |t jj | || t| || qqqdS )z0Ensures copy works correctly on a filled masked.r   Trr   Nr
   r!   r   r   rc   r   rT   rd   r2   r3   r!   r   r   r   r   test_copy__full  s   zMaskTypeTest.test_copy__fullc                 C   sh   dD ]/}dD ]*}t j||f}| t|fD ]}| |t jj | || t| || qqqdS )z.Ensures copy works correctly on an empty mask.r   Nr   r   r   r   r   test_copy__empty  s   zMaskTypeTest.test_copy__emptyc                 C   s   d}d}t jd}| t|f}|| |D ]%}|| | || | |||| | |||| qdS )z3Ensures copy makes an independent copy of the mask.)r   r   )r   r	   r   r   N)r
   r!   r   r   r   r   ZassertNotEqualr   )rd   Zmask_set_posZmask_copy_set_posr!   Zmask_copiesr   r   r   r   test_copy__independent'  s   

z#MaskTypeTest.test_copy__independentc                 C   s$   d}t j|}| | | dS )z,Ensure a mask's size is correctly retrieved.)]   e   N)r
   r!   r   rE   r   )rd   rf   r!   r   r   r   test_get_size<  s   zMaskTypeTest.test_get_sizec                 C   s@   t dd}dD ]}t jj|j|d}| }| || qdS )z!Ensures get_rect works correctly.r*   r`      rp   rr   N)r
   r&   r!   r   r   rC   rE   )rd   expected_rectrs   r!   r:   r   r   r   test_get_rectC  s   zMaskTypeTest.test_get_rectc                 C   s   d}d}|d|dddgt ddfi}d	}tj|}| D ]*\}}|D ]#}|D ]}	td
|}
t|
||	 |jdi ||	i}| ||
 q(q$qdS )ziEnsures get_rect supports a single rect attribute kwarg.

        Tests all the rect attributes.
        )r   r   r7   r6   r9   r8   centerxZcenteryr2   r3   wh)
topleft
bottomlefttoprightbottomrightZmidtopmidleft	midbottomZmidrightcenterr   )r   gffffff@)r   g@gffffff@r   r   r      r   r*   Nr   )	r   r
   r!   r   ru   r&   setattrrC   rE   )rd   ZRECT_SINGLE_VALUE_ATTRIBUTESZRECT_DOUBLE_VALUE_ATTRIBUTESZrect_attributesr   r!   
attributesvalues	attributevaluer   r:   r   r   r   test_get_rect__one_kwargO  s"   z%MaskTypeTest.test_get_rect__one_kwargc                 C   sh   t jd}t dd}ddtddd}| D ]
\}}t||| q|jd	i |}| || dS )
z9Ensures get_rect supports multiple rect attribute kwargs.   ry   r*   gffffff@rZ   r	   g	@)r   r7   r   Nr   )	r
   r!   r   r&   r   ru   r   rC   rE   )rd   r!   r   kwargsZattribr   r:   r   r   r   test_get_rect__multiple_kwargs  s   z+MaskTypeTest.test_get_rect__multiple_kwargsc                 C   sz   t jd}| t |d}W d   n1 sw   Y  | t |d}W d   dS 1 s6w   Y  dS )z&Ensures get_rect only supports kwargs.ry   r   r   Nr   r	   r
   r!   r   rj   	TypeErrorrC   rd   r!   r:   r   r   r   test_get_rect__no_arg_support  s   "z*MaskTypeTest.test_get_rect__no_arg_supportc                 C   s   t jd}| t |jdd}W d   n1 sw   Y  | t |jdd}W d   n1 s7w   Y  | t |jdd}W d   dS 1 sSw   Y  dS )	z(Ensures get_rect detects invalid kwargs.r   r`   )ZrighteNrW   )Ztoplefr   r	   )move)r
   r!   r   rj   AttributeErrorrC   r   r   r   r   !test_get_rect__invalid_kwarg_name  s   "z.MaskTypeTest.test_get_rect__invalid_kwarg_namec                 C   s  t jd}| t |jdd}W d   n1 sw   Y  | t |jdd}W d   n1 s7w   Y  | t |jdd}W d   n1 sRw   Y  | t |jd	d
}W d   n1 smw   Y  | t |jdd}W d   n1 sw   Y  | t |jdd}W d   n1 sw   Y  | t |jdd}W d   dS 1 sw   Y  dS )z/Ensures get_rect detects invalid kwarg formats.)r   r`   1)r8   Nr   )r9   rW   )r   )r   r   )r   )r   r   r	   r   )r   r   )r   r   r   r   r   r   #test_get_rect__invalid_kwarg_format  s,   "z0MaskTypeTest.test_get_rect__invalid_kwarg_formatc                 C   s   d\}}t j||f}t jj||fdd}d}d}|d |d f}| ||| | |j|d| | |t|| | |jt|d| dS )z4Ensure individual mask bits are correctly retrieved.r   r   Trr   r   r   )rK   N)r
   r!   r   rE   r   r   )rd   r2   r3   mask0rg   Zmask0_expected_bitZmask1_expected_bitrK   r   r   r   test_get_at  s   zMaskTypeTest.test_get_atc                 C      d\}}t j||f}| t ||df W d   n1 s#w   Y  | t |d|f W d   n1 s?w   Y  | t |d W d   n1 sYw   Y  | t |d W d   dS 1 stw   Y  dS )zEnsure get_at() checks bounds.r`   r   r   Nr]   r[   r
   r!   r   rj   
IndexErrorr   rd   r2   r3   r!   r   r   r   test_get_at__out_of_bounds     "z'MaskTypeTest.test_get_at__out_of_boundsc           	      C   s   d\}}t j||f}t jj||fdd}d}| }d}|d |d f}||| |jt||d | ||| | | | | ||| | | | dS )z)Ensure individual mask bits are set to 1.r      Trr   r   )rK   r   N)r
   r!   r   rP   r   r   rE   r   	rd   r2   r3   r   rg   Zmask0_expected_countZmask1_expected_countexpected_bitrK   r   r   r   test_set_at  s   zMaskTypeTest.test_set_atc           	      C   s   d\}}t j||f}t jj||fdd}d}| d }d}|d |d f}||| ||| | ||| | | | | ||| | | | dS )z)Ensure individual mask bits are set to 0.r`   r   Trr   r   r   Nr
   r!   r   rP   r   rE   r   r   r   r   r   test_set_at__to_0  s   zMaskTypeTest.test_set_at__to_0c           	      C   s   d\}}t j||f}t jj||fdd}d}| }d}|d |d f}|| || | ||| | | | | ||| | | | dS )z<Ensure individual mask bits are set using the default value.)r      Trr   r   Nr   r   r   r   r   test_set_at__default_value	  s   

z'MaskTypeTest.test_set_at__default_valuec                 C   r   )zEnsure set_at() checks bounds.r   r   Nr]   r[   r
   r!   r   rj   r   r   r   r   r   r   test_set_at__out_of_bounds  r   z'MaskTypeTest.test_set_at__out_of_boundsc                 C   s   d}d}d}d|i}dD ]_}t jj||d}| }dD ]N}||f}	d|	 }
t jj||d}| }||	|}|||}| |||
 | | ||
 | | ||
 | | ||
 | | ||
 qqdS )aX  Ensure the overlap intersection is correctly calculated.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap 1 (mask2-filled)
            (mask1-empty)  0 overlap 1 (mask2-filled)
            (mask1-filled) 1 overlap 0 (mask2-empty)
            (mask1-empty)  0 overlap 0 (mask2-empty)
        ry   ry   r*   NTTrp   rr   key=)r
   r!   r   rP   getoverlaprE   r   )rd   rf   offsetexpected_defaultZexpected_overlapsfill2rh   mask2_countfill1r"   rO   rg   mask1_countexpected_posoverlap_posr   r   r   test_overlap,  s*   	
zMaskTypeTest.test_overlapc                 C   s   t jjddd}t jjddd}| }| }| }| }| jD ]G}d| }t|d dt|d df}	|j||d}
| |
|	| | | || | | || | | || | | || q#d	S )
z>Ensure an offset overlap intersection is correctly calculated.r   Trr   rz   ry   offset=r   r   otherr   N)	r
   r!   r   rP   r   ORIGIN_OFFSETSr%   r   rE   )rd   rg   rh   r   r   
mask1_size
mask2_sizer   rO   r   r   r   r   r   test_overlap__offsetO  s    

z!MaskTypeTest.test_overlap__offsetc                 C   sT  t jjddd}t jjddd}d}||d ||d | }| }| }| }| jD ]v}d| }	|\}
}t|d}d|krMt|
d d}nd|k rYt|
d d}nt|
d}||t	|}| 
|||f|	 | 
| ||	 | 
| ||	 | 
| ||	 | 
| ||	 | 
||d|	 | 
||d|	 q1d	S )
z_Ensure an offset overlap intersection is correctly calculated
        when (0, 0) bits not set.r   Trr   r   r*   r   r   r   N)r
   r!   r   r   rP   r   r   r%   r   r   rE   r   )rd   rg   rh   	unset_posr   r   r   r   r   rO   r   r   Z
expected_yZ
expected_xr   r   r   r   $test_overlap__offset_with_unset_bitsf  s6   



z1MaskTypeTest.test_overlap__offset_with_unset_bitsc                 C   s   t jjddd}| }| }d\}}||f}t j|}|d |d f}|| d}	| jD ]A}
d|
 }|||
}| || | 	| || | 	| |	| | 	| || | 	| || | 	|
|d| q0dS )z_Ensure an offset overlap intersection is correctly calculated
        when there is no overlap.r   Trr   )C   r   r   r   N)r
   r!   r   rP   r   r   r   r   assertIsNonerE   r   )rd   rg   r   r   Zmask2_wZmask2_hr   rh   set_posr   r   rO   r   r   r   r   test_overlap__no_overlap  s&   


z%MaskTypeTest.test_overlap__no_overlapc                 C   s   t jjddd}t jjddd}| }| }| }| }|d dfd|d f|d  dfd|d  ff}|D ]7}d| }	|||}
| |
|	 | | ||	 | | ||	 | | ||	 | | ||	 q:dS )	z9Ensures overlap handles offsets and boundaries correctly.)r   r   Trr   r   r   r   r   r   N)r
   r!   r   rP   r   r   r   rE   )rd   rg   rh   r   r   r   r   offsetsr   rO   r   r   r   r   test_overlap__offset_boundary  s(   


z*MaskTypeTest.test_overlap__offset_boundaryc                 C   s   t ddD ]o}t ddD ]g}||f}|| }tjj|dd}tjj|dd}| jD ]I}d| d| }t|d dt|d	 df}	|||}
| |
|	| | | || | | || | |	 || | |	 || q)qqd
S )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	   ry   rz   Trr   r{   	, offset=r   r   N)
r   r
   r!   r   r   r%   r   rE   rP   r   )rd   r3   r2   	mask_size
mask_countrg   rh   r   rO   r   r   r   r   r   test_overlap__bit_boundaries  s$   
z)MaskTypeTest.test_overlap__bit_boundariesc                 C   Z   d}d}t j|}t |}| t |||}W d   dS 1 s&w   Y  dS )z8Ensure overlap handles invalid mask arguments correctly.r   r   r*   N)r
   r!   r   Surfacerj   r   r   )rd   r   r   r!   invalid_maskr   r   r   r   test_overlap__invalid_mask_arg  s   
"z+MaskTypeTest.test_overlap__invalid_mask_argc                 C   \   d}d}t j|}t j|}| t |||}W d   dS 1 s'w   Y  dS )z:Ensure overlap handles invalid offset arguments correctly.)r	   r   (0, 0)N)r
   r!   r   rj   r   r   )rd   r   r   rg   rh   r   r   r   r    test_overlap__invalid_offset_arg     "z-MaskTypeTest.test_overlap__invalid_offset_argc                 C   s   d }\}}d}d}d|| i}dD ]_}t jj||d}| }	dD ]N}
|
|f}d| }t jj||
d}| }|||}|||}| ||| | | || | | |	| | | || | | || q"qdS )	ad  Ensure the overlap_area is correctly calculated.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap_area 1 (mask2-filled)
            (mask1-empty)  0 overlap_area 1 (mask2-filled)
            (mask1-filled) 1 overlap_area 0 (mask2-empty)
            (mask1-empty)  0 overlap_area 0 (mask2-empty)
        r   r*   r   r   rp   rr   r   N)r
   r!   r   rP   r   rQ   rE   r   )rd   rf   r2   r3   r   r   Zexpected_countsr   rh   r   r   r"   rO   rg   r   re   overlap_countr   r   r   test_overlap_area  s*   

zMaskTypeTest.test_overlap_areac                 C   s   t jjddd}t jjddd}| }| }| }| }| }| }| jD ]G}	d|	 }
|	|_||}|j	|j
 }|j||	d}| |||
 | | ||
 | | ||
 | | ||
 | | ||
 q+dS )z6Ensure an offset overlap_area is correctly calculated.r   Trr   r   r   r   N)r
   r!   r   rP   r   rC   r   r   rB   r   r   rQ   rE   )rd   rg   rh   r   r   r   r   rect1rect2r   rO   overlap_rectre   r  r   r   r   test_overlap_area__offset  s(   


z&MaskTypeTest.test_overlap_area__offsetc                 C   s   t jjddd}t jjddd}| }| }| }| }d}|d dfd|d f|d  dfd|d  ff}|D ]:}	d|	 }
||t|	}| |||
 | | ||
 | | ||
 | | ||
 | | ||
 q<dS )	z>Ensures overlap_area handles offsets and boundaries correctly.r   Trr   r   r   r   r   N)r
   r!   r   rP   r   rQ   r   rE   )rd   rg   rh   r   r   r   r   re   r   r   rO   r  r   r   r   "test_overlap_area__offset_boundary9  s*   


z/MaskTypeTest.test_overlap_area__offset_boundaryc                 C   s   t ddD ]w}t ddD ]o}||f}|| }tjj|dd}tjj|dd}| }| }| jD ]I}	d| d|	 }
|	|_||}|j|j	 }|
||	}| |||
 | | ||
 | | ||
 | | ||
 | | ||
 q1qqdS )	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	   ry   rz   Trr   r{   r   N)r   r
   r!   r   rC   r   r   rB   r   r   rQ   rE   rP   r   )rd   r3   r2   r   r   rg   rh   r  r  r   rO   r  Zexpected_overlap_countr  r   r   r   !test_overlap_area__bit_boundariesX  s,   

z.MaskTypeTest.test_overlap_area__bit_boundariesc                 C   r   )z=Ensure overlap_area handles invalid mask arguments correctly.r   r   r*   N)r
   r!   r   r   rj   r   rQ   )rd   r   r   r!   r   r  r   r   r   #test_overlap_area__invalid_mask_arg|     
"z0MaskTypeTest.test_overlap_area__invalid_mask_argc                 C   r   )z?Ensure overlap_area handles invalid offset arguments correctly.)r   r	   r   N)r
   r!   r   rj   r   rQ   )rd   r   r   rg   rh   r  r   r   r   %test_overlap_area__invalid_offset_arg  r  z2MaskTypeTest.test_overlap_area__invalid_offset_argc                 C   s  d}d}t j|}dt jj|ddi}dD ]i}t jj||d}| }dD ]X}||f}	d|	 }
t jj||d}| }||	|}|j||d}| |t jj|
 t| |||
 | | ||
 | | ||
 | |	 ||
 | |	 ||
 q&qd	S )
ad  Ensure overlap_mask's mask has correct bits set.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 overlap_mask 1 (mask2-filled)
            (mask1-empty)  0 overlap_mask 1 (mask2-filled)
            (mask1-filled) 1 overlap_mask 0 (mask2-empty)
            (mask1-empty)  0 overlap_mask 0 (mask2-empty)
        r   r*   r   Trr   rp   r   r   N)
r
   r!   r   rP   r   overlap_maskrc   rT   rE   r   )rd   rf   r   r   expected_masksr   rh   r   r   r"   rO   rg   r   expected_maskr  r   r   r   test_overlap_mask  s,   	
zMaskTypeTest.test_overlap_maskc           
      C   s  t jjddd}t jjddd}| }| }| }| }||d}tdD ]}tdD ]}	| |||	fdd	| d
|	 d q0q*tdD ]}tddD ]}	| |||	fdd	| d
|	 d qRqK| | | | | | | | | | | | dS )z0Ensure overlap_mask's mask has correct bits set.2   r  Trr   )i,  
   r]   r  r  r   (, )r`   r   N)	r
   r!   r   rP   r   r  r   rE   r   )
rd   rg   rh   r   r   r   r   Zmask3r   jr   r   r   test_overlap_mask__bits_set  s&   ((z(MaskTypeTest.test_overlap_mask__bits_setc                 C   s  t jjddd}t jjddd}| }| }| }| }t |}| }| }	| jD ]Z}
d|
 }|
|	_||	}|	  |
t j|jdd|j |||
}| |t jj| t| ||| | | || | | || | | || | | || q0dS )z=Ensure an offset overlap_mask's mask is correctly calculated.r   Trr   r   r   N)r
   r!   r   rP   r   rC   r   r   rB   cleardrawr   r  rc   rT   rE   )rd   rg   rh   r   r   r   r   r  r  r  r   rO   r  r  r   r   r   test_overlap_mask__offset  s2   



z&MaskTypeTest.test_overlap_mask__offsetc                 C   s   t jjddd}t jjddd}t | }| }| }|dd}dD ]?}t||t|| |j}d| }	|	|}
|
  |t j|
jdd|
j |||}| |t jj|	 t| |||	 q'dS )	a  Ensure an offset overlap_mask's mask is correctly calculated.

        Testing the specific case of:
            -both masks are wider than 32 bits
            -a positive offset is used
            -the mask calling overlap_mask() is wider than the mask passed in
        r   r   Trr   r   r   r   r   r   r   r   N)r
   r!   r   r   rC   inflater   getattrr   rB   r  r  r   r  rc   rT   )rd   rg   rh   r  r  r  corner_rectcornerr   rO   r  r  r   r   r   #test_overlap_mask__specific_offsets  s&   	

z0MaskTypeTest.test_overlap_mask__specific_offsetsc                 C   s  t jjddd}t jjddd}| }| }| }| }d}|}|d dfd|d f|d  dfd|d  ff}	|	D ]L}
d|
 }|||
}| |t jj| | | || | | || | | || | | || | | || | | || q>dS )	z>Ensures overlap_mask handles offsets and boundaries correctly.)	   r   Trr   )r`   r   r   r   r   N)r
   r!   r   rP   r   r  rc   rE   )rd   rg   rh   r   r   r   r   re   rf   r   r   rO   r  r   r   r   "test_overlap_mask__offset_boundary  s0   


z/MaskTypeTest.test_overlap_mask__offset_boundaryc              	   C   s0  t ddD ]}t ddD ]}||f}|| }tjj|dd}tjj|dd}t|}| }| }	| jD ]]}
d| d|
 }|
|	_||	}|  |	tj|j
dd|j |||
}| |tjj| t| ||| | | || | | || | | || | | || q6qqdS )	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	   ry   rz   Trr   r{   r   N)r   r
   r!   r   rC   r   r   rB   r  r  r   r  rc   rT   rE   rP   r   )rd   r3   r2   r   r   rg   rh   r  r  r  r   rO   r  r  r   r   r   !test_overlap_mask__bit_boundaries6  s6   


z.MaskTypeTest.test_overlap_mask__bit_boundariesc                 C   r   )z=Ensure overlap_mask handles invalid mask arguments correctly.r   r*   N)r
   r!   r   r   rj   r   r  )rd   r   r   r!   r   r  r   r   r   #test_overlap_mask__invalid_mask_arg_  r  z0MaskTypeTest.test_overlap_mask__invalid_mask_argc                 C   r   )z?Ensure overlap_mask handles invalid offset arguments correctly.r   r	   r   N)r
   r!   r   rj   r   r  )rd   r   r   rg   rh   r  r   r   r   %test_overlap_mask__invalid_offset_argi  r  z2MaskTypeTest.test_overlap_mask__invalid_offset_argc                    s   t d  dd |  dd  dd |  dd | t fdd | t fdd | t fdd | t fd	d d
S )z/do the set_at, and get_at parts work correctly?r  r  r*   r   )r&  r   c                      s
     dS )Nr]   )r   r   r   r   r   <lambda>  s   
 z/MaskTypeTest.test_mask_access.<locals>.<lambda>c                           ddS )Nr]   r   r   r   r-  r   r   r.        c                      r/  )Nr  r   r   r0  r   r-  r   r   r.    r1  c                      r/  )Nr   r  r   r0  r   r-  r   r   r.    r1  N)r
   r   r   rE   r   rj   r   rd   r   r-  r   test_mask_accesss  s   
zMaskTypeTest.test_mask_accessc                 C   sP   d\}}|| }||f}t j|}|  | | | | | | dS )zEnsure a mask can be filled.r_   N)r
   r!   r   rs   rE   rP   r   )rd   r2   r3   re   rf   r!   r   r   r   	test_fill     zMaskTypeTest.test_fillc                 C   sd   t ddD ]*}t ddD ]"}tj||f}|| }|  | | |d| d| d qqdS )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   ry   rz   size=(r  r  N)r   r
   r!   r   rs   rE   rP   )rd   r3   r2   r!   re   r   r   r   test_fill__bit_boundaries  s   z&MaskTypeTest.test_fill__bit_boundariesc                 C   D   d}d}t jj|dd}|  | | | | | | dS )zEnsure a mask can be cleared.r   r      Trr   N)r
   r!   r   r  rE   rP   r   rd   re   rf   r!   r   r   r   
test_clear     zMaskTypeTest.test_clearc                 C   sd   d}t ddD ](}t ddD ] }tjj||fdd}|  | | |d| d| d	 qqd
S )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   ry   rz   Trr   r8  r  r  N)r   r
   r!   r   r  rE   rP   )rd   re   r3   r2   r!   r   r   r   test_clear__bit_boundaries  s   z'MaskTypeTest.test_clear__bit_boundariesc           
      C   s  d}||f}t j|}t jj|dd}|| }d}t|D ]}|d8 }|d7 }||f}|| ||d q|  |  | | | | | | | | | | | | t|D ]}||f}d| }	| |	|d|	 | |	|d|	 qddS )zEnsure a mask can be inverted.r   Trr   r   r   zpos=N)
r
   r!   r   r   r   invertrE   rP   r   r   )
rd   siderf   rg   rh   Zexpected_count1Zexpected_count2r   rK   rO   r   r   r   test_invert  s0   

zMaskTypeTest.test_invertc                 C   r:  )z#Ensure a full mask can be inverted.r   +   a   Trr   Nr
   r!   r   rA  rE   rP   r   r=  r   r   r   test_invert__full  r?  zMaskTypeTest.test_invert__fullc                 C   sP   d\}}||f}|| }t j|}|  | | | | | | dS )z%Ensure an empty mask can be inverted.rD  NrG  )rd   r2   r3   rf   re   r!   r   r   r   test_invert__empty  r7  zMaskTypeTest.test_invert__emptyc                 C   s   dD ];}t ddD ]3}t ddD ]+}tjj||f|d}|r dn|| }|  | | |d| d| d	| d
 qq	qdS )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)
        rp   r   ry   rz   rr   r   rq   , size=(r  r  N)r   r
   r!   r   rA  rE   rP   )rd   rs   r3   r2   r!   re   r   r   r   test_invert__bit_boundaries  s   z(MaskTypeTest.test_invert__bit_boundariesc                 C   s   d\}}||f}dD ]m}t jj||d}|r|| nd}t|d |d D ]Q}t|d |d D ]E}||f}	|r<|| nd}
d|	 }|j|	d}| |t jj| | | |
| | | |	 | | || | | || q0q%q
dS )	zEnsure a mask can be scaled.)rE  =   rp   rr   r   r  r{   )scaleN)	r
   r!   r   r   rM  rc   rE   rP   r   )rd   r2   r3   original_sizers   original_maskoriginal_countZnew_wZnew_hrf   re   rO   r!   r   r   r   
test_scale  s&   
zMaskTypeTest.test_scalec                 C   s   t d}| t |d W d   n1 sw   Y  | t |tdd W d   n1 s7w   Y  | t |d W d   dS 1 sRw   Y  dS )z.Ensure scale handles negative sizes correctly.r   r\   NrZ   r  )r  rZ   )r
   r   rj   rk   rM  r   rd   r!   r   r   r   test_scale__negative_size,  s   
"z&MaskTypeTest.test_scale__negative_sizec                 C   s   d}d}t jj|dd}dt j|i}dD ]I}t jj||d}| }dD ]8}||f}	d|	 }
t jj||d}||	|}||| t| |||
 | | ||
 | | ||
 q&qdS )	aA  Ensure a mask can be drawn onto another mask.

        Testing the different combinations of full/empty masks:
            (mask1-filled) 1 draw 1 (mask2-filled)
            (mask1-empty)  0 draw 1 (mask2-filled)
            (mask1-filled) 1 draw 0 (mask2-empty)
            (mask1-empty)  0 draw 0 (mask2-empty)
        r   r*   Trr   )FFrp   r   N)	r
   r!   r   rP   r   r  rT   rE   r   rd   rf   r   r   r  r   rh   r   r   r"   rO   rg   r  r   r   r   	test_draw9  s$   	
zMaskTypeTest.test_drawc                 C   s   t jd}t jjddd}| }| }t | }| }| }| jD ]R}d| }	||_||}
|	  t
|
j|
jD ]}t
|
j|
jD ]	}|||f qKqB|	  |j||d t| |||	 | | ||	 | | ||	 q(dS )z5Ensure an offset mask can be drawn onto another mask.r   r   Trr   r   r   N)r
   r!   r   rP   r   rC   r   r   rB   r  r   r6   r8   r7   r9   r   r  rT   rE   rd   rg   rh   r   r   r  r  r  r   rO   r  r   r   r   r   r   test_draw__offsetY  s,   


zMaskTypeTest.test_draw__offsetc                 C   s   t jd}t jjddd}t | }| }| }|dd}dD ]H}t||t|| |j}d| }	|	|}
|
  t|
j|
jD ]}t|
j|
jD ]	}|||f qQqH|
  ||| t| |||	 q%dS )	a  Ensure an offset mask can be drawn onto another mask.

        Testing the specific case of:
            -both masks are wider than 32 bits
            -a positive offset is used
            -the mask calling draw() is wider than the mask passed in
        r  r  Trr   r  r   r   N)r
   r!   r   r   rC   r!  r   r"  r   rB   r  r   r6   r8   r7   r9   r   r  rT   rd   rg   rh   r  r  r  r#  r$  r   rO   r  r   r   r   r   r   test_draw__specific_offsetsz  s(   

z(MaskTypeTest.test_draw__specific_offsetsc           
      C   s   t jd}t jjddd}| }| }| }| }|d dfd|d f|d  dfd|d  ff}|D ]1}d| }	||| | | ||	 | | ||	 | | ||	 | | ||	 q8dS )	z6Ensures draw handles offsets and boundaries correctly.)r   r   r   Trr   r   r   r   N)r
   r!   r   rP   r   r  rE   
rd   rg   rh   r   r   r   r   r   r   rO   r   r   r   test_draw__offset_boundary  s&   


z'MaskTypeTest.test_draw__offset_boundaryc              	   C   s  t ddD ]}t ddD ]}}||f}|| }tj|}tjj|dd}t|}| }| }	| jD ]T}
d| d|
 }|
|	_||	}|  t |j	|j
D ]}t |j|jD ]	}|||f qZqQ|  |||
 t| ||| | | || | | || q4qqdS )	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	   ry   rz   Trr   r{   r   N)r   r
   r!   r   rC   r   r   rB   r  r6   r8   r7   r9   r   r  rT   rE   rP   r   rd   r3   r2   r   r   rg   rh   r  r  r  r   rO   r  r   r   r   r   r   test_draw__bit_boundaries  s4   


z&MaskTypeTest.test_draw__bit_boundariesc                 C   Z   d}d}t j|}t |}| t ||| W d   dS 1 s&w   Y  dS )z5Ensure draw handles invalid mask arguments correctly.r   r*   N)r
   r!   r   r   rj   r   r  rd   r   r   r!   r   r   r   r   test_draw__invalid_mask_arg  r  z(MaskTypeTest.test_draw__invalid_mask_argc                 C   \   d}d}t j|}t j|}| t ||| W d   dS 1 s'w   Y  dS )z7Ensure draw handles invalid offset arguments correctly.r   r   N)r
   r!   r   rj   r   r  rd   r   r   rg   rh   r   r   r   test_draw__invalid_offset_arg  r  z*MaskTypeTest.test_draw__invalid_offset_argc                 C   s   d}d}t j|}dt jj|ddi}dD ]I}t jj||d}| }dD ]8}||f}	d|	 }
t jj||d}||	|}||| t| |||
 | | ||
 | | ||
 q&qdS )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*   rp   Trr   r   N)	r
   r!   r   rP   r   eraserT   rE   r   rT  r   r   r   
test_erase  s$   	
zMaskTypeTest.test_erasec                 C   s   t jd}t jjddd}| }| }t | }| }| }| jD ]S}d| }	||_||}
|	  t
|
j|
jD ]}t
|
j|
jD ]
}|||fd qKqB|	  |j||d t| |||	 | | ||	 | | ||	 q(dS )	z-Ensure an offset mask can erase another mask.r   r   Trr   r   r   r   N)r
   r!   r   rP   r   rC   r   r   rB   rs   r   r6   r8   r7   r9   r   rd  rT   rE   rV  r   r   r   test_erase__offset  s,   


zMaskTypeTest.test_erase__offsetc                 C   s   t jd}t jjddd}t | }| }| }|dd}dD ]K}t||t|| |j}d| }	|	|}
|
  t|
j|
jD ]}t|
j|
jD ]
}|||fd qQqH|
  ||t| t| |||	 q%d	S )
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  Trr   r  r   r   r   N)r
   r!   r   r   rC   r!  r   r"  r   rB   rs   r   r6   r8   r7   r9   r   rd  r   rT   rX  r   r   r   test_erase__specific_offsets<  s(   

z)MaskTypeTest.test_erase__specific_offsetsc           
      C   s   t jjddd}t jjddd}| }| }| }| }|d dfd|d f|d  dfd|d  ff}|D ]1}d| }	||| | | ||	 | | ||	 | | ||	 | | ||	 q:dS )	z7Ensures erase handles offsets and boundaries correctly.r   r`   Trr   )r   r   r   r   r   N)r
   r!   r   rP   r   rd  rE   rZ  r   r   r   test_erase__offset_boundaryb  s&   


z(MaskTypeTest.test_erase__offset_boundaryc              	   C   s  t ddD ]}t ddD ]~}||f}|| }tj|}tjj|dd}t|}| }| }	| jD ]U}
d| d|
 }|
|	_||	}|  t |j	|j
D ]}t |j|jD ]
}|||fd qZqQ|  |||
 t| ||| | | || | | || q4qqd	S )
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	   ry   rz   Trr   r{   r   r   N)r   r
   r!   r   rC   r   r   rB   rs   r6   r8   r7   r9   r   rd  rT   rE   rP   r   r\  r   r   r   test_erase__bit_boundaries~  s4   


z'MaskTypeTest.test_erase__bit_boundariesc                 C   r^  )z6Ensure erase handles invalid mask arguments correctly.r   r   r*   N)r
   r!   r   r   rj   r   rd  r_  r   r   r   test_erase__invalid_mask_arg  r  z)MaskTypeTest.test_erase__invalid_mask_argc                 C   ra  )z8Ensure erase handles invalid offset arguments correctly.r   r   N)r
   r!   r   rj   r   rd  rb  r   r   r   test_erase__invalid_offset_arg  r  z+MaskTypeTest.test_erase__invalid_offset_argc                 C   sh   d}||f}d}t j|}t|D ]}|d7 }|||f q| }| || | | | dS )z/Ensure a mask's set bits are correctly counted.r   r   r   N)r
   r!   r   r   r   rP   rE   r   )rd   rB  rf   re   r!   r   rP   r   r   r   
test_count  s   zMaskTypeTest.test_countc                    s   dD ]`}t ddD ]X}t ddD ]P tjj |f|d}|r" | nd} fddt |D D ]0}|r>||d |d8 }n
||d |d7 }| }| ||d	| d
  d| d|  q/qq	qdS )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)
        rp   r   ry   rz   rr   r   c                 3   &    | ]}t  D ]}||fV  qqd S r=   r   r>   r2   r   r   r1        $ z:MaskTypeTest.test_count__bit_boundaries.<locals>.<genexpr>rq   rJ  r  z), pos=N)r   r
   r!   r   r   rP   rE   )rd   rs   r3   r!   re   rK   rP   r   rq  r   test_count__bit_boundaries  s*   
z'MaskTypeTest.test_count__bit_boundariesc                 C   sP   d\}}||f}|| }t jj|dd}| }| || | | | dS )z4Ensure a full mask's set bits are correctly counted.)r   rF  Trr   Nr
   r!   r   rP   rE   r   )rd   r2   r3   rf   re   r!   rP   r   r   r   test_count__full_mask  s   z"MaskTypeTest.test_count__full_maskc                 C   <   d}d}t j|}| }| || | | | dS )z6Ensure an empty mask's set bits are correctly counted.r   r;  Nrt  )rd   re   rf   r!   rP   r   r   r   test_count__empty_mask     z#MaskTypeTest.test_count__empty_maskc                 C   s2   t jjddd}| j}| }| || dS )z8Ensure a filled mask's centroid is correctly calculated.r   Trr   N)r
   r!   r   rC   r   centroidrE   )rd   r!   expected_centroidry  r   r   r   test_centroid  s   
zMaskTypeTest.test_centroidc                 C   rv  )z8Ensure an empty mask's centroid is correctly calculated.r*   )r   g   N)r
   r!   r   ry  rE   r   )rd   rz  rf   r!   ry  r   r   r   test_centroid__empty_mask  rx  z&MaskTypeTest.test_centroid__empty_maskc                 C   sn   d\}}t j||f}t|D ]$}|  t|D ]}|||f |d |f}| }| || qqdS )z`Ensure a mask's centroid is correctly calculated
        when setting points along a single row.r   r	   Nr
   r!   r   r   r  r   ry  rE   rd   r2   r3   r!   r   r   rz  ry  r   r   r   test_centroid__single_row     z&MaskTypeTest.test_centroid__single_rowc                 C   s   d\}}t j||f}td|D ]-}|  t|D ]"}||df |||f |d |d f}| }| || qqdS )z\Ensure a mask's centroid is correctly calculated
        when setting points along two rows.r   r   r   r	   Nr~  r  r   r   r   test_centroid__two_rows(     z$MaskTypeTest.test_centroid__two_rowsc                 C   sn   d\}}t j||f}t|D ]$}|  t|D ]}|||f ||d f}| }| || qqdS )zcEnsure a mask's centroid is correctly calculated
        when setting points along a single column.r   r	   Nr~  rd   r2   r3   r!   r   r   rz  ry  r   r   r   test_centroid__single_column;  r  z)MaskTypeTest.test_centroid__single_columnc                 C   s   d\}}t j||f}td|D ]-}|  t|D ]"}|d|f |||f |d |d f}| }| || qqdS )z_Ensure a mask's centroid is correctly calculated
        when setting points along two columns.r   r   r   r	   Nr~  r  r   r   r   test_centroid__two_columnsL  r  z'MaskTypeTest.test_centroid__two_columnsc                 C   sF   t jd}| j}t|D ]}|| q| }| || dS )zREnsure a mask's centroid is correctly calculated
        when its corners are set.r   N)	r
   r!   r   rC   r   r5   r   ry  rE   )rd   r!   rz  r$  ry  r   r   r   test_centroid__all_corners_  s   
z'MaskTypeTest.test_centroid__all_cornersc           	      C   s   t jd}| }t|}t|D ]\\}}||d d D ]O}|  || || |d |d krG|d t|d |d  d f}n|d |d kr`t|d |d  d |d f}n|j	}|
 }| || qqdS )zWEnsure a mask's centroid is correctly calculated
        when only two corners are set.r   r   Nr   r	   )r
   r!   r   rC   r5   	enumerater  r   absr   ry  rE   )	rd   r!   	mask_rectZmask_cornersr   Zcorner1Zcorner2rz  ry  r   r   r   test_centroid__two_cornersl  s"   

""z'MaskTypeTest.test_centroid__two_cornersc                 C   sB   d}d}t |}t j|}| }| |t | || dS )z:Ensure a mask's orientation angle is correctly calculated.g     Fr   N)r
   r   r!   from_surfaceanglerc   floatrE   )rd   expected_anglerf   r   r!   r  r   r   r   
test_angle  s   
zMaskTypeTest.test_anglec                 C   sH   d}d}t j|}| }| |t | || | | | dS )z5Ensure an empty mask's angle is correctly calculated.        )k   rE  N)	r
   r!   r   r  rc   r  assertAlmostEqualrE   r   )rd   r  rf   r!   r  r   r   r   test_angle__empty_mask  s   z#MaskTypeTest.test_angle__empty_maskc                 C   s   t d}| | d |  | | d t jddd}||d | | d |  | | d	 ||d
 | | d |  | | d dS )z%Test fill, clear, invert, draw, eraser   r   i'  r,  Trr   r  i&  r   r*      N)	r
   r   rE   rP   rs   rd  rA  r  r  )rd   r   rS   r   r   r   test_drawing  s   
zMaskTypeTest.test_drawingc                 C   s   t d}| | g  |dd | | dg |dd | |ddg |dd | | g d | |jdd	g d
 dS ) )   r  r,  r   r     r  r`   r`   )r,  r  r  r  r,  r	   )Zevery)r,  r  r,  N)r
   r   rE   outliner   )rd   r   r   r   r   test_outline  s   
zMaskTypeTest.test_outlinec              	   C   s   g d}|D ]9}t |}|D ]/}t |}||}| |t jj dD ]}| | | | | | |  d  q%qqd S )N)rW   )r   r   )r   r   r   rV   r   )r
   r   convolverc   r!   rE   r   )rd   r0   s1rR   s2rS   or   r   r   r   test_convolve__size  s   


$z MaskTypeTest.test_convolve__sizec                 C   sr   t d}td}|d ||}| |tjj t| || |||}| |tjj t| || dS )zaConvolving with a single point is the identity, while convolving a point with something flips it.r   rW   r*   N)r   r
   r   r   r  rc   r!   rT   )rd   r   kconvolve_maskr   r   r   test_convolve__point_identities  s   


z,MaskTypeTest.test_convolve__point_identitiesc                 C   s   t d}td}|d td}td}||| ||d | |tjj t| || |	  |	  |j||t
ddd ||d | |tjj t| || d	S )
zGchecks that convolution modifies only the correct portion of the outputr,  r	   r	   r*   r  rW   r  )r   outputr   r  N)r   r
   r   r   r  r  rc   r!   rT   r  r   )rd   r   r  r  testr   r   r   test_convolve__with_output  s   



z'MaskTypeTest.test_convolve__with_outputc                 C   sR   t jddd}d}|D ]\}}||d |}| |t jj | | | qd S )Nr  Trr   ))r   r   r   )r   r	   r   ))r  r  r   ))r  r   )r
   r   r  rc   r!   rE   rP   )rd   fullZpts_dataptre   r  r   r   r   test_convolve__out_of_range  s   z(MaskTypeTest.test_convolve__out_of_rangec                 C   s   t d}t d}||}| |tjj t| d D ]&}t| d D ]}| |	||fdk|
||d |d fdu  q'qdS )z#Tests the definition of convolutionr   r   r   c   N)r   r  rc   r
   r!   r   r   r   rE   r   r   )rd   rR   rS   convr   r  r   r   r   test_convolve  s   
*zMaskTypeTest.test_convolveFc                 C   sX   t jj||fdd}||d |d fd |r$||| |  |S ||| |S )NTrr   r	   r   )r
   r!   r   r   rd  rA  r  )rd   r!   r   rK   inversepatternr   r   r   _draw_component_pattern_box  s   z(MaskTypeTest._draw_component_pattern_boxc           	      C   s~   t j||f}|d }t|D ]}t|D ]}|||| fv r'|||f qq|r7||| |  |S ||| |S )Nr   r
   r!   r   r   r   rd  rA  r  )	rd   r!   r   rK   r  r  r(   r   r   r   r   r   _draw_component_pattern_x'  s   z&MaskTypeTest._draw_component_pattern_xc           
      C   s   t j||f}|d  }}t|D ]}t|D ]}	|	|ks"||kr)||	|f qq|r9||| |  |S ||| |S )Nr	   r  )
rd   r!   r   rK   r  r  ZxmidZymidr   r   r   r   r   _draw_component_pattern_plus=  s   z)MaskTypeTest._draw_component_pattern_plusc                 C   sT  d\}}||f}t j|}g }d}| |d|}|||f d}|| df}| |||}|||f |d |d f}| |d|}|||f |d \}	}
|	 }td	d
 |D }|	 }| 
|t jj | | | | | | | ||	|
| | | | | | | |D ]\}}| ||||  qdS )z<Ensure a mask's connected component is correctly calculated.))   r<  r*   r   ry   r   r	   r   rZ   c                 s   s    | ]	\}}|  V  qd S r=   )rP   )r,   p_r   r   r   r1   k  s    z8MaskTypeTest.test_connected_component.<locals>.<genexpr>N)r
   r!   r   r  appendr  r  rP   sumconnected_componentrc   rE   r   rQ   )rd   r2   r3   rf   rO  patternsr   r  r   expected_patternexpected_offsetre   rP  r!   r   r   r   test_connected_componentS  s>   z%MaskTypeTest.test_connected_componentc                 C   sx   d}t jj|dd}| }| }| |t jj | | | | | | | | | | | | dS )zcEnsure a mask's connected component is correctly calculated
        when the mask is full.
        )ra   r   Trr   Nr
   r!   r   rP   r  rc   rE   r   )rd   rf   rO  re   r!   r   r   r   #test_connected_component__full_mask  s   z0MaskTypeTest.test_connected_component__full_maskc                 C   sx   d}t j|}| }d}| }| |t jj | | | | | | | | | | | | dS )zdEnsure a mask's connected component is correctly calculated
        when the mask is empty.
        )rn   rE  r   Nr  )rd   rf   rO  rP  re   r!   r   r   r   $test_connected_component__empty_mask  s   z1MaskTypeTest.test_connected_component__empty_maskc                 C   s   d\}}||f}t jj|dd}|d |d }}||f}|d |d f}| j|d|dd}	d}
| }||}| |t jj | | |
 | | | | |	|	||
 | | | | | | | |	|	||
 dS )	zEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is set with a connected component of 1 bit.
        )r~   r   Trr   r	   r   r   )r  N)
r
   r!   r   r  rP   r  rc   rE   r   rQ   )rd   r2   r3   rf   rO  xsetysetr   r  r  re   rP  r!   r   r   r   %test_connected_component__one_set_bit  s0   

z2MaskTypeTest.test_connected_component__one_set_bitc                 C   s(  d}t j|}d\}}d }\}}|d |d f}t jj||fdd}	td|D ]}
td|D ]}||
|
d |d fv rE|	||
fd	 q0q)|	 }||	| ||}| |t jj | 	| | | 	|
 | | 	||	|| | 	| | | 	|
 | | 	||	|| d
S )zEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is set with a connected component of > 1 bit.
        )q   r   r   )r`   r   r   Trr   r   ry   r   N)r
   r!   r   r   r   rP   r  r  rc   rE   r   rQ   )rd   rf   rO  Zp_widthZp_heightr   r  r  r  r  r   r   re   r!   r   r   r   (test_connected_component__multi_set_bits  s6   

z5MaskTypeTest.test_connected_component__multi_set_bitsc           	      C   s   d\}}||f}t jj|dd}|d |d f}||d | }d}||}| |t jj | | | | | | | | | | | | | |	|d dS )zpEnsure a mask's connected component is correctly calculated
        when the coordinate's bit is unset.
        )m   r   Trr   r	   r   N)
r
   r!   r   r   rP   r  rc   rE   r   r   )	rd   r2   r3   rf   rO  r   rP  re   r!   r   r   r   #test_connected_component__unset_bit  s   
z0MaskTypeTest.test_connected_component__unset_bitc              	   C   s   d\}}||f}t jj|dd}| }ddd|d f|d dffD ],}| t ||}W d   n1 s9w   Y  | | | | | | q"dS )	z+Ensure connected_component() checks bounds.)   r`   Trr   r[   r]   r   r   N)	r
   r!   r   rP   rj   r   r  rE   r   )rd   r2   r3   rN  rO  rP  rK   r!   r   r   r   'test_connected_component__out_of_bounds	  s    z4MaskTypeTest.test_connected_component__out_of_boundsc           
      C   s  t d}| | g  | }| | |  |dd |dd | }| }|d}|d}|d}| | |d   | |d  d | |d  d | |g  |dd | }|d}|d	}| }|d}|jdd
}|d}| | d | | d | | d | t|d | t|d | t|d | t|d |D ]
}	| 	|	t j
j qdS )r  r,  r*   r   rW   r	   r   r   )r&  r&  r  )minimumN)r
   r   assertListEqualconnected_componentsr  rE   rP   r   lenrc   r!   )
rd   r   compcompsZcomps1Zcomps2Zcomps3Zcomp1Zcomp2r!   r   r   r   test_connected_components	  sB   







z&MaskTypeTest.test_connected_componentsc                 C   sR   g }d}d}t j|}|d}| || | | | | | | dS )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   rZ   N)r
   r!   r   r  r  rE   rP   r   )rd   expected_compsr   r   r!   connected_compsr   r   r   7test_connected_components__negative_min_with_empty_mask>	  s   
zDMaskTypeTest.test_connected_components__negative_min_with_empty_maskc                 C   sn   d}t jj|dd}| }d}|d}| t|| t| |d | | | | | | | dS )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   r`   Trr   r   r  r   N)	r
   r!   r   rP   r  rE   r  rT   r   )rd   r   r!   r   expected_lenr  r   r   r   6test_connected_components__negative_min_with_full_maskR	  s   
zCMaskTypeTest.test_connected_components__negative_min_with_full_maskc                 C   s.  d}t j|}i }t|D ]}|| t j|}|| |||< q|d d |d d f}|| t j|}|| |||< | }|d}| t|t| |D ]*}	d}
t	|
 D ]}|	|rzd}
t| |	||  ||=  nqd| |
d|  qZ| | | | | | d	S )
a  Ensures connected_components() properly handles negative min values
        when the mask has some bits set.

        Negative and zero values for the min parameter (minimum number of bits
        per connected component) equate to setting it to one.
        )r   r  r   r	   r   r  FTzmissing component for pt=N)r
   r!   r   r5   r   rP   r  rE   r  tuplekeysr   rT   
assertTruer   )rd   r   r!   r  r$  Znew_maskr   r   r  r  foundr  r   r   r   :test_connected_components__negative_min_with_some_bits_setg	  s8   






zGMaskTypeTest.test_connected_components__negative_min_with_some_bits_setc           	      C   s   g }| d | d | d | d | d | d |D ];\}}g }t|}|D ]}| t| |D ]}|| q:q/t|td}| }| t| td|d|  q"d	S )
z+Ensures get_bounding_rects works correctly.)r,  ))r*   rX   rV   )r  ))r   r   )ry   r	   ))r*   rX   rV   rW   r	   r   r   r   )r   )))r	   r   rW   r  r  r  )r   ))r   r   r  r   )r*  ))r  ry   r   rV   rW   r  r  )r   ))r*   )r  )r  )r  )r  )r"   r{   N)	r  r
   r   r)   r   sortedr  get_bounding_rectsr  )	rd   Z	mask_datar   Zrect_point_tuplesrectsr!   Zrect_pointsr  Zexpected_rectsr   r   r   test_get_bounding_rects	  sF   
z$MaskTypeTest.test_get_bounding_rectsc           
      C   s   d}d}t |td}t d}t ddft ddff}|D ]5\}}|| t jj||d	}||}	| |	| t	sG| 
t|	| | 
|	 | t| |	| q d
S )z8Ensures empty and full masks can be drawn onto surfaces.r   r   r   r   redwhiteTblackFrr   N)r
   r   SRCALPHAColorrs   r!   r   
to_surfaceassertIsIS_PYPYrE   sysgetrefcountr   rL   )
rd   expected_ref_countr   r   surface_color
test_fillsrH   rs   r!   r  r   r   r   test_to_surface
  s   


zMaskTypeTest.test_to_surfacec                 C   s   d}t }d}d}tddftddff}|D ]N\}}tjj||d}d	D ]?}	|	r0|d
}
n| }
| |
tj tsF| 	t
|
| | |
 |@  | 	|
 | | 	|
 | t| |
| q&qd
S )zAEnsures empty and full masks can be drawn onto a created surface.r	   r   r  r  Tr  Frr   rp   Nr  r
   r  r!   r   r  rc   r   r  rE   r  r  r  	get_flagsget_bitsizer   rL   )rd   r  expected_flagexpected_depthr   r  rH   rs   r!   Zuse_argr  r   r   r   test_to_surface__create_surface(
  s(   z,MaskTypeTest.test_to_surface__create_surfacec           
      C   s   d}t d}t d}d}t jj|dd}t |}d|i}dD ]8}|| |r3|jd
i |}	n||d }	| |	| tsK| 	t
|	| | 	|	 | t| |	| q!d	S )z/Ensures to_surface accepts a surface arg/kwarg.ry   r  r  r   Trr   r   rp   Nr   )r
   r  r!   r   r   rs   r  r  r  rE   r  r  r   rL   )
rd   r  rH   r  r   r!   r   r   
use_kwargsr  r   r   r   test_to_surface__surface_paramA
  s$   



z+MaskTypeTest.test_to_surface__surface_paramc                 C   s   d}t }d}td}d}tjj|dd}t|||}|| d|i}dD ]F}	|	r4|jd
i |}
n|d	|d }
| |
tj t	sN| 
t|
| | |
 |@  | 
|
 | | 
|
 | t| |
| q'd	S )z2Ensures to_surface accepts a setsurface arg/kwarg.r	   r   r  r   Trr   
setsurfacerp   Nr   r  r
   r  r!   r   r   rs   r  rc   r  rE   r  r  r  r  r  r   rL   )rd   r  r  r  rH   r   r!   r   r   r  r  r   r   r   !test_to_surface__setsurface_paramY
  s*   

z.MaskTypeTest.test_to_surface__setsurface_paramc                 C   s   d}t }d}td}d}tj|}t|||}|| d|i}dD ]G}	|	r2|jdi |}
n	|dd|d }
| |
tj t	sM| 
t|
| | |
 |@  | 
|
 | | 
|
 | t| |
| q%dS )	z4Ensures to_surface accepts a unsetsurface arg/kwarg.r	   r   r  r   unsetsurfacerp   Nr   r  )rd   r  r  r  rH   r   r!   r  r   r  r  r   r   r   #test_to_surface__unsetsurface_paramt
  s*   

z0MaskTypeTest.test_to_surface__unsetsurface_paramc           
      C   s   d}t }d}td}d}tjj|dd}d|i}dD ]H}|r(|jd
i |}	n
|d	d	d	|d }	| |	tj tsD| 	t
|	| | |	 |@  | 	|	 | | 	|	 | t| |	| qd	S )z0Ensures to_surface accepts a setcolor arg/kwarg.r	   r   r  r   Trr   setcolorrp   Nr   r  
rd   r  r  r  rH   r   r!   r   r  r  r   r   r   test_to_surface__setcolor_param
  s&   
z,MaskTypeTest.test_to_surface__setcolor_paramc                 C   sP   t d}d}t jj|dd}|jddddd}| | | t| || dS )z(Ensures the default setcolor is correct.r  rk  Trr   N)r   r   r  
unsetcolorr
   r  r!   r   r  rE   r   rL   rd   rH   r   r!   r  r   r   r   !test_to_surface__setcolor_default
  s   
z.MaskTypeTest.test_to_surface__setcolor_defaultc           
   	   C   s   d}t }d}td}d}tj|}d|i}dD ]I}|r&|jdi |}	n|dddd|d }	| |	tj tsC| 	t
|	| | |	 |@  | 	|	 | | 	|	 | t| |	| qdS )	z2Ensures to_surface accepts a unsetcolor arg/kwarg.r	   r   r  r   r  rp   Nr   r  r  r   r   r   !test_to_surface__unsetcolor_param
  s*   
z.MaskTypeTest.test_to_surface__unsetcolor_paramc                 C   sL   t d}d}t j|}|jddddd}| | | t| || dS )z*Ensures the default unsetcolor is correct.r  rk  N)r   r   r  r  r	  r
  r   r   r   #test_to_surface__unsetcolor_default
  s   
z0MaskTypeTest.test_to_surface__unsetcolor_defaultc              
   C   s   d}t }d}d}td}d}d}tj|}d|i}	dD ]N}
|
r,|}|jd
i |	}n|}|d	d	d	d	d	|	d }| |tj tsL| 	t
|| | | |@  | 	| | | 	| | t| || qd	S )z,Ensures to_surface accepts a dest arg/kwarg.r	   r   r   r   r   r   r  r*   r   destrp   Nr   r  )rd   r  r  r  default_surface_colordefault_unsetcolorr  r   r!   r   r  rH   r  r   r   r   test_to_surface__dest_param
  s2   
z(MaskTypeTest.test_to_surface__dest_paramc           	      C      t d}t d}d}t jj|dd}| }|d d |d d f}t |td	}|| |j|d
d
d
d}| 	|| | 
| | t| ||| t| ||| d
S )z$Ensures the default dest is correct.r  r  r   Trr   r   r	   r   r   Nr   r  r  r
   r  r!   r   rC   r   r  rs   r  r  rE   r   rL   rN   	rd   rH   r  r   r!   r  	surf_sizer   r  r   r   r   test_to_surface__dest_default
  s   


z*MaskTypeTest.test_to_surface__dest_defaultc                 C   s   d}t }d}d}td}d}tj|}d| i}dD ]O}	|	r,|}
|jd
i |}n|}
|dddddd	|d }| |tj t	sM| 
t|| | | |@  | 
| | | 
| | t| ||
 qdS )z-Ensures to_surface accepts an area arg/kwarg.r	   r   r  r  r   arearp   Nr*   r   )r  r
   r  r!   r   rC   r  rc   r   r  rE   r  r  r  r  r  r   rL   )rd   r  r  r  r  r  r   r!   r   r  rH   r  r   r   r   test_to_surface__area_param  s0   
z(MaskTypeTest.test_to_surface__area_paramc           	      C   r  )z$Ensures the default area is correct.r  r  r   Trr   r   r	   r   r   Nr  r  r  r   r   r   test_to_surface__area_default1  s   


z*MaskTypeTest.test_to_surface__area_defaultc                 C   s   t d}d}t jj|dd}t |}t d}| }|| dddt d	fd
|fd| fd|fd|ff}t|}|D ]$\}	}
||	 || |j	di |}| 
| | t| || q@dS )z.Ensures to_surface accepts the correct kwargs.r  r   Trr   r  NNr  r*   r  yellowr  r  r   r   Nr   )r
   r  r!   r   r   r   rs   dictpopr  rE   r   rL   )rd   rH   r   r!   r   r  r   	test_datar   namer  r  r   r   r   test_to_surface__kwargsI  s.   







z$MaskTypeTest.test_to_surface__kwargsc                 C   s   t d}d}t j|}t |td}t d}|| | }|| ddd|fdt d	fd
|fd|fdf}t|}|D ]&\}	}
|	|	 |j
di |}| |t j | | | t| || qAdS )zWEnsures to_surface accepts the correct kwargs
        when creating a surface.
        r  r   r   r  r  r  r  r  r  r  r   )r   NNr   )r
   r  r!   r   r   r  rs   r   r  r   r  rc   rE   r   rL   )rd   rH   r   r!   r   setsurface_colorr  r!  r   r"  r  r  r   r   r   &test_to_surface__kwargs_create_surfaceh  s0   



	
z3MaskTypeTest.test_to_surface__kwargs_create_surfacec                 C   sp   t d}d}t jj|dd}t |}|jd|d|t |dd}| || | | | t	| || dS )z2Ensures to_surface kwargs are not order dependent.bluer   Trr   r*   N)r  r  r  r   r  r   )
r
   r  r!   r   r   r  r  rE   r   rL   rd   rH   r   r!   r   r  r   r   r   )test_to_surface__kwargs_order_independent  s   

	z6MaskTypeTest.test_to_surface__kwargs_order_independentc              	   C   s  d}t jj|dd}t d}t |}| t |dddddd W d   n1 s.w   Y  | t |dddd| W d   n1 sLw   Y  | t |ddd|d W d   n1 sjw   Y  | t |dd|dd W d   n1 sw   Y  | t |d|ddd W d   n1 sw   Y  | t ||dddd W d   dS 1 sw   Y  dS )/Ensures to_surface detects invalid kwarg types.r   Trr   greenNr   )r
   r!   r   r  r   rj   r   r  )rd   r   r!   Zinvalid_surfZinvalid_colorr   r   r   #test_to_surface__args_invalid_types  s,   

"z0MaskTypeTest.test_to_surface__args_invalid_typesc              	   C   s   d}t j|}t |t |t |t dt ddd}dt ddt dt dd	d}d}|D ])}t|}|| ||< | t |jdi | W d
   n1 sZw   Y  q6d
S )r)  r   r*  r*   r   r   r  r  r  r  )r   r	   r   ry   )r   r  r   r  r   r   r   Nr   )	r
   r!   r   r   r  r  rj   r   r  )rd   r   r!   Zvalid_kwargsZinvalid_kwargsZkwarg_orderkwargr   r   r   r   %test_to_surface__kwargs_invalid_types  s2   
		z2MaskTypeTest.test_to_surface__kwargs_invalid_typesc                 C   sZ   t jd}dt di}| t |jdi | W d   dS 1 s&w   Y  dS )z/Ensures to_surface detects invalid kwarg names.r   Z	setcolourr  Nr   )r
   r!   r   r  rj   r   r  )rd   r!   r   r   r   r   $test_to_surface__kwargs_invalid_name  s
   "z1MaskTypeTest.test_to_surface__kwargs_invalid_namec                 C   s  d}t d}t d}t d}t d}t d}t |td}| }| }	|| |	| t jj|dd	}
|}d
d|fd|fd|	fd|fd|fdf}g }t|}|D ]%\}}|durf|	| |
| || |
j|i |}t| || qYdS )z7Ensures to_surface accepts a combination of args/kwargsr   r  r  r&  r*  cyanr   Trr   r  r   r   r  r  r  r  N)r
   r  r   r  r   rs   r!   r   r  r  r   r  rL   )rd   r   r  r$  unsetsurface_colorr  r  r   r   r  r!   rH   r!  argsr   r"  r   r  r   r   r    test_to_surface__args_and_kwargs  s>   










z-MaskTypeTest.test_to_surface__args_and_kwargsc                 C   sj   d}t jj|dd}t |td}t d}dd|||ddd	f}|D ]}|j|d
}t| || q$dS )z<Ensures to_surface handles valid setcolor formats correctly.r   Trr   r   r*  r      r   r   r7  r   r7  	#00FF00FF
0x00FF00FFr  N	r
   r!   r   r   r  r  Zmap_rgbr  rL   )rd   r   r!   r   rH   test_colorsr  r  r   r   r   'test_to_surface__valid_setcolor_formats  s    

z4MaskTypeTest.test_to_surface__valid_setcolor_formatsc                 C   sf   d}t j|}t |td}t d}dd|||dddf}|D ]}|j|d}t| || q"d	S )
z>Ensures to_surface handles valid unsetcolor formats correctly.r   r   r*  r6  r8  r9  r:  r  Nr<  )rd   r   r!   r   rH   r=  r  r  r   r   r   )test_to_surface__valid_unsetcolor_formats-  s    

z6MaskTypeTest.test_to_surface__valid_unsetcolor_formatsc              	   C      t jd}dD ]}| t |j|d W d   n1 s w   Y  qt dt ddfD ]}| t |j|d W d   n1 sIw   Y  q1dS )z>Ensures to_surface handles invalid setcolor formats correctly.r   zgreen colorz
#00FF00FF0Z0x00FF00FF0r   r;  Nr   r  皙?r
   r!   r   rj   rk   r  r   r   )rd   r!   r  r   r   r   )test_to_surface__invalid_setcolor_formatsB     z6MaskTypeTest.test_to_surface__invalid_setcolor_formatsc              	   C   rA  )z@Ensures to_surface handles invalid unsetcolor formats correctly.r   rB  r?  Nr   r  rC  rD  )rd   r!   r  r   r   r   +test_to_surface__invalid_unsetcolor_formatsN  rF  z8MaskTypeTest.test_to_surface__invalid_unsetcolor_formatsc                 C   s`   t d}t jjddd}dddgtdddt ddf}|D ]}|j|d	}t| || qd
S )z8Ensures to_surface handles valid dest formats correctly.r  r
  Trr   r*   r   )r   r   r   r   r,  r  N)r
   r  r!   r   r   r&   r  rL   rd   rH   r!   destsr  r  r   r   r   #test_to_surface__valid_dest_formatsZ  s   

z0MaskTypeTest.test_to_surface__valid_dest_formatsc              	   C   sf   t jd}ddddhdditf}|D ]}| t |j|d W d   n1 s+w   Y  qdS )z:Ensures to_surface handles invalid dest formats correctly.r
  r+  r.  r   r   rH  N)r
   r!   r   r&   rj   r   r  )rd   r!   Zinvalid_destsr  r   r   r   %test_to_surface__invalid_dest_formatsk  s   z2MaskTypeTest.test_to_surface__invalid_dest_formatsc                 C   sb   t d}t jjddd}t ddt ddt ddf}|D ]}|j|d	}t| || q d
S )z?Ensures to_surface correctly handles negative sized dest rects.r  r
  Trr   r*   )r  )rM  r  )rM  rM  rH  Nr
   r  r!   r   r&   r  rL   rI  r   r   r   )test_to_surface__negative_sized_dest_rectz     



z6MaskTypeTest.test_to_surface__negative_sized_dest_rectc                 C   sb   t d}t jjddd}t ddt ddt ddf}|D ]}|j|d}t| || q d	S )
z;Ensures to_surface correctly handles zero sized dest rects.r  r
  Trr   r*   r3  r2  rH  NrN  rI  r   r   r   %test_to_surface__zero_sized_dest_rect  rP  z2MaskTypeTest.test_to_surface__zero_sized_dest_rectc                 C   s  d}t d}t d}t |}t jj|dd}d}d}|d |d	 |d |d	 f||f|t|ft||ft|t|f|d |d	 |d |d	 g||g|t|gt||gt|t|gt ||f}|D ]!}	|| t |	}
|j||	d
}t	| |||
 t
| |||
 qhdS )z8Ensures to_surface handles valid area formats correctly.r
  r  r  Trr   r*   r  r   r   r  N)r
   r  r   r!   r   listr&   rs   r  rL   rN   )rd   r   r  rH   r   r!   area_posZ	area_sizeareasr  rI   r  r   r   r   #test_to_surface__valid_area_formats  s4   









z0MaskTypeTest.test_to_surface__valid_area_formatsc              	   C   sp   t jd}dddddh ddd	d
tf}|D ]}| td |j|d}W d   n1 s0w   Y  qdS )z:Ensures to_surface handles invalid area formats correctly.r
  r+  r*   )r   r   r   )r*   r   )r+  rW   >   r   r   r	   r   r   r   r  zinvalid area argumentrR  N)r
   r!   r   r&   assertRaisesRegexr   r  )rd   r!   Zinvalid_areasr  Zunused_to_surfacer   r   r   %test_to_surface__invalid_area_formats  s    z2MaskTypeTest.test_to_surface__invalid_area_formatsc           	      C   s   d}t d}t d}t |}t j|}|d t ddt ddt d	d
f}|D ]}|| |j||d}t	| ||| t
| ||| q/dS )z?Ensures to_surface correctly handles negative sized area rects.r
  r  r  r*   rV   rY   rX   r^   rW   r\   rR  N)r
   r  r   r!   r   r   r&   rs   r  rL   rN   )	rd   r   r  rH   r   r!   rU  r  r  r   r   r   )test_to_surface__negative_sized_area_rect  s    







z6MaskTypeTest.test_to_surface__negative_sized_area_rectc                 C   s|   d}t d}t |}t jj|dd}t ddt ddt ddf}|D ]}|| |j||d}t| || q'd	S )
z;Ensures to_surface correctly handles zero sized area rects.r
  r  Trr   r*   rV   rX   rR  N)	r
   r  r   r!   r   r&   rs   r  rL   )rd   r   rH   r   r!   rU  r  r  r   r   r   %test_to_surface__zero_sized_area_rect  s   





z2MaskTypeTest.test_to_surface__zero_sized_area_rectc                 C   s  d}t }d}d}d}d}td}td}td}	td	}
t|||}| }|| || d
d
d
d
d
d}dD ]}tjj||d}|d
fD ]}||d< |d
fD ]}||d< |	d
fD ]}||d< |
d
fD ]x}||d< |d
fD ]m}|d
u r|dd
 n||d< |r|d
ur|}n|d
ur|	}n|}n|d
ur|}n	|d
ur|
}n|}|j	di |}| 
|tj ts| t|| | | |@  | | | | | | t| || quqkqaqWqMq?d
S )zEnsures to_surface works with a default surface value
        and combinations of other parameters.

        This tests many different parameter combinations with full and empty
        masks.
        r	   r   r   r*   r  r  r&  r*  r2  N)r   r  r  r  r  rp   rr   r   r  r  r  r  r   )r  r
   r  r   r   rs   r!   r   r   r  rc   r  rE   r  r  r  r  r  r   rL   )rd   r  r  r  r   r  r  r$  r3  r  r  r   r  r   rs   r!   setsurface_paramunsetsurface_paramsetcolor_paramunsetcolor_param
dest_paramrH   r  r   r   r   8test_to_surface__default_surface_with_param_combinations  s~   






zEMaskTypeTest.test_to_surface__default_surface_with_param_combinationsc                 C   s  d}t }d}d}d}td}td}td}td}	td	}
t|||}| }| }|| || |d
d
d
d
d
d}dD ]}tjj||d}|d
fD ]}||d< |d
fD ]}||d< |	d
fD ]}||d< |
d
fD ]|}||d< || |d
fD ]l}|d
u r|dd
 n||d< |r|d
ur|}n|d
ur|	}n|}n|d
ur|}n	|d
ur|
}n|}|j	di |}| 
|| ts| t|| | | |@  | | | | | | t| || qqsqiq_qUqGd
S )zEnsures to_surface works with a surface value
        and combinations of other parameters.

        This tests many different parameter combinations with full and empty
        masks.
        ry   r   r   r*   r  r  r&  r*  r2  Nr-  rp   rr   r   r  r  r  r  r   )r  r
   r  r   r   rs   r!   r   r   r  r  r  rE   r  r  r  r  r  r   rL   )rd   r  r  r  r   r  r  r$  r3  r  r  r   r   r  r   rs   r!   r[  r\  r]  r^  r_  rH   r  r   r   r   0test_to_surface__surface_with_param_combinationsO  s   






	

z=MaskTypeTest.test_to_surface__surface_with_param_combinationsc                    s$  t d}t d}d \} }t j|}| }t |}t d} fddt|D D ]}	||	 q/| jD ]U}
|
|_	|
| |j||
d}|   fddt|D D ]0}	|	d	 |
d	  |	d
 |
d
  f}||	st|}n
||r||}n|}| ||	||
|	f qZ|  q:dS )zEnsures that to_surface works correctly with with set/unset bits
        when using the defaults for setcolor and unsetcolor.
        r  r  r  r  r  c                 3   .    | ]}t |d @  dD ]}||fV  qqdS r   r	   Nrp  r,   r   r   r3   r   r   r1        , zCMaskTypeTest.test_to_surface__set_and_unset_bits.<locals>.<genexpr>rH  c                 3   &    | ]}t  D ]}||fV  qqd S r=   rp  re  rf  r   r   r1     rr  r   r   N)r
   r  r!   r   rC   r   r   r   r   r   rs   r  rD   rM   r   rE   rF   )rd   default_setcolorr  r2   r   r!   r  r   r  rK   r  r  mask_posrH   r   rf  r   #test_to_surface__set_and_unset_bits  s0   





 


z0MaskTypeTest.test_to_surface__set_and_unset_bitsc              
      sl  d \} }t j|}| }t |}t d}| }t d}|| | }	t d}
|	|
  fddt|D D ]}|	| qA| j
D ]g}||_dD ]_}|| |rh|j||||	ddd	}n	|j||||	d
}|   fddt|D D ]-}|d |d  |d |d  f}||s|}n
||r|}n|
}| ||| q|  qSqLdS )zyEnsures that to_surface works correctly with with set/unset bits
        when using setsurface and unsetsurface.
        rb  r  r*  r&  c                 3   rc  rd  rp  re  rf  r   r   r1     rg  z`MaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface.<locals>.<genexpr>rp   N)r  r   r  r  r  )r  r   r  c                 3   rh  r=   rp  re  rf  r   r   r1     rr  r   r   )r
   r!   r   rC   r   r  r   rs   r   r   r   r   r  rD   rM   r   rE   rF   )rd   r2   r   r!   r  r   r  r   r$  r  r3  rK   r  Zdisable_color_paramsr  rj  rH   r   rf  r   @test_to_surface__set_and_unset_bits_with_setsurface_unsetsurface  sX   







	 


zMMaskTypeTest.test_to_surface__set_and_unset_bits_with_setsurface_unsetsurfacec                 C      t d}t d}d}d}t |}t d}dD ].}t jj||d}|| |r-|n|}	||}
| |
| | |
	 | t
| |
|	 qdS )	zEnsures that surfaces narrower than the mask work correctly.

        For this test the surface's width is less than the mask's width.
        r  r  rb     r  r  rp   rr   Nr
   r  r   r!   r   rs   r  r  rE   r   rL   )rd   ri  r  r   narrow_sizer   r  rs   r!   rH   r  r   r   r   +test_to_surface__surface_narrower_than_mask     





z8MaskTypeTest.test_to_surface__surface_narrower_than_maskc                 C      t d}t d}d}d}t |td}t d}|| | }dD ]6}t jj||d}	|	j|d	}
| 	|
t j | 
|
 | |rUt| |
|| t| |
|| q%t| |
| q%d
S )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  rb  rn  r   r  rp   rr   r   Nr
   r  r   r  rs   rC   r!   r   r  rc   rE   r   rL   rN   )rd   ri  r  r   rq  r   r$  setsurface_rectrs   r!   r  r   r   r   .test_to_surface__setsurface_narrower_than_mask$  (   



z;MaskTypeTest.test_to_surface__setsurface_narrower_than_maskc                 C      t d}t d}d}d}t |td}t d}|| | }dD ]6}t jj||d}	|	j|d	}
| 	|
t j | 
|
 | |rMt| |
| q%t| |
|| t| |
|| q%d
S )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  rb  rn  r   r  rp   rr   r  Nrv  )rd   ri  r  r   rq  r  r3  unsetsurface_rectrs   r!   r  r   r   r   0test_to_surface__unsetsurface_narrower_than_maskD  ,   



z=MaskTypeTest.test_to_surface__unsetsurface_narrower_than_maskc           
      C      d}d}d}t |td}t d}|| | }dD ]8}t jj||d}|j|ddd	}	| 	|	t j | 
|	 | |rOt| |	|| t| |	|| qt| |	| qdS )
zEnsures that setsurfaces narrower than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the setsurface's width is less than the mask's width.
        r  rb  rn  r   r  rp   rr   Nr   r  r  r
   r   r  r  rs   rC   r!   r   r  rc   rE   r   rL   rN   )
rd   r  r   rq  r   r$  rw  rs   r!   r  r   r   r   >test_to_surface__setsurface_narrower_than_mask_and_colors_nonef  *   

zKMaskTypeTest.test_to_surface__setsurface_narrower_than_mask_and_colors_nonec           
      C      d}d}d}t |td}t d}|| | }dD ]8}t jj||d}|j|ddd	}	| 	|	t j | 
|	 | |rGt| |	| qt| |	|| t| |	|| qdS )
zEnsures that unsetsurfaces narrower than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the unsetsurface's width is less than the mask's width.
        r  rb  rn  r   r  rp   rr   Nr  r  r  r  )
rd   r  r   rq  r  r3  r|  rs   r!   r  r   r   r   @test_to_surface__unsetsurface_narrower_than_mask_and_colors_none  .   

zMMaskTypeTest.test_to_surface__unsetsurface_narrower_than_mask_and_colors_nonec                 C      t d}t d}d}d}t |}t d}dD ]:}t jj||d}| }	|| |r1|n|}
||}| || | 	|
 | t| ||
|	 t| |||	 qdS )	zEnsures that surfaces wider than the mask work correctly.

        For this test the surface's width is greater than the mask's width.
        r  r  ro     r`   r  r  rp   rr   Nr
   r  r   r!   r   rC   rs   r  r  rE   r   rL   rN   )rd   ri  r  r   	wide_sizer   r  rs   r!   r  rH   r  r   r   r   (test_to_surface__surface_wider_than_mask  "   





z5MaskTypeTest.test_to_surface__surface_wider_than_maskc           
      C      t d}d}d}t |td}t d}|| dD ]+}t jj||d}|r*|n|}|j|d}	| |	t j | 	|	
 | t| |	| qd	S )
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  rp   rr   ru  Nr
   r  r   r  rs   r!   r   r  rc   rE   r   rL   )
rd   r  r   r  r   r$  rs   r!   rH   r  r   r   r   +test_to_surface__setsurface_wider_than_mask  s   


z8MaskTypeTest.test_to_surface__setsurface_wider_than_maskc           
      C      t d}d}d}t |td}t d}|| dD ]+}t jj||d}|r*|n|}|j|d}	| |	t j | 	|	
 | t| |	| qd	S )
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  rp   rr   r{  Nr  )
rd   ri  r   r  r  r3  rs   r!   rH   r  r   r   r   -test_to_surface__unsetsurface_wider_than_mask     


z:MaskTypeTest.test_to_surface__unsetsurface_wider_than_maskc                 C   rm  )	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  r`   r  ro  r  rp   rr   Nrp  )rd   ri  r  r   
short_sizer   r  rs   r!   rH   r  r   r   r   *test_to_surface__surface_shorter_than_mask  rs  z7MaskTypeTest.test_to_surface__surface_shorter_than_maskc                 C   rt  )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  rp   rr   ru  Nrv  )rd   ri  r  r   r  r   r$  rw  rs   r!   r  r   r   r   -test_to_surface__setsurface_shorter_than_mask  ry  z:MaskTypeTest.test_to_surface__setsurface_shorter_than_maskc                 C   rz  )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  rp   rr   r{  Nrv  )rd   ri  r  r   r  r  r3  r|  rs   r!   r  r   r   r   /test_to_surface__unsetsurface_shorter_than_mask-  r~  z<MaskTypeTest.test_to_surface__unsetsurface_shorter_than_maskc           
      C   r  )
zEnsures that setsurfaces shorter than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the setsurface's height is less than the mask's height.
        r  r  r  r   r  rp   rr   Nr  r  )
rd   r  r   r  r   r$  rw  rs   r!   r  r   r   r   =test_to_surface__setsurface_shorter_than_mask_and_colors_noneO  r  zJMaskTypeTest.test_to_surface__setsurface_shorter_than_mask_and_colors_nonec           
      C   r  )
zEnsures that unsetsurfaces shorter than the mask work correctly
        when setcolor and unsetcolor are set to None.

        For this test the unsetsurface's height is less than the mask's height.
        r  r  r  r   r  rp   rr   Nr  r  )
rd   r  r   r  r  r3  r|  rs   r!   r  r   r   r   ?test_to_surface__unsetsurface_shorter_than_mask_and_colors_noneq  r  zLMaskTypeTest.test_to_surface__unsetsurface_shorter_than_mask_and_colors_nonec                 C   r  )	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  rp   rr   Nr  )rd   ri  r  r   	tall_sizer   r  rs   r!   r  rH   r  r   r   r   )test_to_surface__surface_taller_than_mask  r  z6MaskTypeTest.test_to_surface__surface_taller_than_maskc           
      C   r  )
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  rp   rr   ru  Nr  )
rd   r  r   r  r   r$  rs   r!   rH   r  r   r   r   ,test_to_surface__setsurface_taller_than_mask  r  z9MaskTypeTest.test_to_surface__setsurface_taller_than_maskc           
      C   r  )
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  rp   rr   r{  Nr  )
rd   ri  r   r  r  r3  rs   r!   rH   r  r   r   r   .test_to_surface__unsetsurface_taller_than_mask  r  z;MaskTypeTest.test_to_surface__unsetsurface_taller_than_maskc                 C   r  )	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  ro     r  r  rp   rr   Nr  )rd   ri  r  r   wide_tall_sizer   r  rs   r!   r  rH   r  r   r   r   3test_to_surface__surface_wider_and_taller_than_mask  s"   





z@MaskTypeTest.test_to_surface__surface_wider_and_taller_than_maskc           
      C   r  )
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  rp   rr   ru  Nr  )
rd   r  r   r  r   r$  rs   r!   rH   r  r   r   r   6test_to_surface__setsurface_wider_and_taller_than_mask     


zCMaskTypeTest.test_to_surface__setsurface_wider_and_taller_than_maskc           
      C   r  )
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  rp   rr   r{  Nr  )
rd   ri  r   r  r  r3  rs   r!   rH   r  r   r   r   8test_to_surface__unsetsurface_wider_and_taller_than_mask  r  zEMaskTypeTest.test_to_surface__unsetsurface_wider_and_taller_than_maskc                 C   r  )	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  rh  )r   ro  r  rp   rr   Nr  )rd   ri  r  r   wide_short_sizer   r  rs   r!   r  rH   r  r   r   r   4test_to_surface__surface_wider_and_shorter_than_mask,  "   





zAMaskTypeTest.test_to_surface__surface_wider_and_shorter_than_maskc                 C   rt  )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  rh  r  r   r  rp   rr   ru  Nrv  )rd   ri  r  r   r  r   r$  rw  rs   r!   r  r   r   r   7test_to_surface__setsurface_wider_and_shorter_than_maskH  (   



zDMaskTypeTest.test_to_surface__setsurface_wider_and_shorter_than_maskc                 C   rz  )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  rh  r  r   r  rp   rr   r{  Nrv  )rd   ri  r  r   r  r  r3  r|  rs   r!   r  r   r   r   9test_to_surface__unsetsurface_wider_and_shorter_than_maskj  ,   



zFMaskTypeTest.test_to_surface__unsetsurface_wider_and_shorter_than_maskc                 C   r  )	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  rp   rr   Nr  )rd   ri  r  r   narrow_tall_sizer   r  rs   r!   r  rH   r  r   r   r   6test_to_surface__surface_narrower_and_taller_than_mask  r  zCMaskTypeTest.test_to_surface__surface_narrower_and_taller_than_maskc                 C   rt  )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  rp   rr   ru  Nrv  )rd   ri  r  r   r  r   r$  rw  rs   r!   r  r   r   r   9test_to_surface__setsurface_narrower_and_taller_than_mask  r  zFMaskTypeTest.test_to_surface__setsurface_narrower_and_taller_than_maskc                 C   rz  )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  rp   rr   r{  Nrv  )rd   ri  r  r   r  r  r3  r|  rs   r!   r  r   r   r   ;test_to_surface__unsetsurface_narrower_and_taller_than_mask  r  zHMaskTypeTest.test_to_surface__unsetsurface_narrower_and_taller_than_maskc                 C   r  )	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  rp   rr   Nr  )rd   ri  r  r   narrow_short_sizer   r  rs   r!   r  rH   r  r   r   r   7test_to_surface__surface_narrower_and_shorter_than_mask  r  zDMaskTypeTest.test_to_surface__surface_narrower_and_shorter_than_maskc                 C   rt  )zEnsures that setsurfaces narrower and shorter than the mask work
        correctly.

        For this test the setsurface's width is less than the mask's width
        and the setsurface's height is less than the mask's height.
        r  r  r  r  r   r  rp   rr   ru  Nrv  )rd   ri  r  r   r  r   r$  rw  rs   r!   r  r   r   r   :test_to_surface__setsurface_narrower_and_shorter_than_mask  r  zGMaskTypeTest.test_to_surface__setsurface_narrower_and_shorter_than_maskc                 C   rz  )zEnsures that unsetsurfaces narrower and shorter than the mask work
        correctly.

        For this test the unsetsurface's width is less than the mask's width
        and the unsetsurface's height is less than the mask's height.
        r  r  r  r  r   r  rp   rr   r{  Nrv  )rd   ri  r  r   r  r  r3  r|  rs   r!   r  r   r   r   <test_to_surface__unsetsurface_narrower_and_shorter_than_mask.  r  zIMaskTypeTest.test_to_surface__unsetsurface_narrower_and_shorter_than_maskc                    s  t d}t d}t d}t d}t d}d}d}d}d	}	t |}
t |}t |	}|
| || || |
  | }| }t jj|d
d}| }t dd|j_fddt	j
jD D ]}||d qo||
||}| ||
 | | | |   fddt	 jD D ]-}||s|}n||r||r|}n|}n
||r|}n|}| ||| q|  dS )zBEnsures that all the surface parameters can be of different sizes.r  r  r  r*  r&  )r  r  )r`      )r&  r  )r     Trr   r*   r   c                 3   s,    | ]}t  j jD ]}||fV  qqd S r=   )r   r   r   re  )unfilled_rectr   r   r1   r  s    zWMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_mask.<locals>.<genexpr>r   c                 3   s(    | ]}t  jD ]}||fV  q	qd S r=   )r   r   re  )surface_rectr   r   r1     s    
N)r
   r  r   rs   rC   r!   r   r&   r   r   r   r   r   r  r  rE   r   rD   rM   r   rF   )rd   ri  r  r  r$  r3  r   Zsurface_sizeZsetsurface_sizeZunsetsurface_sizer   r   r  rw  r|  r!   r  rK   r  rH   r   )r  r  r   7test_to_surface__all_surfaces_different_sizes_than_maskR  sX   


















zDMaskTypeTest.test_to_surface__all_surfaces_different_sizes_than_maskc                 C   s*  d}t ||f}| }| }t d}t d}t d}dd t| |d D dd t| |d D d	d t| |d D d
d t| |d D f}dD ]>}	t jj||f|	d}
|	rd|n|}|D ])}|D ]$}||_|	|}|
| |
j||d}t| ||| t| ||| qlqhqTdS )zBEnsures dest values can be different locations on/off the surface.r   r  r  r  c                 s       | ]}|d fV  qdS r+   r   r,   sr   r   r   r1         z?MaskTypeTest.test_to_surface__dest_locations.<locals>.<genexpr>r   c                 s       | ]}d |fV  qdS r+   r   r  r   r   r   r1     r  c                 s       | ]}||fV  qd S r=   r   r  r   r   r   r1     r  c                 s       | ]}| |fV  qd S r=   r   r  r   r   r   r1         rp   rr   rH  N)r
   r   rC   r   r  r   r!   r   r   rB   rs   r  rL   rN   )rd   SIDEr   r  	dest_rectr  ri  r  
directionsrs   r!   rH   	directionrK   r  r  r   r   r   test_to_surface__dest_locations  s8   




z,MaskTypeTest.test_to_surface__dest_locationsc                 C   s0  d}t ||f}t d}t d}t d}dd t| |d D dd t| |d D d	d t| |d D d
d t| |d D f}dD ]I}t jj||f|d}| }	|	 }
|rd|n|}|D ],}|D ]'}||
_|
	|	}d|_|
| |j||
d}t| ||| t| ||| qlqhqLdS )z>Ensures area rects can be different locations on/off the mask.r   r  r  r  c                 s   r  r+   r   r  r   r   r   r1     r  z?MaskTypeTest.test_to_surface__area_locations.<locals>.<genexpr>r   c                 s   r  r+   r   r  r   r   r   r1     r  c                 s   r  r=   r   r  r   r   r   r1     r  c                 s   r  r=   r   r  r   r   r   r1     r  rp   rr   r*   rR  N)r
   r   r  r   r!   r   rC   r   r   rB   rs   r  rL   rN   )rd   r  r   r  ri  r  r  rs   r!   r  rI   rH   r  rK   r  r  r   r   r   test_to_surface__area_locations  s:   




z,MaskTypeTest.test_to_surface__area_locationsc              	   C   sj  d}t ||f}| }| }t d}t d}t d}dd t| |d D dd t| |d D d	d t| |d D d
d t| |d D f}t|d }	dD ]X}
t jj||f|
d}| }| }|
rr|n|}|D ];}|D ]6}||_	|	D ].}||_	|
|}|j	|_	|
|}|| |j|||d}t| ||| t| ||| qqzqvqZdS )z]Ensures dest/area values can be different locations on/off the
        surface/mask.
        r   r  r  r  c                 s   r  r+   r   r  r   r   r   r1     r  zHMaskTypeTest.test_to_surface__dest_and_area_locations.<locals>.<genexpr>r   c                 s   r  r+   r   r  r   r   r   r1     r  c                 s   r  r=   r   r  r   r   r   r1     r  c                 s   r  r=   r   r  r   r   r   r1     r  r	   rp   rr   )r  r  N)r
   r   rC   r   r  r   rS  r!   r   r   rB   rs   r  rL   rN   )rd   r  r   r  r  r  ri  r  Zdest_directionsZarea_positionsrs   r!   r  rI   rH   Zdest_directionZdest_posrT  Zarea_overlap_rectZdest_overlap_rectr  r   r   r   (test_to_surface__dest_and_area_locations  sP   


	


z5MaskTypeTest.test_to_surface__dest_and_area_locationsc                 C   s(  d}dddd|d |d f|d |f||d f||f|d |f||d f|d |d ff}t ||f}t d}t d}t d	}d
D ]L}t jj||f|d}| }	|rY|n|}
|D ]3}t d|}| jD ]'}||_|	|	}d|_|
| |j||d}t| ||
| t| ||| qhq]qEdS )z*Ensures area rects can be different sizes.r   r*   rV   rX   rW   r   r  r  r  rp   rr   rR  N)r
   r   r  r!   r   rC   r&   r   r   rB   rs   r  rL   rN   )rd   r  ZSIZESr   r  ri  r  rs   r!   r  rH   r   rI   rK   r  r  r   r   r   test_to_surface__area_sizes  sH   









z(MaskTypeTest.test_to_surface__area_sizesc           
      C   s   d}t d}d|_t d}d|_t j|tdd}t j|tdd}|| || dD ],}t jj||d	}|r<|n|}|j||d
}	| 	|	t j | 
|	 | t| |	| q.dS )zEEnsures the setsurface/unsetsurface color alpha values are respected.r   r*  5   r&  r  r   flagsdepthrp   rr   r   r  N)r
   r  r-   r   r  rs   r!   r   r  rc   rE   r   rL   )
rd   r   r$  r3  r   r  rs   r!   rH   r  r   r   r   %test_to_surface__surface_color_alphasB  s&   



z2MaskTypeTest.test_to_surface__surface_color_alphasc                 C   s   d}t d}d|_t d}d|_dD ],}t jj||d}|r"|n|}|j||d}| |t j | |	 | t
| || qd	S )
z;Ensures the setcolor/unsetcolor alpha values are respected.r   r*  #   r&     rp   rr   )r  r  N)r
   r  r-   r!   r   r  rc   r   rE   r   rL   )rd   r   r  r  rs   r!   rH   r  r   r   r   test_to_surface__color_alphas\  s   

z*MaskTypeTest.test_to_surface__color_alphasc                 C   s   d}t d}t d}t d}dD ][}t j||d}t j||d}t j||d}|| || || dD ]2}	t jj||	d}
|	rL|d	n|d	}|
|||}| |t j | 	|
 | t| || q;qd
S )zAEnsures to_surface works correctly with supported surface depths.r   r  r*  r&  r  r     r   r  rp   rr   r*   N)r
   r  r   rs   r!   r   r   r  rc   rE   r   rL   )rd   r   r  r$  r3  r  r   r   r  rs   r!   rH   r  r   r   r   test_to_surface__depthsn  s*   





z$MaskTypeTest.test_to_surface__depthsc              	   C   s   d}t d}t d}t d}t j|}d}|D ]H}t j||d d}t j||d d}	t j||d	 d}
|| |	| |
| | t |||	|
 W d
   n1 s^w   Y  qd
S )zCEnsures an exception is raised when surfaces have different depths.r   r  r*  r&  )	)r  r  r  )r  r  r  )r  r  r   )r  r  r  )r  r  r   )r  r  r  )r   r  r  )r   r   r  )r   r  r   r   r  r   r	   N	r
   r  r!   r   r   rs   rj   rk   r  )rd   r   r  r$  r3  r!   test_depthsZdepthsr   r   r  r   r   r   !test_to_surface__different_depths  s$   





z.MaskTypeTest.test_to_surface__different_depthsc           
   	   C   s   d}t d}t d}t j|}d}|D ]8\}}t j||d}t j||d}	|| |	| | t |j||	d W d   n1 sIw   Y  qdS )zmEnsures an exception is raised when surfaces have different depths
        than the created surface.
        r   r*  r&  ))r  r  )r  r  )r  r  )r  r  )r   r  )r   r  )r   r  r  r   r  r  Nr  )
rd   r   r$  r3  r!   r  Z	set_depthZunset_depthr   r  r   r   r   7test_to_surface__different_depths_with_created_surfaces  s   



zDMaskTypeTest.test_to_surface__different_depths_with_created_surfacesc                 C   s   d}t d}t d}t d}dD ]j}dtfD ]c}t j|||d}t j|||d}t j|||d}	|| || |	| dD ]7}
t jj||
d	}|
rR|n|}||||	}| |t j | 	|
 | t| || |r{| | |@  qDqqd
S )zHEnsures to_surface works correctly when the SRCALPHA flag is set or not.r   r  r*  r&  r  r   r  rp   rr   Nr
   r  r  r   rs   r!   r   r  rc   rE   r   rL   r  r  )rd   r   r  r$  r3  r  r  r   r   r  rs   r!   rH   r  r   r   r   test_to_surface__same_srcalphas  s2   





z,MaskTypeTest.test_to_surface__same_srcalphasc                 C   s   d}t d}t d}t}t j||dd}t j||dd}|| || dD ]5}t jj||d}|r8|n|}	|j||d}
| |
t j | 	|

 | t| |
|	 | |
 |@  q*d	S )
zEnsures to_surface works correctly when it creates a surface
        and the SRCALPHA flag is set on both setsurface and unsetsurface.
        r   r*  r&  r   r  rp   rr   r  Nr  )rd   r   r$  r3  Zexpected_flagsr   r  rs   r!   rH   r  r   r   r   5test_to_surface__same_srcalphas_with_created_surfaces  s&   



zBMaskTypeTest.test_to_surface__same_srcalphas_with_created_surfacesc              
   C   s   d}t d}t d}t d}t j|}tddfttdfdttfddtff}dD ]P}|D ]K}t j||d |d}	t j||d |d}
t j||d	 |d}|	| |
| || | t |	|	|
| W d
   n1 suw   Y  q/q+d
S )zdEnsures an exception is raised when surfaces have different SRCALPHA
        flag settings.
        r   r  r*  r&  r   r  r  r   r	   N
r
   r  r!   r   r  r   rs   rj   rk   r  )rd   r   r  r$  r3  r!   Z
test_flagsr  r  r   r   r  r   r   r   $test_to_surface__different_srcalphas  s0   





z1MaskTypeTest.test_to_surface__different_srcalphasc           	   
   C   s   d}t d}t d}t j|}dD ]H}dtdfdtffD ]<}t j||d |d}t j||d |d}|| || | t |j	||d	 W d
   n1 sVw   Y  qqd
S )z}Ensures an exception is raised when surfaces have different SRCALPHA
        flag settings than the created surface.
        r   r*  r&  r  r*   r   r  r   r  Nr  )	rd   r   r$  r3  r!   r  r  r   r  r   r   r   :test_to_surface__different_srcalphas_with_created_surfaces'  s    



zGMaskTypeTest.test_to_surface__different_srcalphas_with_created_surfacesc                    s   t d}t d}d \ }}t |td}t d}dD ]M}t jj||d}| }	|r0|n|}
 fdd	t|D D ]-}|| ||	_	|j
||d
}| || | | | t| ||
|	 t| |||	 q=qdS )zwEnsures dest values on the surface work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   r&  r   r  rp   rr   c                 3   ro  r=   rp  r>   rq  r   r   r1   M  rr  z@MaskTypeTest.test_to_surface__dest_on_surface.<locals>.<genexpr>rH  N)r
   r  r   r  r!   r   rC   r   rs   r   r  r  rE   r   rL   rN   )rd   ri  r  r3   r   r   r  rs   r!   r  rH   r  r  r   rq  r    test_to_surface__dest_on_surface=  s*   



z-MaskTypeTest.test_to_surface__dest_on_surfacec                    s@  d \ }}t |td}t d}| }t d}|| | }t d}|| |||dd}	t|	}
|
d d	D ]]}t jj	||d
}|
 }|rR|n|} fddt|D D ]=}||_d	D ]5}|| |rq|
n|	}||d< |jdi |}| || | | | t| ||| t| ||| qfq_q@dS )zjEnsures dest values on the surface work correctly
        when using setsurface and unsetsurface.
        r  r   r  r*  r&  Nr   r   r  r  )r  N)r  Nrp   rr   c                 3   ro  r=   rp  r>   rq  r   r   r1   |  rr  z]MaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurface.<locals>.<genexpr>r  r   )r
   r   r  r  r   rs   r  updater!   r   rC   r   r   r  r  rE   r   rL   rN   )rd   r3   r   r   r  r   r$  r  r3  r   color_kwargsrs   r!   r  rH   r  use_color_paramstest_kwargsr  r   rq  r   =test_to_surface__dest_on_surface_with_setsurface_unsetsurfaceZ  sH   






zJMaskTypeTest.test_to_surface__dest_on_surface_with_setsurface_unsetsurfacec                 C   s   t d}t d}d \}}}t |td}t d}| | f| dfd| fg}|t|  dD ]D}	t jj||	d}
|
 }|	rH|n|}|D ]-}|	| ||_
|
j||d	}| || | | | t| ||| t| ||| qLq6d
S )zxEnsures dest values off the surface work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   r   r  r   rp   rr   rH  N)r
   r  r   r  extendr;   rC   r!   r   rs   r   r  r  rE   r   rL   rN   )rd   ri  r  r2   r3   r   r   r  rJ  rs   r!   r  rH   r  r  r   r   r   !test_to_surface__dest_off_surface  s.   



z.MaskTypeTest.test_to_surface__dest_off_surfacec                 C   s^  d \}}}t |td}t d}| }t d}|| | }t d}	||	 | | f| dfd| fg}
|
t|  |||dd}t	|}|
d	 d
D ]T}t jj||d}| }|rj|n|	}|
D ]=}||_d
D ]5}|| |r|n|}||d< |jdi |}| || | | | t| ||| t| ||| quqnqXdS )zkEnsures dest values off the surface work correctly
        when using setsurface and unsetsurface.
        r   r   r  r*  r&  r   Nr  r  rp   rr   r  r   )r
   r   r  r  r   rs   r  r;   rC   r  r  r!   r   r   r  r  rE   r   rL   rN   )rd   r2   r3   r   r   r  r   r$  r  r3  rJ  r   r  rs   r!   r  rH   r  r  r  r  r   r   r   >test_to_surface__dest_off_surface_with_setsurface_unsetsurface  sL   






zKMaskTypeTest.test_to_surface__dest_off_surface_with_setsurface_unsetsurfacec                    s   t d}t d}d \ }}t |td}t d}dD ]Y}t jj||d}| }	|	 }
|r4|n|} fdd	t|D D ]5}|	| ||
_
|	|
}d
|_
|j||
d}| || | | | t| ||| t| ||| qAqdS )ztEnsures area values on the mask work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r  r   r  rp   rr   c                 3   ro  r=   rp  r>   rq  r   r   r1     rr  z=MaskTypeTest.test_to_surface__area_on_mask.<locals>.<genexpr>r*   rR  N)r
   r  r   r  r!   r   rC   r   r   rs   r   rB   r  r  rE   r   rL   rN   )rd   ri  r  r3   r   r   r  rs   r!   r  rI   rH   rK   r  r  r   rq  r   test_to_surface__area_on_mask  s0   




z*MaskTypeTest.test_to_surface__area_on_maskc                    sv  d \ }}t |td}t d}| }t d}|| | }t d}|| |||t d|d}	t|	}
|
d d	D ]t}t j	j
||d
}| }| }|rZ|n|} fddt|D D ]P}||_||}d|_d	D ]@}|| |r|
n|	}||d _||d }d|_|jdi |}| || | | | t| ||| t| ||| qvqgqDdS )zgEnsures area values on the mask work correctly
        when using setsurface and unsetsurface.
        r  r   r  r*  r&  r*   r   r   r  r  r  rp   rr   c                 3   ro  r=   rp  r>   rq  r   r   r1   (  rr  zZMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurface.<locals>.<genexpr>r  Nr   )r
   r   r  r  r   rs   r&   r  r  r!   r   rC   r   r   rB   r  r  rE   r   rL   rN   )rd   r3   r   r   r  r   r$  r  r3  r   r  rs   r!   r  rI   rH   rK   r  r  r  r  r   rq  r   :test_to_surface__area_on_mask_with_setsurface_unsetsurface  sR   









zGMaskTypeTest.test_to_surface__area_on_mask_with_setsurface_unsetsurfacec                 C   s  t d}t d}d \}}}t |td}t d}| | f| dfd| fg}|tt d||f dD ]P}	t jj||	d	}
|
	 }|
 }|	rP|n|}|D ]5}|| ||_||}d|_|
j||d
}| || | | | t| ||| t| ||| qTq:dS )zuEnsures area values off the mask work correctly
        when using the defaults for setcolor and unsetcolor.
        r  r  r   r   r  r   r*   rp   rr   rR  N)r
   r  r   r  r  r;   r&   r!   r   rC   r   rs   r   rB   r  r  rE   r   rL   rN   )rd   ri  r  r2   r3   r   r   r  	positionsrs   r!   r  rI   rH   rK   r  r  r   r   r   test_to_surface__area_off_mask=  s4   




z+MaskTypeTest.test_to_surface__area_off_maskc                 C   s~  d \}}}t |td}t d}| }t d}|| | }t d}	||	 | | f| dfd| fg}
|
tt d||f |||t d|d}t	|}|
d	 d
D ]\}t jj||d}| }|rr|n|	}|
D ]E}d
D ]@}|| |r|n|}||d _||d }d|_|jdi |}| || | | | t| ||| t| ||| qzqvq`dS )zhEnsures area values off the mask work correctly
        when using setsurface and unsetsurface.
        r   r   r  r*  r&  r   r*   r  r  rp   rr   r  Nr   )r
   r   r  r  r   rs   r  r;   r&   r  r  r!   r   rC   r   rB   r  r  rE   r   rL   rN   )rd   r2   r3   r   r   r  r   r$  r  r3  r  r   r  rs   r!   r  rH   rK   r  r  r  r  r   r   r   ;test_to_surface__area_off_mask_with_setsurface_unsetsurfaceb  sN   








zHMaskTypeTest.test_to_surface__area_off_mask_with_setsurface_unsetsurfacec                 C   sb   d}d}t |}t jjddd}||}| || ts'| t	|| | |
 | dS )z2Ensures zero sized surfaces are handled correctly.r   r*   r   ry   Trr   N)r
   r   r!   r   r  r  r  rE   r  r  r   )rd   r  r   r   r!   r  r   r   r   'test_to_surface__surface_with_zero_size  s   

z4MaskTypeTest.test_to_surface__surface_with_zero_sizec           	      C   s   d}t }d}td}d}tjj|dd}td||}|j|d}| |tj ts4| 	t
|| | | |@  | 	| | | 	| | t| || d	S )
z5Ensures zero sized setsurfaces are handled correctly.r	   r   r  r	   ry   Trr   r*   ru  Nr  r
   r  r!   r   r   r  rc   r  rE   r  r  r  r  r  r   rL   )	rd   r  r  r  rH   r   r!   r   r  r   r   r   *test_to_surface__setsurface_with_zero_size  s   
z7MaskTypeTest.test_to_surface__setsurface_with_zero_sizec           	      C   s   d}t }d}td}d}tj|}td||}|j|d}| |tj ts2| 	t
|| | | |@  | 	| | | 	| | t| || dS )z7Ensures zero sized unsetsurfaces are handled correctly.r	   r   r  r  r*   r{  Nr  )	rd   r  r  r  rH   r   r!   r  r  r   r   r   ,test_to_surface__unsetsurface_with_zero_size  s   
z9MaskTypeTest.test_to_surface__unsetsurface_with_zero_sizec                 C   s\   dD ])}dD ]$}d| d| }t jj||d}| |t jj| | | || qqdS )z-Ensures masks can be created with zero sizes.)r   r   )r   r   r*   rp   r{   z, fill=rr   N)r
   r!   r   rc   rE   r   )rd   r   rs   rO   r!   r   r   r   test_zero_mask  s   zMaskTypeTest.test_zero_maskc                 C   sJ   dD ] }t j|}| }| |t jj | || t| || qdS )z0Ensures copy correctly handles zero sized masks.)r`   r   )r   r`   r*   Nr   )rd   rf   r!   r   r   r   r   test_zero_mask_copy  s   z MaskTypeTest.test_zero_mask_copyc                 C   s.   dD ]}t j|}| }| || qdS )z4Ensures get_size correctly handles zero sized masks.))r  r   )r   (   r*   N)r
   r!   r   r   rE   rd   rf   r!   r   r   r   r   test_zero_mask_get_size  s
   z$MaskTypeTest.test_zero_mask_get_sizec                 C   s:   dD ]}t d|}t j|}| }| || qdS )z4Ensures get_rect correctly handles zero sized masks.)r  )r   ry   r*   r*   N)r
   r&   r!   r   rC   rE   )rd   rf   r   r!   r:   r   r   r   test_zero_mask_get_rect  s   z$MaskTypeTest.test_zero_mask_get_rectc              	   C   N   dD ]"}t j|}| t |d}W d   n1 sw   Y  qdS )z2Ensures get_at correctly handles zero sized masks.))3   r   )r   r  r*   r*   Nr   )rd   r   r!   r   r   r   r   test_zero_mask_get_at     z"MaskTypeTest.test_zero_mask_get_atc              	   C   sN   dD ]"}t j|}| t |d W d   n1 sw   Y  qdS )z2Ensures set_at correctly handles zero sized masks.))r   r   )r      r*   r*   Nr   rl   r   r   r   test_zero_mask_set_at  r  z"MaskTypeTest.test_zero_mask_set_atc                 C   sd   d}t ddD ](\}}d| d| }tjj|dd}tjj|dd}|||}| || qdS )	zwEnsures overlap correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r*   r	  *   size1=, size2=Trr   N)r4   r
   r!   r   r   r   )rd   r   size1size2rO   rg   rh   r   r   r   r   test_zero_mask_overlap	  s   z#MaskTypeTest.test_zero_mask_overlapc           	      C   sj   d}d}t ddD ])\}}d| d| }tjj|dd}tjj|dd}|||}| ||| q	d	S )
z|Ensures overlap_area correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r*   r   r  4   r  r  Trr   N)r4   r
   r!   r   rQ   rE   )	rd   r   re   r  r  rO   rg   rh   r  r   r   r   test_zero_mask_overlap_area  s   z(MaskTypeTest.test_zero_mask_overlap_areac           	      C   s   d}d}t ddD ]=\}}d| d| }tjj|dd}tjj|dd}|||}| |tjj| | | || | | || q	d	S )
z|Ensures overlap_mask correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r*   r   rE  r  r  r  Trr   N)	r4   r
   r!   r   r  rc   rE   rP   r   )	rd   r   re   r  r  rO   rg   rh   r  r   r   r   test_zero_mask_overlap_mask*  s   z(MaskTypeTest.test_zero_mask_overlap_maskc                 C   s>   d}dD ]}t j|}|  | | |d|  qdS )z0Ensures fill correctly handles zero sized masks.r   r   r{   N)r
   r!   r   rs   rE   rP   )rd   re   r   r!   r   r   r   test_zero_mask_fill=  s   z MaskTypeTest.test_zero_mask_fillc                 C   6   d}|D ]}t j|}|  | | d qd S Nr   r   )r
   r!   r   r  rE   rP   rd   r0   r   r!   r   r   r   test_zero_mask_clearH     z!MaskTypeTest.test_zero_mask_clearc                 C   r  r  )r
   r!   r   rA  rE   rP   r  r   r   r   test_zero_mask_flipP  r  z MaskTypeTest.test_zero_mask_flipc                 C   sH   d}|D ]}t j|}|d}| |t jj | | d qd S )Nr   r	   r   )r
   r!   r   rM  rc   rE   r   )rd   r0   r   r!   rh   r   r   r   test_zero_mask_scaleX  s   
z!MaskTypeTest.test_zero_mask_scalec                 C      d}t ddD ]8\}}d| d| }tjj|dd}tjj|dd}| }||| | | || | | || qdS )	ztEnsures draw correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r*   r   rn   r  r  Trr   N)r4   r
   r!   r   rP   r  rE   r   rd   r   r  r  rO   rg   rh   re   r   r   r   test_zero_mask_drawb     z MaskTypeTest.test_zero_mask_drawc                 C   r   )	zuEnsures erase correctly handles zero sized masks.

        Tests combinations of sized and zero sized masks.
        r*      ra   r  r  Trr   N)r4   r
   r!   r   rP   rd  rE   r   r!  r   r   r   test_zero_mask_eraset  r#  z!MaskTypeTest.test_zero_mask_erasec                 C   s2   d}|D ]}t jj|dd}| | d qd S )Nr   Trr   r   )r
   r!   r   rE   rP   r  r   r   r   test_zero_mask_count  s
   z!MaskTypeTest.test_zero_mask_countc                 C   .   d}|D ]}t j|}| | d qd S )Nr   r*   )r
   r!   r   rE   ry  r  r   r   r   test_zero_mask_centroid  
   z$MaskTypeTest.test_zero_mask_centroidc                 C   r'  )Nr   r  )r
   r!   r   rE   r  r  r   r   r   test_zero_mask_angle  r)  z!MaskTypeTest.test_zero_mask_anglec                 C   :   g }dD ]}t j|}| }| ||d|  qdS )z3Ensures outline correctly handles zero sized masks.))rL  r   r   <   r*   r{   Nr
   r!   r   r  r  rd   Zexpected_pointsr   r!   r'   r   r   r   test_zero_mask_outline     z#MaskTypeTest.test_zero_mask_outlinec                 C   s<   g }dD ]}t j|}|d}| ||d|  qdS )z_Ensures outline correctly handles zero sized masks
        when using the skip pixels argument.))rz   r   )r   r   r*   r  r{   Nr.  r/  r   r   r    test_zero_mask_outline__with_arg  s   
z-MaskTypeTest.test_zero_mask_outline__with_argc                 C   s   dD ]W}t jj|dd}dD ]J}d| d| }t jj|dd}td|d |d  d td|d |d  d f}||}| |t jj| | ||| | | || qqd	S )
zEnsures convolve correctly handles zero sized masks.

        Tests the different combinations of sized and zero sized masks.
        ))r   r   r~   r   r   F   r*   Trr   )r   Q   r   r,  r*   sizes=r  r   r   N)	r
   r!   r   r%   r  rc   r   rE   r   )rd   r  rg   r  rO   rh   rf   r!   r   r   r   test_zero_mask_convolve  s   
z$MaskTypeTest.test_zero_mask_convolvec           	   	   C   s   dD ]L}t jj|dd}dD ]?}t jj|dd}dD ]2}d| d| d| }t j|}|||}| |t jj| | ||| | | || qqqdS )	zEnsures convolve correctly handles zero sized masks
        when using an output mask argument.

        Tests the different combinations of sized and zero sized masks.
        ))r`   r   [   r   r   Z   r*   Trr   ))r   r`   )r   r   )r   >   r*   )r   r3  r4  r*   r8  r  N)r
   r!   r   r  rc   r  rE   r   )	rd   r  rg   r  rh   Zoutput_sizerO   output_maskr!   r   r   r   )test_zero_mask_convolve__with_output_mask  s   z6MaskTypeTest.test_zero_mask_convolve__with_output_maskc                 C   sd   d}dD ]+}d| }t j|}| }| |t jj| | | | | | || qdS )z?Ensures connected_component correctly handles zero sized masks.r   )r6  )r   P   r*   r{   N)r
   r!   r   r  rc   rE   r   rP   )rd   re   r   rO   r!   cc_maskr   r   r   "test_zero_mask_connected_component  s   
z/MaskTypeTest.test_zero_mask_connected_componentc              	   C   r  )zdEnsures connected_component correctly handles zero sized masks
        when using an index argument.)r:  r<  r*   r*   N)r
   r!   r   rj   r   r  )rd   r   r!   rB  r   r   r   +test_zero_mask_connected_component__indexed  s   z8MaskTypeTest.test_zero_mask_connected_component__indexedc                 C   r+  )z@Ensures connected_components correctly handles zero sized masks.)r  r3  r*   r{   N)r
   r!   r   r  r  )rd   Zexpected_cc_masksr   r!   Zcc_masksr   r   r   #test_zero_mask_connected_components  r1  z0MaskTypeTest.test_zero_mask_connected_componentsc                 C   r+  )z>Ensures get_bounding_rects correctly handles zero sized masks.))r   r   )r   r  r*   r{   N)r
   r!   r   r  r  )rd   expected_bounding_rectsr   r!   bounding_rectsr   r   r   !test_zero_mask_get_bounding_rects   s   z.MaskTypeTest.test_zero_mask_get_bounding_rectsc                 C   s   t d}t d}dD ]:}t |td}|| dD ])}t jj|dd}|j||d}| || | 	|
 | d	|vrEt| || qqd
S )zCEnsures to_surface correctly handles zero sized masks and surfaces.r&  r  )r   )r   r   )r   r   r*   r   ))r   r   )r   r   r*   Trr   r;  r   N)r
   r  r   r  rs   r!   r   r  r  rE   r   rL   )rd   
mask_colorZ
surf_colorr  r   r   r!   r  r   r   r   test_zero_mask_to_surface  s   


z&MaskTypeTest.test_zero_mask_to_surfacec                 C   sR   t d}dD ]}t jj|dd}|j|d}| |t j | | | qdS )z|Ensures to_surface correctly handles zero sized masks and surfaces
        when it has to create a default surface.
        r&  )r  r  r*   Trr   r;  N)	r
   r  r!   r   r  rc   r   rE   r   )rd   rI  r   r!   r  r   r   r   )test_zero_mask_to_surface__create_surface!  s   
z6MaskTypeTest.test_zero_mask_to_surface__create_surfaceN)F)__name__
__module____qualname__r   unittestskipIfr  ri   rm   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  r  r  r%  r'  r(  r)  r+  r5  r6  r9  r>  r@  rC  rH  rI  rK  rQ  rS  rU  rW  rY  r[  r]  r`  rc  re  rf  rg  ri  rj  rl  rm  rn  rs  ru  rw  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ZexpectedFailurer  r  r#  r%  r(  r,  r0  r1  r5  r>  r@  rE  rG  rK  rL  rO  rQ  rV  rX  rY  rZ  r`  ra  rk  rl  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  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*  r0  r2  r9  r@  rC  rD  rE  rH  rJ  rK  r   r   r   r   rU      s   





7


#$








#


#


$

"
#
"
(









 !&

*

 !&

*



	

,#&+
2

y
 
!'- TW%A ""$ ""$"$"$"
$D#
$5+! 3 5
 8
#
6	

	rU   c                           e Zd ZdZ fddZ  ZS )SubMaskz4Subclass of the Mask class to help test subclassing.c                    s   t  j|i | d| _d S )NT)super__init__test_attribute)rd   r4  r   	__class__r   r   rT  3  s   
zSubMask.__init__)rL  rM  rN  __doc__rT  __classcell__r   r   rV  r   rR  0      rR  c                       rQ  )SubMaskCopy;Subclass of the Mask class to help test copying subclasses.c                       t   }| j|_|S r=   )rS  r   rU  rd   r   rV  r   r   r   ;     
zSubMaskCopy.copyrL  rM  rN  rX  r   rY  r   r   rV  r   r[  8  rZ  r[  c                       rQ  )SubMaskDunderCopyr\  c                    r]  r=   )rS  __copy__rU  r^  rV  r   r   rb  D  r_  zSubMaskDunderCopy.__copy__)rL  rM  rN  rX  rb  rY  r   r   rV  r   ra  A  rZ  ra  c                       rQ  )SubMaskCopyAndDunderCopyr\  c                    s
   t   S r=   )rS  r   r4  rV  r   r   r   M  s   
zSubMaskCopyAndDunderCopy.copyr`  r   r   rV  r   rc  J  rZ  rc  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8S )9MaskSubclassTestzTest subclassed Masks.c                 C   s8   t ddd}| |tjj | |t  | |j dS )z)Ensures the Mask class can be subclassed.r   Trr   N)rR  rc   r
   r!   r   r  rU  rR  r   r   r   test_subclass_maskT  s   z#MaskSubclassTest.test_subclass_maskc                 C   sl   t ddd}| t|fD ]$}| |tjj | |t  | || t| || | t	|d qdS )z(Ensures copy works for subclassed Masks.r   r	   Trr   rU  N)
rR  r   rc   r
   r!   r   r   rT   assertFalsehasattrrd   r!   r   r   r   r   test_subclass_copy\  s   z#MaskSubclassTest.test_subclass_copyc                 C   s   t ddd}t| t|fD ]1\}}| |tjj | |t  | || t| || d|kr<| 	t
|d q| |j qdS )z8Ensures copy works for subclassed Masks overriding copy.rf  Trr   r   rU  N)r[  r  r   rc   r
   r!   r   r   rT   rg  rh  r  rU  )rd   r!   r   r   r   r   r   !test_subclass_copy__override_copyi  s   z2MaskSubclassTest.test_subclass_copy__override_copyc                 C   h   t ddd}| t|fD ]"}| |tjj | |t  | || t| || | |j	 qdS )z<Ensures copy works for subclassed Masks overriding __copy__.rf  Trr   N)
ra  r   rc   r
   r!   r   r   rT   r  rU  ri  r   r   r   (test_subclass_copy__override_dunder_copyz  s   z9MaskSubclassTest.test_subclass_copy__override_dunder_copyc                 C   rl  )zAEnsures copy works for subclassed Masks overriding copy/__copy__.rf  Trr   N)
rc  r   rc   r
   r!   r   r   rT   r  rU  ri  r   r   r   .test_subclass_copy__override_both_copy_methods  s   z?MaskSubclassTest.test_subclass_copy__override_both_copy_methodsc                 C   s$   d}t |}| }| || dS )z,Ensures get_size works for subclassed Masks.r  N)rR  r   rE   r  r   r   r   test_subclass_get_size     z'MaskSubclassTest.test_subclass_get_sizec                 C   s2   t dd}t|jdd}| }| || dS )z,Ensures get_rect works for subclassed Masks.r*   )r   r   Trr   N)r
   r&   rR  r   rC   rE   )rd   r   r!   r:   r   r   r   test_subclass_mask_get_rect  s   z,MaskSubclassTest.test_subclass_mask_get_rectc                 C   s*   d}t ddd}|d}| || dS )z*Ensures get_at works for subclassed Masks.r   r   Trr   r*   N)rR  r   rE   )rd   r   r!   bitr   r   r   test_subclass_get_at  s   
z%MaskSubclassTest.test_subclass_get_atc                 C   sH   d}d}d}t ddd}|| | ||| | | | dS )z*Ensures set_at works for subclassed Masks.r   r*   Fr  r   N)rR  r   rE   r   rP   )rd   r   re   rK   r!   r   r   r   test_subclass_set_at  s   
z%MaskSubclassTest.test_subclass_set_atc                 C   sl   d}d}t jjd|dt|df}t jjd|dt|df}|D ]}|D ]}||d}| || q$q dS )z+Ensures overlap works for subclassed Masks.r*   r  Tr   N)r
   r!   r   rR  r   rE   )rd   r   r   masks	arg_masksr!   arg_maskr   r   r   r   test_subclass_overlap  s   z&MaskSubclassTest.test_subclass_overlapc                 C   sx   d}|d |d  }t jjd|dt|df}t jjd|dt|df}|D ]}|D ]}||d}| || q*q&dS )z0Ensures overlap_area works for subclassed Masks.r   r   r   Tr   r*   N)r
   r!   r   rR  rQ   rE   )rd   r   re   ru  rv  r!   rw  r  r   r   r   test_subclass_overlap_area  s   z+MaskSubclassTest.test_subclass_overlap_areac                 C   s   d}|d |d  }t jjd|dt|df}t jjd|dt|df}|D ]+}|D ]&}||d}| |t jj | |t | | | | |	 | q*q&dS )z0Ensures overlap_mask works for subclassed Masks.r   r   r   Tr   r*   N)
r
   r!   r   rR  r  rc   assertNotIsInstancerE   rP   r   )rd   rf   re   ru  rv  r!   rw  r  r   r   r   test_subclass_overlap_mask  s"   z+MaskSubclassTest.test_subclass_overlap_maskc                 C   <   d}|d |d  }t d|d}|  | | | dS )z(Ensures fill works for subclassed Masks.r  r   r   Fr   N)rR  rs   rE   rP   rd   r   re   r!   r   r   r   test_subclass_fill  
   z#MaskSubclassTest.test_subclass_fillc                 C   s.   d}d}t |d}|  | | | dS )z)Ensures clear works for subclassed Masks.)ry   r   r   TN)rR  r  rE   rP   r}  r   r   r   test_subclass_clear  s
   
z$MaskSubclassTest.test_subclass_clearc                 C   r|  )z*Ensures invert works for subclassed Masks.r   ry   r   r   Fr   N)rR  rA  rE   rP   r}  r   r   r   test_subclass_invert  r  z%MaskSubclassTest.test_subclass_invertc                 C   sF   d}t d}||}| |tjj | |t  | | | dS )z)Ensures scale works for subclassed Masks.r*  r  N)	rR  rM  rc   r
   r!   r   rz  rE   r   )rd   rf   r!   Zscaled_maskr   r   r   test_subclass_scale  s   
z$MaskSubclassTest.test_subclass_scalec                 C   sz   d}|d |d  }t jjd|dt|df}t j|t|fD ]}|D ]}|  ||d | | | q%q!dS )z(Ensures draw works for subclassed Masks.r   r   r   Tr   r*   N)r
   r!   r   rR  r  r  rE   rP   )rd   r   re   rv  r!   rw  r   r   r   test_subclass_draw  s   z#MaskSubclassTest.test_subclass_drawc                 C   st   d}d}t j|dt|df}t j|dt|df}|D ]}|D ]}|  ||d | | | q"qdS )z)Ensures erase works for subclassed Masks.r  r   Tr*   N)r
   r!   r   rR  rs   rd  rE   rP   )rd   r   re   ru  rv  r!   rw  r   r   r   test_subclass_erase/  s   z$MaskSubclassTest.test_subclass_erasec                 C   sH   d}|d |d  d }t d|d}|dd | }| || dS )z)Ensures count works for subclassed Masks.r*  r   r   Tr   rW   N)rR  r   rP   rE   )rd   r   re   r!   rP   r   r   r   test_subclass_count?  s   z$MaskSubclassTest.test_subclass_countc                 C   s(   d}d}t d}| }| || dS )z,Ensures centroid works for subclassed Masks.r*   r   N)rR  ry  rE   )rd   rz  r   r!   ry  r   r   r   test_subclass_centroidJ  s
   z'MaskSubclassTest.test_subclass_centroidc                 C   s&   d}t dd}| }| || dS )z)Ensures angle works for subclassed Masks.r  r   rb   N)rR  r  r  )rd   r  r!   r  r   r   r   test_subclass_angleT  s   
z$MaskSubclassTest.test_subclass_anglec                 C   $   g }t d}| }| || dS )z+Ensures outline works for subclassed Masks.r  N)rR  r  r  )rd   Zexpected_outliner!   r  r   r   r   test_subclass_outline]  rp  z&MaskSubclassTest.test_subclass_outlinec                 C   s8  d\}}||f}d}t d|d d t d|d d f}tj|t|f}tj|t|f}tj|t|fD ]_}|D ]Z}	||	}
| |
tjj | |
t | |
	 | | |

 | |D ]2}||	|}
| |
tjj | |
	 | | |

 | t|tr| |
t qe| |
t qeq>q:dS )z,Ensures convolve works for subclassed Masks.r   r   r	   r   N)r%   r
   r!   r   rR  r  rc   rz  rE   rP   r   
isinstance)rd   r2   r3   r   re   rf   rv  Zoutput_masksr!   rw  r  r?  r   r   r   test_subclass_convolvef  s0   $

z'MaskSubclassTest.test_subclass_convolvec                 C   sX   d}d}t |}| }| |tjj | |t  | | | | |	 | dS )z7Ensures connected_component works for subclassed Masks.r   r  N)
rR  r  rc   r
   r!   r   rz  rE   rP   r   )rd   re   rf   r!   rB  r   r   r   !test_subclass_connected_component  s   z2MaskSubclassTest.test_subclass_connected_componentc                 C   r  )z8Ensures connected_components works for subclassed Masks.r   N)rR  r  r  )rd   Zexpected_ccsr!   Zccsr   r   r   "test_subclass_connected_components  rp  z3MaskSubclassTest.test_subclass_connected_componentsc                 C   r  )z6Ensures get_bounding_rects works for subclassed Masks.r   N)rR  r  r  )rd   rF  r!   rG  r   r   r    test_subclass_get_bounding_rects  rp  z1MaskSubclassTest.test_subclass_get_bounding_rectsc                 C   sr   t d}d}t|dd}t |td}|t d |j||d}| || | |	 | t
| || dS )	z.Ensures to_surface works for subclassed Masks.r&  r   Trr   r   r  r;  N)r
   r  rR  r   r  rs   r  r  rE   r   rL   r'  r   r   r   test_subclass_to_surface  s   
z)MaskSubclassTest.test_subclass_to_surfaceN)rL  rM  rN  rX  re  rj  rk  rm  rn  ro  rq  rs  rt  rx  ry  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rd  Q  s:    			



		!		rd  zpypy has lots of mask failuresc                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )MaskModuleTestc              	   C   s  d}g d}d}|d |d  }d}dD ]m}t |t|}t|D ]_}||d< || |dk r7|d	d }d
d|d ||d ddh}	|	D ]9}
d| d| d|
 }||
krZ|}n|}t jj||
d}| |t jj	| | 
| || | 
| || qFq!qdS )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      r7  r   )r`   r&  r   r   r  r   r   r*   rZ   r7  depth=z, alpha=z, threshold=)r   r    N)r
   r   r  r   rs   r   r!   r  rc   r   rE   r   rP   )rd   threshold_countr  rf   Zall_set_countZnone_set_countr  r   alphaZthreshold_test_valuesr    rO   re   r!   r   r   r   test_from_surface  s6   	
z MaskModuleTest.test_from_surfacec                 C   s   d}d}g d}|df}t j|dd}t |td}|  t|D ]}||d< ||d	f| q"|  t|D ]@}d
| }	||d	fd	 | }
t j	
||}| |t j	j|	 | | ||	 | | |
|	 | ||||
|	 q9dS )a  Ensures from_surface creates a mask with the correct bits set
        when pixels have different alpha values (32 bits surfaces).

        This test checks the masks created by the from_surface function using
        a 32 bit surface. The surface is created with each pixel having a
        different alpha value (0-255). This surface is tested over a range
        of threshold values (0-255).
        r*   r  )r  r  r  r   r   Trr   r   r   r   
threshold=N)r
   r   r   r  rD   r   r   rF   rP   r!   r  rc   rE   r   rQ   )rd   r   r  r  rf   r  r   r-   r    rO   re   r!   r   r   r   )test_from_surface__different_alphas_32bit  s.   	
z8MaskModuleTest.test_from_surface__different_alphas_32bitc                 C   s  d}g d}|df}t |td}|  t|D ]}||d< ||df| q|  t }t }t|D ]%}|	|dfd }	|	|vrK|g||	< n||	 
| ||	k r[|| q6g }
d}t |}t j|dd	}| D ]@}|D ];}||v r|

||d |f qt|d
 d }t|D ]
}||dfd qt j|dd	}||| |

|||f  qp|
D ]C\}}}| }t||D ]4}d| }t j||}| |t jj| | | || | | || | ||||| qqdS )a  Ensures from_surface creates a mask with the correct bits set
        when pixels have different alpha values (16 bit surfaces).

        This test checks the masks created by the from_surface function using
        a 16 bit surface. Each pixel of the surface is set with a different
        alpha value (0-255), but since this is a 16 bit surface the requested
        alpha value can differ from what is actually set. The resulting surface
        will have groups of alpha values which complicates the test as the
        alpha groups will all be set/unset at a given threshold. The setup
        calculates these groups and an expected mask for each. This test data
        is then used to test each alpha grouping over a range of threshold
        values.
        r  )n   x      r   r   r  r   r   r*   Trr   rZ   r  N)r
   r   r  rD   r   r   rF   r   setr   r  addr   r   rd  rP   r!   r  rc   rE   r   rQ   )rd   r  r  rf   r   r-   Zalpha_thresholdsZspecial_thresholdsr    r  r!  r   Z
erase_maskZexp_maskZ
thresholdsZto_thresholdZthresfrom_thresholdr  re   rO   r!   r   r   r   )test_from_surface__different_alphas_16bit  s`   


z8MaskModuleTest.test_from_surface__different_alphas_16bitc           	      C   s   d}d}d}dD ]@}d| }t |d|}|D ]/}|| ||  t j|}| |t jj| | 	|
 || | 	| || qqdS )zEnsures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with the colorkey color so the resulting masks
        are expected to have no bits set.
        )r.  r   r  r   r  r7  r7  r7  rh  r   r  r  N)r
   r   set_colorkeyrs   r   r!   r  rc   r   rE   r   rP   )	rd   	colorkeysrf   re   r  rO   r   colorkeyr!   r   r   r   -test_from_surface__with_colorkey_mask_cleareda  s   

z<MaskModuleTest.test_from_surface__with_colorkey_mask_clearedc           
      C   s   d}d}d}|d |d  }dD ]>}d| }t |d|}|| |D ](}|| t j|}	| |	t jj| | |		 || | |	
 || q%qdS )	zEnsures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with a color that is not the colorkey color so
        the resulting masks are expected to have all bits set.
        )r.  r   )r  r   r  r  r  r   r   r   r  r  N)r
   r   rs   r  r!   r  rc   r   rE   r   rP   )
rd   r  r  rf   re   r  rO   r   r  r!   r   r   r   ,test_from_surface__with_colorkey_mask_filled|  s    


z;MaskModuleTest.test_from_surface__with_colorkey_mask_filledc                 C   s   dd }d}d}d}t j|}||jddg|R   | }d}d	D ]J}d
| }	t |d|}
||
j||g|R   |
| t j|
}| |t jj|	 | 	|
 ||	 | 	| ||	 | 	|||||	 q#dS )a  Ensures from_surface creates a mask with the correct bits set
        when the surface uses a colorkey.

        The surface is filled with alternating pixels of colorkey and
        non-colorkey colors, so the resulting masks are expected to have
        alternating bits set.
        c                    s<   d} fddt |D D ]}| ||r|n| | }qd S )NFc                 3   rh  r=   rp  re  rf  r   r   r1     rr  zbMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate.<locals>.<genexpr>rp  )func	set_valueunset_valuer2   r3   ZsetbitrK   r   rf  r   	alternate  s
   zOMaskModuleTest.test_from_surface__with_colorkey_mask_pattern.<locals>.alternate)r   r  r  )r  r-  r5  )r`   r	   r   r   r*   r  r  N)r
   r!   r   r   rP   r   r  r  rc   rE   r   rQ   )rd   r  r  r  rf   r  re   r   r  rO   r   r!   r   r   r   -test_from_surface__with_colorkey_mask_pattern  s*   	

z<MaskModuleTest.test_from_surface__with_colorkey_mask_patternc                 C   s  g d}|D ]0}t jdd|}|dd t j|dd}| }| | d | | t 	dg q|D ]H}t jdd|}t jdd|}|d	 |d
 |d	d t jj|dd|d}| 
|t jj | | d | | t 	dg q9dS )z*Does mask.from_threshold() work correctly?r  r  r   )r5  r5  r   r   r  r  r  r  r  r  r   r  r  r7  r  r  r  r7  i  r   r   r      r  r  r  r  r  r  r  )r   colorr    Zothersurfacer   N)r
   r   r   rs   r!   r  r  rE   rP   r&   rc   r   )rd   r-   r   surfr!   r  surf2r   r   r   test_from_threshold  s4   

z"MaskModuleTest.test_from_thresholdc                 C   sH   dD ]}t jt |}| |t jjd|  | | | qdS )z?Ensures from_surface can create masks from zero sized surfaces.r   r{   N)r
   r!   r  r   rc   ZMaskTyperE   r   rl   r   r   r   test_zero_size_from_surface  s
   z*MaskModuleTest.test_zero_size_from_surfacec           	      C   s  g d}d}|D ]w}|D ]*}t j|d|}|dd t j|dd}| | d | }| |g  q|D ]E}t j|d|}t j|d|}|d |d	 |dd
 t j|dd|}| 	|t jj
 | | d | }| |g  q9qd S )Nr  r   r   r  r  r  r  r  r  r  r  )r
   r   r   rs   r!   r  rE   rP   r  rc   r   )	rd   r-   r0   r   r   r  r!   r  r  r   r   r   test_zero_size_from_threshold  s6   

z,MaskModuleTest.test_zero_size_from_thresholdc                 C   s   d}d}d}t |}|D ]}||d qt|}d|jd  }|D ]}|\}}	|| }
| ||
|	f || ? d@ dd| d q#|D ]}|\}}	|| }
| ||
|	f || ? d@ dd| d	 qEd S )
N)i  r   )rV   )r   r  )   r=  )r*   )r   r  )r  r;  r   r  zthe pixel at z is not set to 1r   z is not set to 0)r
   r   r   
memoryviewstridesrE   )rd   r   Z
pixels_setZpixels_unsetr!   pointviewZintwidthr   r   colr   r   r   test_buffer_interface	  s2   


z$MaskModuleTest.test_buffer_interfaceN)rL  rM  rN  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    0&T("!r  __main__)r   )r   r=   )#collectionsr   r   platformr   rO  r  r
   Zpygame.localsZpygame.mathr   python_implementationr  r   r#   r)   r4   r5   r;   rL   rN   rT   ZTestCaserU   r!   r   rR  r[  ra  rc  rd  rP  r  rL  mainr   r   r   r   <module>   s    



	

                                           I		  
f  t