Пример #1
0
 def test_setitem_int(self):
     """Test slice assignment to same int."""
     bm = ByteMatrix(2, 3, [b'123', b'456'])
     bm[0:1, 0:2] = 0
     assert bm.to_bytes() == b'\x00\x003456'
     bm[1, 0:2] = 1
     assert bm.to_bytes() == b'\x00\x003\x01\x016'
     bm[0:2, 0] = 2
     assert bm.to_bytes() == b'\x02\x003\x02\x016'
Пример #2
0
 def test_setitem(self):
     """Test int and slice assignment."""
     bm = ByteMatrix(2, 3, [b'123', b'456'])
     bm[1, 2] = ord(b'Z')
     assert bm.to_bytes() == b'12345Z'
     bm[0:1, 0:2] = ByteMatrix(1, 2, [[1, 2]])
     assert bm.to_bytes() == b'\x01\x02345Z'
     bm[1, 0:2] = ByteMatrix(1, 2, [[4, 5]])
     assert bm.to_bytes() == b'\x01\x023\x04\x05Z'
     bm[0:2, 0] = ByteMatrix(2, 1, [[65], [66]])
     assert bm.to_bytes() == b'A\x023B\x05Z'
Пример #3
0
 def test_elementwise_inplace_int(self):
     """Test in-place elementwise operations with scalar."""
     bm = ByteMatrix(2, 3, 0)
     bm |= 1
     assert bm.to_bytes() == b'\x01' * 6
     bm &= 255
     assert bm.to_bytes() == b'\x01' * 6
     bm ^= 2
     assert bm.to_bytes() == b'\x03' * 6
     bm >>= 1
     assert bm.to_bytes() == b'\x01' * 6
     bm <<= 2
     assert bm.to_bytes() == b'\x04' * 6
Пример #4
0
 def test_bytearray_tall(self):
     """Create 1-column matrix from bytearray."""
     bm = ByteMatrix(6, 1, bytearray(b'123456'))
     assert bm.width == 1
     assert bm.height == 6
     assert bm.to_bytes() == b'123456'
Пример #5
0
 def test_list_of_bytes(self):
     """Create matrix from list of bytes."""
     bm = ByteMatrix(2, 3, [b'123', b'456'])
     assert bm.width == 3
     assert bm.height == 2
     assert bm.to_bytes() == b'123456'
Пример #6
0
 def test_bytearray_wide(self):
     """Create 1-row matrix from bytearray."""
     bm = ByteMatrix(1, 6, bytearray(b'123456'))
     assert bm.width == 6
     assert bm.height == 1
     assert bm.to_bytes() == b'123456'
Пример #7
0
 def test_bytearray(self):
     """Create matrix from bytearray."""
     bm = ByteMatrix(2, 3, bytearray(b'123456'))
     assert bm.width == 3
     assert bm.height == 2
     assert bm.to_bytes() == b'123456'
Пример #8
0
 def test_list_of_list(self):
     """Create matrix from list of list."""
     bm = ByteMatrix(2, 3, [[1, 2, 3], [4, 5, 6]])
     assert bm.width == 3
     assert bm.height == 2
     assert bm.to_bytes() == bytes(bytearray(range(1, 7)))
Пример #9
0
 def test_int(self):
     """Create matrix with all elements equal."""
     bm = ByteMatrix(2, 3, 1)
     assert bm.width == 3
     assert bm.height == 2
     assert bm.to_bytes() == b'\x01' * 6
Пример #10
0
 def test_empty(self):
     """Create empty matrix."""
     bm = ByteMatrix()
     assert bm.width == 0
     assert bm.height == 0
     assert bm.to_bytes() == b''