Add calculator tests and a local quality gate

This commit is contained in:
venomade committed 2026-11-02 10:43:47 +00:00
1 parent 016ac885f7
commit 8dd5bcec50
5 files changed
+42

No files matched your search

+2
View File
@@ -1,4 +1,6 @@
__pycache__/ __pycache__/
.pytest/cache/
.venv/
*.pyc *.pyc
.env .env
keep-demo.log keep-demo.log
+12
View File
@@ -14,3 +14,15 @@ Run: `./run.sh`
- Lastly enter a second number - Lastly enter a second number
- Read the result, printed as `Result: ` followed by the answer. - Read the result, printed as `Result: ` followed by the answer.
- When done stop with `Ctrl+c` - 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`.
Executable
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
cd -- "$(dirname -- "$0")"
echo "=== Calculator quality gate ==="
python3 -m pytest -v
echo "QUALITY GATE PASSED"
+1
View File
@@ -0,0 +1 @@
pytest
+21
View File
@@ -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