# 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,
)

BIG_INT = 123456789 ** 5
BYTES_BIG = b'TH8\xe2\xaaN\xd7^aX7\x93\xe7\xc6\xa3\x02\x85'
BYTES_LITTLE = b'\x85\x02\xa3\xc6\xe7\x937Xa^\xd7N\xaa\xe28HT'
HEX = '544838e2aa4ed75e61583793e7c6a30285'
ODD_HEX = '4fadd1977328c11efc1c1d8a781aa6b9677984d3e0bd0bfc52b9f3b03885a00'
ODD_HEX_BYTES = (
    b'\x04\xfa\xdd\x19w2\x8c\x11\xef\xc1\xc1\xd8\xa7\x81' b'\xaak\x96w\x98M>\x0b\xd0\xbf\xc5+\x9f;\x03\x88Z\x00'
)
ODD_HEX_NUM = 2252489133021925628692706218705147644319767320134875440800653003170737838592


def test_decimal():
    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):

# 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,
)


BIG_INT = 123456789 ** 5
BYTES_BIG = b'TH8\xe2\xaaN\xd7^aX7\x93\xe7\xc6\xa3\x02\x85'
BYTES_LITTLE = b'\x85\x02\xa3\xc6\xe7\x937Xa^\xd7N\xaa\xe28HT'
HEX = '544838e2aa4ed75e61583793e7c6a30285'
ODD_HEX = '4fadd1977328c11efc1c1d8a781aa6b9677984d3e0bd0bfc52b9f3b03885a00'
ODD_HEX_BYTES = (
    b'\x04\xfa\xdd\x19w2\x8c\x11\xef\xc1\xc1\xd8\xa7\x81' b'\xaak\x96w\x98M>\x0b\xd0\xbf\xc5+\x9f;\x03\x88Z\x00'
)
ODD_HEX_NUM = 2252489133021925628692706218705147644319767320134875440800653003170737838592


def test_decimal():
    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()