mirror of
https://github.com/venomade/calculator.git
synced 2026-11-16 18:27:39 +00:00
Add calculator tests and a local quality gate
This commit is contained in:
1 parent
016ac885f7
commit
8dd5bcec50
5 files changed
+42
No files matched your search
@@ -1,4 +1,6 @@
|
||||
__pycache__/
|
||||
.pytest/cache/
|
||||
.venv/
|
||||
*.pyc
|
||||
.env
|
||||
keep-demo.log
|
||||
@@ -14,3 +14,15 @@ Run: `./run.sh`
|
||||
- Lastly enter a second number
|
||||
- Read the result, printed as `Result: ` followed by the answer.
|
||||
- When done stop with `Ctrl+c`
|
||||
|
||||
## Testing
|
||||
- Enter a `venv` and install `pytest`:
|
||||
```sh
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
python3 -m pip install -r requirements-dev.txt
|
||||
python3 -m pytest --version
|
||||
```
|
||||
- Run: `./test.sh`
|
||||
- All tests should return `PASSED` and the return code of `test.sh` should be `1`.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd -- "$(dirname -- "$0")"
|
||||
echo "=== Calculator quality gate ==="
|
||||
python3 -m pytest -v
|
||||
echo "QUALITY GATE PASSED"
|
||||
@@ -0,0 +1 @@
|
||||
pytest
|
||||
@@ -0,0 +1,21 @@
|
||||
from calculator import add, subtract, multiply, divide
|
||||
|
||||
def test_add():
|
||||
assert add(2, 3) == 5
|
||||
|
||||
def test_divide():
|
||||
assert divide(6, 2) == 3
|
||||
|
||||
def test_subtract():
|
||||
assert subtract(5, 3) == 2
|
||||
|
||||
def test_multiply():
|
||||
assert multiply(4, 3) == 12
|
||||
|
||||
def test_divide_uneven():
|
||||
# Arrange
|
||||
a, b = 5, 2
|
||||
# Act
|
||||
result = divide(a, b)
|
||||
# Assert
|
||||
assert result == 2.5
|
||||
Reference in new issue
Block a user