Add pytest dependency and initial unit test
parent
8a425c0741
commit
4479a3339f
|
|
@ -13,6 +13,7 @@
|
|||
"ms-python.python",
|
||||
"ms-python.vscode-pylance"
|
||||
],
|
||||
"postCreateCommand": "pip install --upgrade pip",
|
||||
|
||||
"postCreateCommand": "pip install --upgrade pip && pip install pytest black",
|
||||
"remoteUser": "vscode"
|
||||
}
|
||||
|
|
@ -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}")
|
||||
|
|
@ -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)
|
||||
Loading…
Reference in New Issue