示例#1
0
def test_standard_text_to_block():
    b = Block()

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
    assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0, 0, 0, 0, 0])

    b.from_list([0x66] * 10)
    standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
    assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0x66, 0x66, 0x66, 0x66, 0x66])
示例#2
0
def test_standard_text_to_block():
    b = Block()

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
    assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0, 0, 0, 0, 0])

    b.from_list([0x66] * 10)
    standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
    assert_list_equal(b.to_list(),
                      [132, 149, 163, 164, 0, 0x66, 0x66, 0x66, 0x66, 0x66])
示例#3
0
    def test_to_block(self):
        block = Block()

        s = SwirlFrameRow(x1=3, x2=5, x3=55, x4=92)
        block.from_list([33, 33, 33, 33, 33])
        s.to_block(block, 1, False)
        assert_equal([33, 3, 5, 55, 92], block.to_list())

        s = SwirlFrameRow(x1=3, x2=5, x3=0xff, x4=0)
        block.from_list([33, 33, 33, 33, 33])
        s.to_block(block, 2, True)
        assert_equal([33, 33, 3, 5, 33], block.to_list())
示例#4
0
    def test_to_block(self):
        block = Block()

        s = SwirlFrameRow(x1=3, x2=5, x3=55, x4=92)
        block.from_list([33, 33, 33, 33, 33])
        s.to_block(block, 1, False)
        assert_equal([33, 3, 5, 55, 92], block.to_list())

        s = SwirlFrameRow(x1=3, x2=5, x3=0xff, x4=0)
        block.from_list([33, 33, 33, 33, 33])
        s.to_block(block, 2, True)
        assert_equal([33, 33, 3, 5, 33], block.to_list())
示例#5
0
def test_standard_text_to_block_with_brackets():
    b = Block()

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="[01 02 03 04]", max_length=10)
    assert_list_equal(b.to_list(), [0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, 0, 0])

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="[]", max_length=10)
    assert_list_equal(b.to_list(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="Te[ab cd ef]st", max_length=10)
    assert_list_equal(b.to_list(), [132, 149, 0xab, 0xcd, 0xef, 163, 164, 0, 0, 0])
示例#6
0
def test_write_2bpp_graphic_to_block():
    source = [[2, 1, 2, 3, 2, 1, 2, 1],
              [2, 3, 1, 0, 2, 3, 2, 2],
              [3, 0, 3, 2, 2, 2, 0, 2],
              [1, 3, 3, 0, 2, 0, 2, 3],
              [1, 0, 1, 1, 0, 3, 3, 3],
              [1, 3, 3, 3, 3, 2, 1, 2],
              [2, 2, 3, 1, 2, 2, 1, 0],
              [2, 0, 3, 3, 2, 3, 1, 0]]
    target = Block()
    target.from_list([0] * 16)
    assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
    assert_list_equal(target.to_list(),
                      [0b01010101,
                       0b10111010,
                       0b01100100,
                       0b11001111,
                       0b10100000,
                       0b10111101,
                       0b11100001,
                       0b01101011,
                       0b10110111,
                       0b00000111,
                       0b11111010,
                       0b01111101,
                       0b00110010,
                       0b11101100,
                       0b00110110,
                       0b10111100])
示例#7
0
def test_write_2bpp_graphic_to_block_offset_xy():
    source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 2, 1, 2, 3, 2, 1, 2, 1],
              [0, 0, 2, 3, 1, 0, 2, 3, 2, 2],
              [0, 0, 3, 0, 3, 2, 2, 2, 0, 2],
              [0, 0, 1, 3, 3, 0, 2, 0, 2, 3],
              [0, 0, 1, 0, 1, 1, 0, 3, 3, 3],
              [0, 0, 1, 3, 3, 3, 3, 2, 1, 2],
              [0, 0, 2, 2, 3, 1, 2, 2, 1, 0],
              [0, 0, 2, 0, 3, 3, 2, 3, 1, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    target = Block()
    target.from_list([0xff] * 18)
    assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=1, x=2, y=1, bit_offset=0))
    assert_list_equal(target.to_list(),
                      [0xff,
                       0b01010101,
                       0b10111010,
                       0b01100100,
                       0b11001111,
                       0b10100000,
                       0b10111101,
                       0b11100001,
                       0b01101011,
                       0b10110111,
                       0b00000111,
                       0b11111010,
                       0b01111101,
                       0b00110010,
                       0b11101100,
                       0b00110110,
                       0b10111100,
                       0xff])
    def test_to_block(self):
        for test_case in TEST_CASES:
            block_size = MapEnemyGroupTableEntry.to_block_size(test_case["value_rep"])
            assert_equal(len(test_case["block_rep"]), block_size)

            block = Block(size=block_size)
            MapEnemyGroupTableEntry.to_block(block, 0, test_case["value_rep"])
            assert_list_equal(test_case["block_rep"], block.to_list())
