Skip to content
Snippets Groups Projects
Commit 868e821a authored by Azoth275's avatar Azoth275
Browse files

Testfälle schreiben (rote Phase)

Tests -> Fail
parent a7cc3ff4
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,10 @@
# Eingabe: "1,2\n3" → Erwartete Ausgabe: 6
# Eingabe: "1\n2\n3" → Erwartete Ausgabe: 6
# 8. Negative Zahlen → Exception mit allen negativen Werten
# Eingabe: "1,-2" → Exception mit Message "negatives not allowed: -2"
# Eingabe: "-1,-2,3" → Exception mit Message "negatives not allowed: -1, -2"
import unittest
from src.string_calculator import StringCalculator
......@@ -55,9 +59,22 @@ class TestStringCalculator(unittest.TestCase):
self.assertEqual(self.calc.add(",,1,,2,,,"), 3)
def test_add_with_newlines_between_numbers(self):
# Zeilenumbrüche als Trennzeichen erlauben → Summe
self.assertEqual(self.calc.add("1\n2,3"), 6)
self.assertEqual(self.calc.add("1,2\n3"), 6)
self.assertEqual(self.calc.add("1\n2\n3"), 6)
def test_add_raises_exception_on_negative_number(self):
# Negative Zahlen → Exception mit allen negativen Werten
with self.assertRaises(ValueError) as context:
self.calc.add("1,-2")
self.assertIn("negatives not allowed: -2", str(context.exception))
def test_add_raises_exception_on_multiple_negatives(self):
# Negative Zahlen → Exception mit allen negativen Werten
with self.assertRaises(ValueError) as context:
self.calc.add("-1,-2,3")
self.assertIn("negatives not allowed: -1, -2", str(context.exception))
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment