Implemented __repr__ and __len__ for BasicRegister.

This commit is contained in:
Rhinemann 2023-06-27 14:07:47 +03:00
parent f2ee4cd709
commit 75f7dba546
1 changed files with 8 additions and 3 deletions

View File

@ -10,12 +10,17 @@ class BasicRegister:
"""
def __init__(self, memory: list[bool]):
"""Constructor method"""
self.memory: deque[bool] = deque(memory)
def __repr__(self) -> str:
return f"Memory: {[int(value) for value in self.memory]}"
def __str__(self) -> str:
return f"Memory: {[int(value) for value in self.memory]}"
def __len__(self) -> int:
return len(self.memory)
def adjusted_by_size(self, resulting_size: int) -> Self:
"""
Adjusts a register to a given size.
@ -72,8 +77,8 @@ def binary_sum(a_original: BasicRegister, b_original: BasicRegister) -> BasicReg
:return: Register containing the sum.
:rtype: BasicRegister
"""
size_a = len(a_original.memory)
size_b = len(b_original.memory)
size_a = len(a_original)
size_b = len(b_original)
required_size = max(size_a, size_b)