示例#9
0
 def test_to_block(self):
     block = Block()
     block.from_list([0] * 2)
     self.color.r = 248
     self.color.g = 144
     self.color.b = 16
     self.color.to_block(block, 0)
     assert_list_equal(block.to_list(), [0x5f, 0x0a])
示例#10
0
 def test_to_block(self):
     block = Block()
     block.from_list([0] * 2)
     self.color.r = 248
     self.color.g = 144
     self.color.b = 16
     self.color.to_block(block, 0)
     assert_list_equal(block.to_list(), [0x5f, 0x0a])
示例#11
0
    def test_to_block(self):
        for test_case in TEST_CASES:
            block_size = MapEnemyGroupTableEntry.to_block_size(
                test_case["value_rep"])
            assert_equal(len(test_case["block_rep"]), block_size)

            block = Block(size=block_size)
            MapEnemyGroupTableEntry.to_block(block, 0, test_case["value_rep"])
            assert_list_equal(test_case["block_rep"], block.to_list())
示例#12
0
    def test_to_block(self):
        block = Block()
        block.from_list([0] * len(self.BLOCK_DATA))
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.values = self.TABLE_VALUES
        table.to_block(block, 0)

        assert_list_equal(block.to_list(), self.BLOCK_DATA)
示例#13
0
    def test_to_block(self):
        block = Block()
        block.from_list([0] * len(self.BLOCK_DATA))
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.values = self.TABLE_VALUES
        table.to_block(block, 0)

        assert_list_equal(block.to_list(), self.BLOCK_DATA)
示例#14
0
def test_standard_text_to_block_with_brackets():
    b = Block()

    b.from_list([0] * 10)
    standard_text_to_block(block=b,
                           offset=0,
                           text="[01 02 03 04]",
                           max_length=10)
    assert_list_equal(b.to_list(), [0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, 0, 0])

    b.from_list([0] * 10)
    standard_text_to_block(block=b, offset=0, text="[]", max_length=10)
    assert_list_equal(b.to_list(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

    b.from_list([0] * 10)
    standard_text_to_block(block=b,
                           offset=0,
                           text="Te[ab cd ef]st",
                           max_length=10)
    assert_list_equal(b.to_list(),
                      [132, 149, 0xab, 0xcd, 0xef, 163, 164, 0, 0, 0])
示例#15
0
 def test_to_block_4bpp(self):
     tileset = EbGraphicTileset(num_tiles=1, tile_width=8, tile_height=8)
     tileset.tiles = [None]
     tileset.tiles[0] = [
         [8, 1, 12, 9, 6, 5, 3, 2],
         [11, 5, 8, 14, 1, 7, 15, 0],
         [8, 13, 3, 7, 2, 0, 2, 3],
         [10, 0, 4, 14, 7, 10, 11, 9],
         [8, 8, 12, 9, 13, 12, 2, 6],
         [11, 14, 14, 4, 14, 4, 10, 7],
         [12, 2, 12, 8, 4, 15, 12, 14],
         [10, 13, 12, 1, 10, 11, 11, 2],
     ]
     block = Block()
     block.from_list([0] * 32)
     tileset.to_block(block, 0, 4)
     assert_list_equal(
         block.to_list(),
         [
             0b01010110,
             0b00001011,
             0b11001110,
             0b10010110,
             0b01110001,
             0b00111011,
             0b00001011,
             0b10011110,
             0b00011000,
             0b00000011,
             0b10000001,
             0b11101011,
             0b00000100,
             0b01000101,
             0b01010110,
             0b10001111,
             0b00101100,
             0b10110000,
             0b01010110,
             0b10110010,
             0b01010000,
             0b11000000,
             0b00111000,
             0b10010111,
             0b00101101,
             0b11111100,
             0b01111101,
             0b11101010,
             0b10101111,
             0b10110111,
             0b01100000,
             0b11101110,
         ],
     )
示例#16
0
def test_write_1bpp_graphic_to_block_rectangular_short():
    source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]]
    target = Block()
    target.from_list([0xeb] * 8)
    target[0] = 42
    assert_equal(
        6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6))
    assert_list_equal(target.to_list(), [
        42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000
    ])
