diff --git a/__pycache__/utils.cpython-310.pyc b/__pycache__/utils.cpython-310.pyc index f9d943e..b254749 100644 Binary files a/__pycache__/utils.cpython-310.pyc and b/__pycache__/utils.cpython-310.pyc differ diff --git a/tests/__pycache__/test.cpython-310.pyc b/tests/__pycache__/test.cpython-310.pyc index 2f7b446..87773f8 100644 Binary files a/tests/__pycache__/test.cpython-310.pyc and b/tests/__pycache__/test.cpython-310.pyc differ diff --git a/tests/test.py b/tests/test.py index a110a8b..d0e48ca 100644 --- a/tests/test.py +++ b/tests/test.py @@ -95,4 +95,8 @@ def test_restore_empty_file(self): # Should return an empty list if file is empty open(self.test_file, "w").close() lines = self.history.restore() - self.assertEqual(lines, []) \ No newline at end of file + self.assertEqual(lines, []) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/utils.py b/utils.py index dd6613d..5a42bff 100644 --- a/utils.py +++ b/utils.py @@ -1,3 +1,5 @@ + + """ This class is a calculator that performs arithmatic oparation on two numbers. @@ -13,32 +15,63 @@ class Calculator(): def __init__(self,round_digits): self.rounding_digits = round_digits + def addtion(self,a,b): - return 0 + sum = round(a + b, self.rounding_digits) + return sum + def subtraction(self,a,b): - return 0 + subtract = round(a - b, self.rounding_digits) + return subtract + def multiplication(self,a,b): - return 0 + multiply = round(a * b, self.rounding_digits) + return multiply + def division(self,a,b): - return 0 + divide = round(a / b,self.rounding_digits) + return divide + @property def round_digits(self): return self.rounding_digits - + def set_ound_digits(self,digits): self.rounding_digits = digits + +calc0 = Calculator(0) +calc2 = Calculator(2) +print(calc0.addtion(5, 3)) +print(calc2.subtraction(5.555, 2.222),) +print(calc2.multiplication(2.345, 3.456)) +print(calc2.division(10, 3)) class History(): - filepath_ = "" + filepath_ = "History.txt" + def __init__(self, filepath): self.filepath_ = filepath + def save(self,expression:str): - pass + with open(self.filepath_, "a") as f: + f.write(expression + "\n") + + def restore(self)->list[str]: - pass + list_1 = [] + with open(self.filepath_, "r") as f: + + for line in f: + lines = line.strip() + list_1.append(lines) + return list_1 + + def clear(self): - pass \ No newline at end of file + with open(self.filepath_, "w") as f: + pass + \ No newline at end of file