Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI Pipeline

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install pytest flake8 coverage

- name: Lint code
run: flake8 .

- name: Run tests
run: pytest

- name: Run coverage
run: |
coverage run -m pytest
coverage report
2 changes: 1 addition & 1 deletion calculator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .calculator import Calculator
from .calculator import Calculator # noqa: F401
27 changes: 14 additions & 13 deletions calculator/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

class Calculator:

"""Calculator class with methods to sum, subtract, multiply, divide square and find square root"""
"""Calculator class with methods to sum, subtract, multiply,
divide, square, and find square root."""

def __init__(self, memory=0):
self.memory = memory
Expand All @@ -28,12 +29,12 @@ def sum(self, a, b=None):
"""

try:
if b == None:
if b is None:
b = self.memory

self.memory = float(a) + float(b)
return self.memory
except:
except Exception:
return 'Invalid input'

def subtract(self, a, b=None):
Expand All @@ -49,13 +50,13 @@ def subtract(self, a, b=None):
"""

try:
if b == None:
if b is None:
b = a
a = self.memory

self.memory = float(a) - float(b)
return self.memory
except:
except Exception:
return 'Invalid input'

def multiply(self, a, b=None):
Expand All @@ -71,12 +72,12 @@ def multiply(self, a, b=None):
"""

try:
if b == None:
if b is None:
b = self.memory

self.memory = float(a) * float(b)
return self.memory
except:
except Exception:
return 'Invalid input'

def divide(self, a, b=None):
Expand All @@ -92,15 +93,15 @@ def divide(self, a, b=None):
"""

try:
if b == None:
if b is None:
b = a
a = self.memory

self.memory = float(a) / float(b)
return self.memory
except ZeroDivisionError:
return 'Can not divide by zero.'
except:
except Exception:
return 'Invalid input'

def square(self, a=None):
Expand All @@ -115,12 +116,12 @@ def square(self, a=None):
"""

try:
if a == None:
if a is None:
a = self.memory

self.memory = float(a) ** 2
return self.memory
except:
except Exception:
return 'Invalid input'

def sqrt(self, a=None):
Expand All @@ -135,10 +136,10 @@ def sqrt(self, a=None):
"""

try:
if a == None:
if a is None:
a = self.memory

self.memory = math.sqrt(float(a))
return self.memory
except:
except Exception:
return 'Invalid input'
2 changes: 0 additions & 2 deletions tests/test_calculator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from calculator.calculator import Calculator

c = Calculator()
Expand Down