示例#17
0
def test_write_1bpp_graphic_to_block():
    source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0],
              [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]]
    target = Block()
    target.from_list([32] * 10)
    assert_equal(
        8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8))
    assert_list_equal(target.to_list(), [
        32, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000, 0b01110001, 0b00000001, 32
    ])
示例#18
0
 def test_to_block_2bpp(self):
     tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8)
     tileset.tiles = [None, None]
     tileset.tiles[0] = [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2],
                         [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3],
                         [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2],
                         [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]]
     tileset.tiles[1] = [[1, 3, 3, 1, 3, 0, 2, 1], [3, 2, 2, 3, 3, 2, 2, 2],
                         [1, 1, 2, 2, 3, 0, 1, 1], [0, 3, 2, 2, 0, 0, 0, 3],
                         [3, 3, 0, 0, 1, 0, 1, 0], [2, 3, 1, 3, 3, 2, 1, 2],
                         [0, 0, 0, 1, 3, 2, 3, 3], [2, 2, 3, 2, 0, 0, 0, 1]]
     block = Block()
     block.from_list([0] * 32)
     tileset.to_block(block, 0, 2)
     assert_list_equal(
         block.to_list(),
         [
             0b01010101,  # Tile 1
             0b10111010,
             0b01100100,
             0b11001111,
             0b10100000,
             0b10111101,
             0b11100001,
             0b01101011,
             0b10110111,
             0b00000111,
             0b11111010,
             0b01111101,
             0b00110010,
             0b11101100,
             0b00110110,
             0b10111100,
             0b11111001,  # Tile 2
             0b01101010,
             0b10011000,
             0b11111111,
             0b11001011,
             0b00111000,
             0b01000001,
             0b01110001,
             0b11001010,
             0b11000000,
             0b01111010,
             0b11011101,
             0b00011011,
             0b00001111,
             0b00100001,
             0b11110000
         ])
示例#19
0
def test_write_1bpp_graphic_to_block_offset_source():
    source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
              [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1],
              [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 1, 0],
              [0, 0, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    target = Block()
    target.from_list([0] * 8)
    assert_equal(
        8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8))
    assert_list_equal(target.to_list(), [
        0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000,
        0b01110001, 0b00000001
    ])
