Add pytest dependency and initial unit test

feature/interestingPoints
Matias Mas Viehl 2025-12-08 09:21:54 +01:00
parent 8a425c0741
commit 4479a3339f
6 changed files with 88 additions and 42 deletions

View File

@ -13,6 +13,7 @@
"ms-python.python", "ms-python.python",
"ms-python.vscode-pylance" "ms-python.vscode-pylance"
], ],
"postCreateCommand": "pip install --upgrade pip",
"postCreateCommand": "pip install --upgrade pip && pip install pytest black",
"remoteUser": "vscode" "remoteUser": "vscode"
} }

View File

@ -0,0 +1,19 @@
# Datei: sum_calculator.py
def calculate_cumulative_sum(limit):
"""
Soll die kumulative Summe von 0 bis limit berechnen.
"""
total = 0
for i in range(limit):
total += i
return total
if __name__ == "__main__":
test_number = 5
result = calculate_cumulative_sum(test_number)
print(f"Die Zahl ist: {test_number}")
print(f"Ergebnis der Summe: {result}")

View File

@ -0,0 +1,26 @@
# Datei: test_sum_calculator.py
from sum_calculator import calculate_cumulative_sum
def test_sum_for_zero():
"""Testet den Randfall, wenn die Obergrenze 0 ist."""
# Arrange: Testdaten
limit = 0
# Act: Funktion aufrufen
result = calculate_cumulative_sum(limit)
# Assert: Überprüfen des Ergebnisses (0 erwartet)
assert result == 0
def test_sum_for_five():
"""Testet den allgemeinen Fall für die Zahl 5 (0+1+2+3+4+5 = 15)."""
# Arrange: Testdaten
limit = 5
# Act: Funktion aufrufen
result = calculate_cumulative_sum(limit)
# Assert: Überprüfen des Ergebnisses (15 erwartet)
assert result == 15
def test_sum_is_correct_type():
"""Testet, ob die Funktion einen Integer zurückgibt."""
# Arrange, Act, Assert
assert isinstance(calculate_cumulative_sum(3), int)