44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from src.jeb_utils.utils import int_to_bytes
|
|
import pytest
|
|
|
|
@pytest.mark.parametrize('n,signed,expected', [
|
|
(0, False, b'\x00'),
|
|
(1, False, b'\x01'),
|
|
(2, False, b'\x02'),
|
|
(3, False, b'\x03'),
|
|
(42, False, b'\x2a'),
|
|
(254, False, b'\xfe'),
|
|
(255, False, b'\xff'),
|
|
(256, False, b'\x01\x00'),
|
|
(512, False, b'\x02\x00'),
|
|
(513, False, b'\x02\x01'),
|
|
|
|
(0, True, b'\x00'),
|
|
(1, True, b'\x01'),
|
|
(2, True, b'\x02'),
|
|
(3, True, b'\x03'),
|
|
(42, True, b'\x2a'),
|
|
(127, True, b'\x7f'),
|
|
(128, True, b'\x00\x80'),
|
|
(254, True, b'\x00\xfe'),
|
|
(255, True, b'\x00\xff'),
|
|
(256, True, b'\x01\x00'),
|
|
(512, True, b'\x02\x00'),
|
|
(513, True, b'\x02\x01'),
|
|
|
|
(-1, True, b'\xff'),
|
|
(-2, True, b'\xfe'),
|
|
(-3, True, b'\xfd'),
|
|
(-42, True, b'\xd6'),
|
|
(-127, True, b'\x81'),
|
|
(-128, True, b'\xff\x80'),
|
|
(-254, True, b'\xff\x02'),
|
|
(-255, True, b'\xff\x01'),
|
|
(-256, True, b'\xff\x00'),
|
|
(-510, True, b'\xfe\x02'),
|
|
(-511, True, b'\xfe\x01'),
|
|
(-512, True, b'\xfe\x00'),
|
|
(-513, True, b'\xfd\xff'),
|
|
])
|
|
def test_int_to_bytes(n, signed, expected):
|
|
assert int_to_bytes(n, signed) == expected |