示例#20
0
 def test_to_block_1bpp(self):
     tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8)
     tileset.tiles = [None, None]
     tileset.tiles[0] = [
         [0, 0, 0, 0, 0, 0, 1, 1],
         [0, 1, 1, 1, 0, 0, 0, 0],
         [0, 1, 0, 0, 1, 0, 0, 1],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [0, 1, 0, 0, 1, 0, 1, 0],
         [1, 1, 0, 0, 1, 0, 0, 0],
         [0, 1, 1, 1, 0, 0, 0, 1],
         [0, 0, 0, 0, 0, 0, 0, 1],
     ]
     tileset.tiles[1] = [
         [0, 0, 1, 0, 0, 0, 0, 0],
         [0, 0, 1, 1, 0, 0, 0, 0],
         [0, 0, 1, 0, 1, 0, 0, 0],
         [0, 0, 1, 0, 1, 0, 0, 0],
         [0, 1, 1, 0, 0, 0, 0, 0],
         [1, 1, 1, 0, 0, 0, 0, 0],
         [1, 1, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 1],
     ]
     block = Block()
     block.from_list([0] * 16)
     tileset.to_block(block, 0, 1)
     assert_list_equal(
         block.to_list(),
         [
             0b00000011,
             0b01110000,
             0b01001001,
             0b11110000,
             0b01001010,
             0b11001000,
             0b01110001,
             0b00000001,
             0b00100000,
             0b00110000,
             0b00101000,
             0b00101000,
             0b01100000,
             0b11100000,
             0b11000000,
             0b00000001,
         ],
     )
示例#21
0
def test_write_1bpp_graphic_to_block_rectangular_short():
    source = [[0, 0, 0, 0, 0, 0, 1, 1],
              [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1],
              [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0],
              [1, 1, 0, 0, 1, 0, 0, 0]]
    target = Block()
    target.from_list([0xeb] * 8)
    target[0] = 42
    assert_equal(6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6))
    assert_list_equal(target.to_list(), [42, 0xeb,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000])
示例#22
0
def test_write_2bpp_graphic_to_block():
    source = [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2],
              [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3],
              [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2],
              [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]]
    target = Block()
    target.from_list([0] * 16)
    assert_equal(
        16,
        write_2bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=0,
                                    x=0,
                                    y=0,
                                    bit_offset=0))
    assert_list_equal(target.to_list(), [
        0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101,
        0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101,
        0b00110010, 0b11101100, 0b00110110, 0b10111100
    ])
示例#23
0
 def test_to_block_1bpp(self):
     tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8)
     tileset.tiles = [None, None]
     tileset.tiles[0] = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0],
                         [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0],
                         [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0],
                         [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]]
     tileset.tiles[1] = [[0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0],
                         [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0],
                         [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0],
                         [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]
     block = Block()
     block.from_list([0] * 16)
     tileset.to_block(block, 0, 1)
     assert_list_equal(block.to_list(), [
         0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
         0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000,
         0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000,
         0b00000001
     ])
示例#24
0
def test_write_2bpp_graphic_to_block_offset_xy():
    source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 2, 3, 2, 1, 2, 1],
              [0, 0, 2, 3, 1, 0, 2, 3, 2, 2], [0, 0, 3, 0, 3, 2, 2, 2, 0, 2],
              [0, 0, 1, 3, 3, 0, 2, 0, 2, 3], [0, 0, 1, 0, 1, 1, 0, 3, 3, 3],
              [0, 0, 1, 3, 3, 3, 3, 2, 1, 2], [0, 0, 2, 2, 3, 1, 2, 2, 1, 0],
              [0, 0, 2, 0, 3, 3, 2, 3, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    target = Block()
    target.from_list([0xff] * 18)
    assert_equal(
        16,
        write_2bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=1,
                                    x=2,
                                    y=1,
                                    bit_offset=0))
    assert_list_equal(target.to_list(), [
        0xff, 0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000,
        0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010,
        0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 0xff
    ])
示例#25
0
def test_read_1bpp_graphic_from_block_rectangular_tall():
    source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0],
              [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1],
              [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0],
              [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0],
              [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0],
              [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]
    target = Block()
    target.from_list([
        42, 11, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 112, 113, 114, 115, 116,
        12, 21
    ])
    assert_equal(
        16, write_1bpp_graphic_to_block(source, target, 3, x=0, y=0,
                                        height=16))
    assert_list_equal(target.to_list(), [
        42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000,
        0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21
    ])
