# Path: bit/utils.py
# class Decimal(decimal.Decimal):
#     def __new__(cls, value):
#         return super().__new__(cls, str(value))
# 
# def bytes_to_hex(bytestr, upper=False):
#     hexed = hexlify(bytestr).decode()
#     return hexed.upper() if upper else hexed
# 
# def chunk_data(data, size):
#     return (data[i : i + size] for i in range(0, len(data), size))
# 
# def flip_hex_byte_order(string):
#     return bytes_to_hex(hex_to_bytes(string)[::-1])
# 
# def hex_to_bytes(hexed):
# 
#     if len(hexed) & 1:
#         hexed = '0' + hexed
# 
#     return bytes.fromhex(hexed)
# 
# def hex_to_int(hexed):
#     return int(hexed, 16)
# 
# def int_to_hex(num, upper=False):
#     hexed = hex(num)[2:]
#     return hexed.upper() if upper else hexed
# 
# def int_to_unknown_bytes(num, byteorder='big'):
#     """Converts an int to the least number of bytes as possible."""
#     return num.to_bytes((num.bit_length() + 7) // 8 or 1, byteorder)


from bit.utils import (
    Decimal,
    bytes_to_hex,
    chunk_data,
    flip_hex_byte_order,
    hex_to_bytes,
    hex_to_int,
    int_to_hex,
    int_to_unknown_bytes,
)
    assert Decimal(0.8) == Decimal('0.8')


class TestBytesToHex:
    def test_correct(self):
        assert bytes.fromhex(bytes_to_hex(BYTES_BIG)) == BYTES_BIG

    def test_default(self):
        assert bytes_to_hex(BYTES_BIG) == HEX

    def test_upper(self):
        assert bytes_to_hex(BYTES_BIG, upper=True) == HEX.upper()


class TestIntToUnknownBytes:
    def test_default(self):
        assert int_to_unknown_bytes(BIG_INT) == BYTES_BIG

    def test_little(self):
        assert int_to_unknown_bytes(BIG_INT, 'little') == BYTES_LITTLE

    def test_zero(self):
        assert int_to_unknown_bytes(0) == b'\x00'


class TestIntToHex:
    def test_default(self):
        assert int_to_hex(BIG_INT) == HEX

    def test_upper(self):

# Path: bit/utils.py
# class Decimal(decimal.Decimal):
#     def __new__(cls, value):
#         return super().__new__(cls, str(value))
# 
# def bytes_to_hex(bytestr, upper=False):
#     hexed = hexlify(bytestr).decode()
#     return hexed.upper() if upper else hexed
# 
# def chunk_data(data, size):
#     return (data[i : i + size] for i in range(0, len(data), size))
# 
# def flip_hex_byte_order(string):
#     return bytes_to_hex(hex_to_bytes(string)[::-1])
# 
# def hex_to_bytes(hexed):
# 
#     if len(hexed) & 1:
#         hexed = '0' + hexed
# 
#     return bytes.fromhex(hexed)
# 
# def hex_to_int(hexed):
#     return int(hexed, 16)
# 
# def int_to_hex(num, upper=False):
#     hexed = hex(num)[2:]
#     return hexed.upper() if upper else hexed
# 
# def int_to_unknown_bytes(num, byteorder='big'):
#     """Converts an int to the least number of bytes as possible."""
#     return num.to_bytes((num.bit_length() + 7) // 8 or 1, byteorder)


# Path: tests/test_utils.py
from bit.utils import (
    Decimal,
    bytes_to_hex,
    chunk_data,
    flip_hex_byte_order,
    hex_to_bytes,
    hex_to_int,
    int_to_hex,
    int_to_unknown_bytes,
)

    assert Decimal(0.8) == Decimal('0.8')


class TestBytesToHex:
    def test_correct(self):
        assert bytes.fromhex(bytes_to_hex(BYTES_BIG)) == BYTES_BIG

    def test_default(self):
        assert bytes_to_hex(BYTES_BIG) == HEX

    def test_upper(self):
        assert bytes_to_hex(BYTES_BIG, upper=True) == HEX.upper()


class TestIntToUnknownBytes:
    def test_default(self):
        assert int_to_unknown_bytes(BIG_INT) == BYTES_BIG

    def test_little(self):
        assert int_to_unknown_bytes(BIG_INT, 'little') == BYTES_LITTLE

    def test_zero(self):
        assert int_to_unknown_bytes(0) == b'\x00'


class TestIntToHex:
    def test_default(self):
        assert int_to_hex(BIG_INT) == HEX

    def test_upper(self):

        assert int_to_hex(BIG_INT, upper=True) == HEX.upper()