From 75f7dba54611edc33df3657d1a5bc1bf69494ec4 Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Tue, 27 Jun 2023 14:07:47 +0300 Subject: [PATCH] Implemented __repr__ and __len__ for BasicRegister. --- bitutilities.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bitutilities.py b/bitutilities.py index 5a015f5..052163e 100644 --- a/bitutilities.py +++ b/bitutilities.py @@ -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)