示例#26
0
def test_write_1bpp_graphic_to_block_offset_source():
    source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
              [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
              [0, 0, 0, 1, 0, 0, 1, 0, 0, 1],
              [0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
              [0, 0, 0, 1, 0, 0, 1, 0, 1, 0],
              [0, 0, 1, 1, 0, 0, 1, 0, 0, 0],
              [0, 0, 0, 1, 1, 1, 0, 0, 0, 1],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    target = Block()
    target.from_list([0] * 8)
    assert_equal(8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8))
    assert_list_equal(target.to_list(), [0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001])
示例#27
0
def test_write_1bpp_graphic_to_block():
    source = [[0, 0, 0, 0, 0, 0, 1, 1],
              [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1],
              [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0],
              [1, 1, 0, 0, 1, 0, 0, 0],
              [0, 1, 1, 1, 0, 0, 0, 1],
              [0, 0, 0, 0, 0, 0, 0, 1]]
    target = Block()
    target.from_list([32] * 10)
    assert_equal(8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8))
    assert_list_equal(target.to_list(), [32,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001,
                                         32])
示例#28
0
def test_read_1bpp_graphic_from_block_rectangular_tall():
    source = [[0, 0, 0, 0, 0, 0, 1, 1],
              [0, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 0, 1],
              [1, 1, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 1, 0, 1, 0],
              [1, 1, 0, 0, 1, 0, 0, 0],
              [0, 1, 1, 1, 0, 0, 0, 1],
              [0, 0, 0, 0, 0, 0, 0, 1],
              [0, 0, 1, 0, 0, 0, 0, 0],
              [0, 0, 1, 1, 0, 0, 0, 0],
              [0, 0, 1, 0, 1, 0, 0, 0],
              [0, 0, 1, 0, 1, 0, 0, 0],
              [0, 1, 1, 0, 0, 0, 0, 0],
              [1, 1, 1, 0, 0, 0, 0, 0],
              [1, 1, 0, 0, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 1]]
    target = Block()
    target.from_list([42, 11, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 112, 113, 114, 115, 116, 12, 21])
    assert_equal(16, write_1bpp_graphic_to_block(source, target, 3, x=0, y=0, height=16))
    assert_list_equal(target.to_list(), [42, 11, 99,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001,
                                         0b00100000,
                                         0b00110000,
                                         0b00101000,
                                         0b00101000,
                                         0b01100000,
                                         0b11100000,
                                         0b11000000,
                                         0b00000001,
                                         12, 21])
示例#29
0
 def test_to_block_4bpp(self):
     tileset = EbGraphicTileset(num_tiles=1, tile_width=8, tile_height=8)
     tileset.tiles = [None]
     tileset.tiles[0] = [[8, 1, 12, 9, 6, 5, 3, 2],
                         [11, 5, 8, 14, 1, 7, 15, 0],
                         [8, 13, 3, 7, 2, 0, 2, 3],
                         [10, 0, 4, 14, 7, 10, 11, 9],
                         [8, 8, 12, 9, 13, 12, 2, 6],
                         [11, 14, 14, 4, 14, 4, 10, 7],
                         [12, 2, 12, 8, 4, 15, 12, 14],
                         [10, 13, 12, 1, 10, 11, 11, 2]]
     block = Block()
     block.from_list([0] * 32)
     tileset.to_block(block, 0, 4)
     assert_list_equal(block.to_list(), [
         0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001,
         0b00111011, 0b00001011, 0b10011110, 0b00011000, 0b00000011,
         0b10000001, 0b11101011, 0b00000100, 0b01000101, 0b01010110,
         0b10001111, 0b00101100, 0b10110000, 0b01010110, 0b10110010,
         0b01010000, 0b11000000, 0b00111000, 0b10010111, 0b00101101,
         0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111,
         0b01100000, 0b11101110
     ])
