diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 73f0c17..b241c82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,9 +16,9 @@ jobs: with: submodules: "true" - name: Install dependencies - run: pip install -r src/scripts/app/requirements.txt + run: pip install -r app/requirements.txt - name: Run tests and collect coverage - run: pytest src/scripts/app/ --cov + run: pytest app/ --cov - name: Upload coverage to Codecov (script) uses: ./ @@ -50,7 +50,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} run-macos-latest-xlarge: - if: github.head.repo.full_name == 'codecov/codecov-action' + if: github.event.pull_request.head.repo.full_name == 'codecov/codecov-action' runs-on: macos-latest-xlarge steps: - name: Checkout @@ -58,9 +58,9 @@ jobs: with: submodules: "true" - name: Install dependencies - run: pip install -r src/scripts/app/requirements.txt + run: pip install -r app/requirements.txt - name: Run tests and collect coverage - run: pytest src/scripts/app/ --cov + run: pytest app/ --cov - name: Upload coverage to Codecov (script) uses: ./ with: diff --git a/.gitignore b/.gitignore index a310cc1..91945ba 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ public/ # macOS Finder metadata .DS_Store + +# pycache dirs +__pycache__/ diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/calculator.py b/app/calculator.py new file mode 100644 index 0000000..8a976b2 --- /dev/null +++ b/app/calculator.py @@ -0,0 +1,15 @@ +class Calculator: + + def add(x, y): + return x + y + + def subtract(x, y): + return x - y + + def multiply(x, y): + return x * y + + def divide(x, y): + if y == 0: + return 'Cannot divide by 0' + return x * 1.0 / y diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..c75c448 --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1 @@ +pytest-cov diff --git a/app/test_calculator.py b/app/test_calculator.py new file mode 100644 index 0000000..f564193 --- /dev/null +++ b/app/test_calculator.py @@ -0,0 +1,31 @@ +from .calculator import Calculator + + +def test_add(): + assert Calculator.add(1, 2) == 3.0 + assert Calculator.add(1.0, 2.0) == 3.0 + assert Calculator.add(0, 2.0) == 2.0 + assert Calculator.add(2.0, 0) == 2.0 + assert Calculator.add(-4, 2.0) == -2.0 + +def test_subtract(): + assert Calculator.subtract(1, 2) == -1.0 + assert Calculator.subtract(2, 1) == 1.0 + assert Calculator.subtract(1.0, 2.0) == -1.0 + assert Calculator.subtract(0, 2.0) == -2.0 + assert Calculator.subtract(2.0, 0.0) == 2.0 + assert Calculator.subtract(-4, 2.0) == -6.0 + +def test_multiply(): + assert Calculator.multiply(1, 2) == 2.0 + assert Calculator.multiply(1.0, 2.0) == 2.0 + assert Calculator.multiply(0, 2.0) == 0.0 + assert Calculator.multiply(2.0, 0.0) == 0.0 + assert Calculator.multiply(-4, 2.0) == -8.0 + +def test_divide(): + # assert Calculator.divide(1, 2) == 0.5 + assert Calculator.divide(1.0, 2.0) == 0.5 + assert Calculator.divide(0, 2.0) == 0 + assert Calculator.divide(-4, 2.0) == -2.0 + # assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0'