# Path: h800/word.py
# class Word:
#     """H-x800 word class."""
#     def __init__(self, data=0):
#         if data < 0 or data > (2 ** 48 - 1):
#             raise ValueError("Invalid value for 48-bit word!")
#         self.data = BitField(0, width=48,
#                              numbering=BitField.BIT_SCHEME_MSB_1,
#                              order=BitField.BIT_ORDER_MSB_LEFT)
#         self.data[1:48] = data
# 
#     @property
#     def value(self):
#         return int(self.data)
# 
#     @value.setter
#     def value(self, value):
#         if value < 0 or value > (2 ** 48 - 1):
#             raise ValueError("Invalid value for 48-bit word!")
#         self.data.value = value
# 
#     def emit(self):
#         "Emit binary output."
#         # TODO
#         pass
# 
# class InstructionWord(Word):
# 
#     """H-x800 instruction word class."""
# 
#     def __init__(self, command=0, a=0, b=0, c=0):
#         Word.__init__(self)
#         self.data[1:12] = self._command = command   # Command code.
#         self.data[13:24] = self._a = a              # A address group.
#         self.data[25:36] = self._b = b              # B address group.
#         self.data[37:48] = self._c = c              # C address group.
# 
#     @property
#     def command(self):
#         return self.data[1:12]
# 
#     @command.setter
#     def command(self, value):
#         self._command = self.data[1:12] = value
# 
#     @property
#     def a(self):
#         return self.data[13:24]
# 
#     @a.setter
#     def a(self, value):
#         self._a = self.data[13:24] = value
# 
#     @property
#     def b(self):
#         return self.data[25:36]
# 
#     @b.setter
#     def b(self, value):
#         self._b = self.data[25:36] = value
# 
#     @property
#     def c(self):
#         return self.data[37:48]
# 
#     @c.setter
#     def c(self, value):
#         self._c = self.data[37:48] = value


from h800.word import Word, InstructionWord

def test_word_invalid_args():
    gotexc = False
    try:
        print("TEST: test negative value")
        w = Word(-1)
    except ValueError:
        gotexc = True
    else:
        raise
    assert gotexc is True, "Invalid value should have thrown an exception!"

    gotexc = False
    try:
        print("TEST: test too-large value")
        w = Word(2 ** 48)
        assert w is not None
    except ValueError:
        gotexc = True
    else:
        raise
    assert gotexc is True, "Invalid value should have thrown an exception!"


def test_inst_simple_defaults():
    print("TEST: inst simple default cases.")
    w = InstructionWord()
    my_assert(w.value, 0)
    w = InstructionWord(0, 4095, 0, 4095)
    my_assert(w.value, 68702703615)

# Path: h800/word.py
# class Word:
#     """H-x800 word class."""
#     def __init__(self, data=0):
#         if data < 0 or data > (2 ** 48 - 1):
#             raise ValueError("Invalid value for 48-bit word!")
#         self.data = BitField(0, width=48,
#                              numbering=BitField.BIT_SCHEME_MSB_1,
#                              order=BitField.BIT_ORDER_MSB_LEFT)
#         self.data[1:48] = data
# 
#     @property
#     def value(self):
#         return int(self.data)
# 
#     @value.setter
#     def value(self, value):
#         if value < 0 or value > (2 ** 48 - 1):
#             raise ValueError("Invalid value for 48-bit word!")
#         self.data.value = value
# 
#     def emit(self):
#         "Emit binary output."
#         # TODO
#         pass
# 
# class InstructionWord(Word):
# 
#     """H-x800 instruction word class."""
# 
#     def __init__(self, command=0, a=0, b=0, c=0):
#         Word.__init__(self)
#         self.data[1:12] = self._command = command   # Command code.
#         self.data[13:24] = self._a = a              # A address group.
#         self.data[25:36] = self._b = b              # B address group.
#         self.data[37:48] = self._c = c              # C address group.
# 
#     @property
#     def command(self):
#         return self.data[1:12]
# 
#     @command.setter
#     def command(self, value):
#         self._command = self.data[1:12] = value
# 
#     @property
#     def a(self):
#         return self.data[13:24]
# 
#     @a.setter
#     def a(self, value):
#         self._a = self.data[13:24] = value
# 
#     @property
#     def b(self):
#         return self.data[25:36]
# 
#     @b.setter
#     def b(self, value):
#         self._b = self.data[25:36] = value
# 
#     @property
#     def c(self):
#         return self.data[37:48]
# 
#     @c.setter
#     def c(self, value):
#         self._c = self.data[37:48] = value


# Path: h800/word_test.py
from h800.word import Word, InstructionWord


def test_word_invalid_args():
    gotexc = False
    try:
        print("TEST: test negative value")
        w = Word(-1)
    except ValueError:
        gotexc = True
    else:
        raise
    assert gotexc is True, "Invalid value should have thrown an exception!"

    gotexc = False
    try:
        print("TEST: test too-large value")
        w = Word(2 ** 48)
        assert w is not None
    except ValueError:
        gotexc = True
    else:
        raise
    assert gotexc is True, "Invalid value should have thrown an exception!"


def test_inst_simple_defaults():
    print("TEST: inst simple default cases.")
    w = InstructionWord()
    my_assert(w.value, 0)
    w = InstructionWord(0, 4095, 0, 4095)
    my_assert(w.value, 68702703615)

    w = InstructionWord(4095, 0, 4095, 0)