示例#30
0
def test_write_4bpp_graphic_to_block():
    source = [[8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0],
              [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9],
              [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7],
              [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2]]
    target = Block()
    target.from_list([0] * 32)
    assert_equal(
        32,
        write_4bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=0,
                                    x=0,
                                    y=0,
                                    bit_offset=0))
    assert_list_equal(target.to_list(), [
        0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011,
        0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011,
        0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000,
        0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111,
        0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111,
        0b01100000, 0b11101110
    ])
示例#31
0
 def test_to_block_2bpp(self):
     tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8)
     tileset.tiles = [None, None]
     tileset.tiles[0] = [
         [2, 1, 2, 3, 2, 1, 2, 1],
         [2, 3, 1, 0, 2, 3, 2, 2],
         [3, 0, 3, 2, 2, 2, 0, 2],
         [1, 3, 3, 0, 2, 0, 2, 3],
         [1, 0, 1, 1, 0, 3, 3, 3],
         [1, 3, 3, 3, 3, 2, 1, 2],
         [2, 2, 3, 1, 2, 2, 1, 0],
         [2, 0, 3, 3, 2, 3, 1, 0],
     ]
     tileset.tiles[1] = [
         [1, 3, 3, 1, 3, 0, 2, 1],
         [3, 2, 2, 3, 3, 2, 2, 2],
         [1, 1, 2, 2, 3, 0, 1, 1],
         [0, 3, 2, 2, 0, 0, 0, 3],
         [3, 3, 0, 0, 1, 0, 1, 0],
         [2, 3, 1, 3, 3, 2, 1, 2],
         [0, 0, 0, 1, 3, 2, 3, 3],
         [2, 2, 3, 2, 0, 0, 0, 1],
     ]
     block = Block()
     block.from_list([0] * 32)
     tileset.to_block(block, 0, 2)
     assert_list_equal(
         block.to_list(),
         [
             0b01010101,  # Tile 1
             0b10111010,
             0b01100100,
             0b11001111,
             0b10100000,
             0b10111101,
             0b11100001,
             0b01101011,
             0b10110111,
             0b00000111,
             0b11111010,
             0b01111101,
             0b00110010,
             0b11101100,
             0b00110110,
             0b10111100,
             0b11111001,  # Tile 2
             0b01101010,
             0b10011000,
             0b11111111,
             0b11001011,
             0b00111000,
             0b01000001,
             0b01110001,
             0b11001010,
             0b11000000,
             0b01111010,
             0b11011101,
             0b00011011,
             0b00001111,
             0b00100001,
             0b11110000,
         ],
     )
