35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from src.jeb_utils.utils import bits_to_byte
|
|
import pytest
|
|
|
|
@pytest.mark.parametrize('bits,expected', [
|
|
((), b'\x00'),
|
|
((0,), b'\x00'),
|
|
((0, 0), b'\x00'),
|
|
((0, 0, 0, 0, 0, 0, 0, 0), b'\x00'),
|
|
((1,), b'\x01'),
|
|
((0, 1), b'\x01'),
|
|
((0, 0, 0, 0, 0, 0, 0, 1), b'\x01'),
|
|
((0, 0, 0, 0, 1, 0, 0, 1), b'\x09'),
|
|
((1, 0, 0, 1), b'\x09'),
|
|
((1, 1, 1, 1, 1, 1, 1), b'\x7f'),
|
|
((0, 1, 1, 1, 1, 1, 1, 1), b'\x7f'),
|
|
((1, 1, 1, 1, 1, 1, 1, 1), b'\xff'),
|
|
])
|
|
def test_bits_to_byte(bits, expected):
|
|
assert bits_to_byte(*bits) == expected
|
|
|
|
@pytest.mark.parametrize('bits,expected_exception', [
|
|
((2,), ValueError),
|
|
((0, 0, 0, 0, 0, 0, 0, 0, 0), ValueError),
|
|
((0, 0, 0, 0, 0, 0, 0, 0, 1), ValueError),
|
|
((1, 0, 0, 0, 0, 0, 0, 0, 0), ValueError),
|
|
((1, 1, 1, 1, 1, 1, 1, 1, 1), ValueError),
|
|
((1, 1, 1, 1, 1, 1, 1, 2), ValueError),
|
|
((1, 1, 1, 1, 1, 1, 1, -1), ValueError),
|
|
((3, 3, 3, 3, 3, 3, 3, 3), ValueError),
|
|
((3, 3, 3, 3, 3, 3), ValueError),
|
|
((3, 3, 3, 3, 3, 3, 1, 0), ValueError),
|
|
])
|
|
def test_bits_to_byte_exceptions(bits, expected_exception):
|
|
with pytest.raises(expected_exception):
|
|
bits_to_byte(*bits) |