<s> import unittest <EOL> from unittest . mock import Mock <EOL> from unittest . mock import patch <EOL> from pico8 . gfx import gfx <EOL> from pico8 . map import map <EOL> class TestMap ( unittest . TestCase ) : <EOL> def testGetCell ( self ) : <EOL> m = map . Map . empty ( ) <EOL> m . _data [ <NUM_LIT:0> : <NUM_LIT> ] = ( b'<STR_LIT>' <EOL> b'<STR_LIT>' ) * <NUM_LIT:8> <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> self . assertEqual ( i , m . get_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> ) ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> self . assertEqual ( <NUM_LIT:0> , m . get_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:1> ) ) <EOL> def testGetCellSharedMem ( self ) : <EOL> m = map . Map . empty ( ) <EOL> m . _gfx = gfx . Gfx . empty ( ) <EOL> m . _gfx . _data [ <NUM_LIT> : <NUM_LIT> ] = ( b'<STR_LIT>' <EOL> b'<STR_LIT>' ) * <NUM_LIT:8> <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> self . assertEqual ( i , m . get_cell ( i , <NUM_LIT:32> ) ) <EOL> def testSetCell ( self ) : <EOL> m = map . Map . empty ( ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> m . set_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> , i ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> self . assertEqual ( i , m . get_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> ) ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> self . assertEqual ( <NUM_LIT:0> , m . get_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:1> ) ) <EOL> def testGetRectTiles ( self ) : <EOL> m = map . Map . empty ( ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> m . set_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> , i ) <EOL> tile_rect = m . get_rect_tiles ( <NUM_LIT:2> , <NUM_LIT:0> , width = <NUM_LIT:8> , height = <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( tile_rect ) ) <EOL> self . assertEqual ( <NUM_LIT:8> , len ( tile_rect [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( bytearray ( <EOL> b'<STR_LIT>' ) , <EOL> tile_rect [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( bytearray ( b'<STR_LIT:\x00>' ) * <NUM_LIT:8> , tile_rect [ <NUM_LIT:1> ] ) <EOL> def testGetRectTilesOffEdge ( self ) : <EOL> m = map . Map . empty ( ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> m . set_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> , i ) <EOL> tile_rect = m . get_rect_tiles ( <NUM_LIT> , <NUM_LIT:0> , width = <NUM_LIT:8> , height = <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( tile_rect ) ) <EOL> self . assertEqual ( <NUM_LIT:8> , len ( tile_rect [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( bytearray ( <EOL> b'<STR_LIT>' ) , <EOL> tile_rect [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( bytearray ( b'<STR_LIT:\x00>' ) * <NUM_LIT:8> , tile_rect [ <NUM_LIT:1> ] ) <EOL> def testGetRectSharedMem ( self ) : <EOL> m = map . Map . empty ( ) <EOL> m . _gfx = gfx . Gfx . empty ( ) <EOL> m . _gfx . _data [ <NUM_LIT> : <NUM_LIT> ] = ( b'<STR_LIT>' <EOL> b'<STR_LIT>' ) * <NUM_LIT:8> <EOL> tile_rect = m . get_rect_tiles ( <NUM_LIT:2> , <NUM_LIT:32> , width = <NUM_LIT:8> , height = <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( tile_rect ) ) <EOL> self . assertEqual ( <NUM_LIT:8> , len ( tile_rect [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( bytearray ( <EOL> b'<STR_LIT>' ) , <EOL> tile_rect [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( bytearray ( b'<STR_LIT:\x00>' ) * <NUM_LIT:8> , tile_rect [ <NUM_LIT:1> ] ) <EOL> def testSetRectTiles ( self ) : <EOL> m = map . Map . empty ( ) <EOL> m . _gfx = gfx . Gfx . empty ( ) <EOL> m . set_rect_tiles ( [ [ <NUM_LIT:1> ] * <NUM_LIT:4> ] * <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> result = m . get_rect_tiles ( <NUM_LIT:0> , <NUM_LIT:0> , width = <NUM_LIT:7> , height = <NUM_LIT:7> ) <EOL> self . assertEqual ( <EOL> [ bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) , <EOL> bytearray ( b'<STR_LIT>' ) ] , result ) <EOL> def testGetRectPixels ( self ) : <EOL> m = map . Map . empty ( ) <EOL> m . _gfx = gfx . Gfx . empty ( ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> m . _gfx . set_sprite ( i , [ [ i ] * <NUM_LIT:8> ] * <NUM_LIT:8> ) <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> for j in range ( <NUM_LIT:8> ) : <EOL> m . set_cell ( i + <NUM_LIT:16> * j , <NUM_LIT:0> , i ) <EOL> pixels = m . get_rect_pixels ( <NUM_LIT:2> , <NUM_LIT:0> , width = <NUM_LIT:3> , height = <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:16> , len ( pixels ) ) <EOL> self . assertEqual ( <NUM_LIT> , len ( pixels [ <NUM_LIT:0> ] ) ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:8> ) : <EOL> self . assertEqual ( bytearray ( b'<STR_LIT>' * <NUM_LIT:8> + b'<STR_LIT>' * <NUM_LIT:8> + b'<STR_LIT>' * <NUM_LIT:8> ) , <EOL> pixels [ i ] ) <EOL> for i in range ( <NUM_LIT:8> , <NUM_LIT:16> ) : <EOL> self . assertEqual ( bytearray ( b'<STR_LIT:\x00>' * <NUM_LIT> ) , pixels [ i ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
