# Path: luma/core/util.py
# class mutable_string(object):
# class observable(object):
#     def __init__(self, value):
#     def __getattr__(self, attr):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __len__(self):
#     def __iter__(self):
#     def __str__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __hash__(self):
#     def __init__(self, target, observer):
#     def __getattr__(self, attr):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __len__(self):
#     def __iter__(self):
#     def __str__(self):
#     def __repr__(self):
# def from_16_to_8(data):
# def from_8_to_16(data):
# def unsigned_16_to_signed(value):
# def bytes_to_nibbles(data):


from luma.core import util
from helpers import get_reference_file
def test_mutablestring():
    f = util.mutable_string('bar')
    f[1] = '2'
    assert f == 'b2r'
    assert repr(f) == repr('b2r')
    assert len(f) == 3
    assert hash(f) is not None


def test_mutablestring_unicode():
    f = util.mutable_string(u'bazül')
    f[4] = 'L'
    assert f == u'baz\xfcL'
    assert repr(f) == repr(u'baz\xfcL')
    assert len(f) == 5


def test_from_16_to_8_to_16():
    """
    Test the conversion from 16 bit to 8 bit values and back.  Ensure that conversion
    from 8 to 16 bit takes into account whether the 16 bit value is negative or
    positive
    """
    data = [1, 2, 3, 2**15, 2**16 - 1]
    expect = [0, 1, 0, 2, 0, 3, 0x80, 0, 0xFF, 0xFF]

    result = util.from_16_to_8(data)
    assert result == expect

    expect = [1, 2, 3, -32768, -1]

# Path: luma/core/util.py
# class mutable_string(object):
# class observable(object):
#     def __init__(self, value):
#     def __getattr__(self, attr):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __len__(self):
#     def __iter__(self):
#     def __str__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __hash__(self):
#     def __init__(self, target, observer):
#     def __getattr__(self, attr):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __len__(self):
#     def __iter__(self):
#     def __str__(self):
#     def __repr__(self):
# def from_16_to_8(data):
# def from_8_to_16(data):
# def unsigned_16_to_signed(value):
# def bytes_to_nibbles(data):


# Path: tests/test_util.py
from luma.core import util
from helpers import get_reference_file

def test_mutablestring():
    f = util.mutable_string('bar')
    f[1] = '2'
    assert f == 'b2r'
    assert repr(f) == repr('b2r')
    assert len(f) == 3
    assert hash(f) is not None


def test_mutablestring_unicode():
    f = util.mutable_string(u'bazül')
    f[4] = 'L'
    assert f == u'baz\xfcL'
    assert repr(f) == repr(u'baz\xfcL')
    assert len(f) == 5


def test_from_16_to_8_to_16():
    """
    Test the conversion from 16 bit to 8 bit values and back.  Ensure that conversion
    from 8 to 16 bit takes into account whether the 16 bit value is negative or
    positive
    """
    data = [1, 2, 3, 2**15, 2**16 - 1]
    expect = [0, 1, 0, 2, 0, 3, 0x80, 0, 0xFF, 0xFF]

    result = util.from_16_to_8(data)
    assert result == expect

    expect = [1, 2, 3, -32768, -1]

    result = util.from_8_to_16(result)