示例#32
0
def test_write_4bpp_graphic_to_block():
    source = [[8, 1, 12, 9, 6, 5, 3, 2],
              [11, 5, 8, 14, 1, 7, 15, 0],
              [8, 13, 3, 7, 2, 0, 2, 3],
              [10, 0, 4, 14, 7, 10, 11, 9],
              [8, 8, 12, 9, 13, 12, 2, 6],
              [11, 14, 14, 4, 14, 4, 10, 7],
              [12, 2, 12, 8, 4, 15, 12, 14],
              [10, 13, 12, 1, 10, 11, 11, 2]]
    target = Block()
    target.from_list([0] * 32)
    assert_equal(32, write_4bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
    assert_list_equal(target.to_list(),
                      [
                          0b01010110,
                          0b00001011,

                          0b11001110,
                          0b10010110,

                          0b01110001,
                          0b00111011,

                          0b00001011,
                          0b10011110,

                          0b00011000,
                          0b00000011,

                          0b10000001,
                          0b11101011,

                          0b00000100,
                          0b01000101,

                          0b01010110,
                          0b10001111,

                          0b00101100,
                          0b10110000,

                          0b01010110,
                          0b10110010,

                          0b01010000,
                          0b11000000,

                          0b00111000,
                          0b10010111,

                          0b00101101,
                          0b11111100,

                          0b01111101,
                          0b11101010,

                          0b10101111,
                          0b10110111,

                          0b01100000,
                          0b11101110
                      ])
示例#33
0
class TestBlock(BaseTestCase):
    def setup(self):
        self.block = Block()

    def teardown(self):
        del self.block

    def test_baseline(self):
        pass

    def test_empty(self):
        assert_equal(len(self.block), 0)
        assert_equal(len(self.block.data), 0)

    def test_from_file(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_null.bin"))
        assert_equal(len(self.block), 1024)
        assert_list_equal(self.block.to_list(), [0] * 1024)

    def test_from_file_unhappy(self):
        # Attempt to load a directory
        assert_raises(FileAccessError, self.block.from_file, TEST_DATA_DIR)
        # Attempt to load a nonexistent file
        assert_raises(FileAccessError, self.block.from_file, os.path.join(TEST_DATA_DIR, "doesnotexist.bin"))
        # Attempt to load a file in a nonexistent directory
        assert_raises(FileAccessError, self.block.from_file, os.path.join(TEST_DATA_DIR, "dne", "dne.bin"))

    def test_from_list(self):
        self.block.from_list([0, 1, 2, 3, 4, 5])
        assert_equal(len(self.block), 6)
        assert_list_equal(self.block.to_list(), [0, 1, 2, 3, 4, 5])

        self.block.from_list([])
        assert_equal(len(self.block), 0)
        assert_list_equal(self.block.to_list(), [])

        self.block.from_list([69])
        assert_equal(len(self.block), 1)
        assert_list_equal(self.block.to_list(), [69])

    def test_getitem(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))

        assert_equal(self.block[0], 0x25)
        assert_equal(self.block[1023], 0x20)
        assert_equal(self.block[0x3e3], 0xf4)
        assert_equal(self.block[1023], self.block[-1])

        assert_raises(OutOfBoundsError, self.block.__getitem__, 1024)
        assert_raises(OutOfBoundsError, self.block.__getitem__, 9999)

    def test_getitem_slice(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))

        assert_is_instance(self.block[0:1], Block)

        assert_list_equal(self.block[0:0].to_list(), [])
        assert_list_equal(self.block[0x25c:0x25c].to_list(), [])
        assert_list_equal(self.block[0x25c:0x25d].to_list(), [0xa0])
        assert_list_equal(self.block[0x25c:0x25c + 5].to_list(), [0xa0, 0x0b, 0x71, 0x5d, 0x91])
        assert_list_equal(self.block[0x25c:0x25c + 5].to_list(), [0xa0, 0x0b, 0x71, 0x5d, 0x91])
        assert_list_equal(self.block[1022:1024].to_list(), [0x10, 0x20])

        assert_raises(InvalidArgumentError, self.block.__getitem__, slice(0, -1))
        assert_raises(OutOfBoundsError, self.block.__getitem__, slice(-2, -1))
        assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1024, 0))
        assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1024, -1))
        assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1022, 3))

    def test_setitem(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))

        self.block[1] = 0xaa
        assert_equal(self.block[0], 0x25)
        assert_equal(self.block[1], 0xaa)
        assert_equal(self.block[2], 0x38)
        assert_raises(OutOfBoundsError, self.block.__setitem__, 1024, 0xbb)

        assert_raises(InvalidArgumentError, self.block.__setitem__, 5, 0x1234)
        assert_raises(InvalidArgumentError, self.block.__setitem__, 0, 0x100)
        assert_raises(InvalidArgumentError, self.block.__setitem__, 1, -1)

    def test_setitem_slice(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))

        assert_list_equal(self.block[0:3].to_list(), [0x25, 0x20, 0x38])
        self.block[0:3] = [0xeb, 0x15, 0x66]
        assert_list_equal(self.block[0:3].to_list(), [0xeb, 0x15, 0x66])
        self.block[0:1024] = [5] * 1024
        assert_equal(self.block[0:1024].to_list(), [5] * 1024)

        assert_raises(InvalidArgumentError, self.block.__setitem__, slice(5, 0), [])
        assert_raises(InvalidArgumentError, self.block.__setitem__, slice(55, 55), [])
        assert_raises(OutOfBoundsError, self.block.__setitem__, slice(-1, 2), [])
        assert_raises(OutOfBoundsError, self.block.__setitem__, slice(1, 1025), [0] * 1024)
        assert_raises(OutOfBoundsError, self.block.__setitem__, slice(1024, 1025), [1])
        assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 1), [])
        assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 1), [1, 2, 3])
        assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 5), [1, 2])

    def test_read_multi(self):
        self.block.from_list([0x03, 0xa1, 0x44, 0x15, 0x92, 0x65])

        assert_equal(self.block.read_multi(0, 4), 0x1544a103)
        assert_equal(self.block.read_multi(1, 4), 0x921544a1)
        assert_equal(self.block.read_multi(1, 1), 0xa1)
        assert_equal(self.block.read_multi(1, 2), 0x44a1)
        assert_equal(self.block.read_multi(2, 3), 0x921544)
        assert_equal(self.block.read_multi(3, 3), 0x659215)
        assert_equal(self.block.read_multi(5, 1), 0x65)
        assert_equal(self.block.read_multi(0, 0), 0)
        assert_equal(self.block.read_multi(5, 0), 0)

        assert_raises(InvalidArgumentError, self.block.read_multi, 0, -1)
        assert_raises(InvalidArgumentError, self.block.read_multi, 0, -99)
        assert_raises(OutOfBoundsError, self.block.read_multi, -1, 3)
        assert_raises(OutOfBoundsError, self.block.read_multi, 7, 1)
        assert_raises(OutOfBoundsError, self.block.read_multi, 5, 2)
        assert_raises(OutOfBoundsError, self.block.read_multi, 0, 7)

    def test_write_multi(self):
        self.block.from_list([0x03, 0xa1, 0x44, 0x15, 0x92, 0x65])

        self.block.write_multi(0, 0, 0)
        assert_list_equal(self.block.to_list(), [0x03, 0xa1, 0x44, 0x15, 0x92, 0x65])
        self.block.write_multi(0, 0xff, 1)
        assert_list_equal(self.block.to_list(), [0xff, 0xa1, 0x44, 0x15, 0x92, 0x65])
        self.block.write_multi(1, 0xa1b2, 2)
        assert_list_equal(self.block.to_list(), [0xff, 0xb2, 0xa1, 0x15, 0x92, 0x65])
        self.block.write_multi(2, 0x100000f, 4)
        assert_list_equal(self.block.to_list(), [0xff, 0xb2, 0x0f, 0x00, 0x00, 0x01])

        assert_raises(InvalidArgumentError, self.block.write_multi, 0, 0, -1)
        assert_raises(OutOfBoundsError, self.block.write_multi, -1, 0, 1)
        assert_raises(OutOfBoundsError, self.block.write_multi, -1, 0, 1)
        assert_raises(OutOfBoundsError, self.block.write_multi, 0, 0, 7)
        assert_raises(OutOfBoundsError, self.block.write_multi, 1, 0, 6)
        assert_raises(OutOfBoundsError, self.block.write_multi, 3, 0, 4)

    def test_len(self):
        self.block.from_list([0x03, 0xa1, 0x44, 0x15, 0x92, 0x65])
        assert_equal(len(self.block), 6)
        self.block.from_list([])
        assert_equal(len(self.block), 0)
示例#34
0
def test_write_asm_pointer():
    block = Block()
    block.from_list([0xee] * 9)
    write_asm_pointer(block, 1, 0xabcdef12)
    assert_list_equal(block.to_list(), [0xee, 0xee, 0x12, 0xef, 0xee, 0xee, 0xee, 0xcd, 0xab])
示例#35
0
def test_write_asm_pointer():
    block = Block()
    block.from_list([0xee] * 9)
    write_asm_pointer(block, 1, 0xabcdef12)
    assert_list_equal(block.to_list(),
                      [0xee, 0xee, 0x12, 0xef, 0xee, 0xee, 0xee, 0xcd, 0xab])