From 9dee85d9fe116bb0895a229aae43238dae34757b Mon Sep 17 00:00:00 2001 From: linopino <lasse.pikkemaat@web.de> Date: Tue, 1 Apr 2025 19:18:56 +0200 Subject: [PATCH] Integration von Orlandos Code + Tests --- others/Orlando/reportOrlandosImp.md | 4 ++++ src/stringcalculator.py | 9 ++++++--- ...tringclaculator.py => testStringcalculator.py} | 15 +++++++++++++-- testsOthers/testsOrlando/reportOrlandosTests.md | 5 +++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 others/Orlando/reportOrlandosImp.md rename tests/{test_stringclaculator.py => testStringcalculator.py} (84%) create mode 100644 testsOthers/testsOrlando/reportOrlandosTests.md diff --git a/others/Orlando/reportOrlandosImp.md b/others/Orlando/reportOrlandosImp.md new file mode 100644 index 0000000..504a41a --- /dev/null +++ b/others/Orlando/reportOrlandosImp.md @@ -0,0 +1,4 @@ +| Name | Interface break | Failed Testcases | +|---------|-----------------|-------------------------------------------------------------------------------------------------------------------------------| +| Orlando | no | test_add_multiple_negative_numbers (test_stringclaculator.TestStringCalculator) ... negatives not allowed: -10, -20, -30 FAIL | +| Orlando | no | test_add_single_negative_number (test_stringclaculator.TestStringCalculator) ... negatives not allowed: -2 FAIL | \ No newline at end of file diff --git a/src/stringcalculator.py b/src/stringcalculator.py index 4b8e76f..f48f2e8 100644 --- a/src/stringcalculator.py +++ b/src/stringcalculator.py @@ -1,7 +1,6 @@ from src.interfaces import IStringCalculator import re - class StringCalculator(IStringCalculator): def add(self, numbers: str) -> int: if not numbers: @@ -11,7 +10,11 @@ class StringCalculator(IStringCalculator): if "\n" not in numbers: raise ValueError("Ungültiges Format: Nicht vollständig") delimiter_end_index = numbers.index("\n") - delimiter = numbers[2:delimiter_end_index] + delimiter_part = numbers[2:delimiter_end_index] + if delimiter_part.startswith("[") and delimiter_part.endswith("]"): + delimiter = delimiter_part[1:-1] + else: + delimiter = delimiter_part numbers = numbers[delimiter_end_index + 1:] numbers = numbers.replace(delimiter, ",") @@ -29,4 +32,4 @@ class StringCalculator(IStringCalculator): numbers_list = [num for num in numbers_list if num <= 1000] - return sum(numbers_list) \ No newline at end of file + return sum(numbers_list) diff --git a/tests/test_stringclaculator.py b/tests/testStringcalculator.py similarity index 84% rename from tests/test_stringclaculator.py rename to tests/testStringcalculator.py index a0c1d76..718074c 100644 --- a/tests/test_stringclaculator.py +++ b/tests/testStringcalculator.py @@ -19,11 +19,18 @@ #Feature5 Zahlen größer 1000 nicht erkennen # Bei Eingabe von 2,1001 soll 2 ausgegeben werden # Bei Eingabe von 1002, 50200 soll 0 asugegeben werden +#Feature6 Begrenzungszeichen beliebig lang +# Bei Eingabe von //[**]\n1**2**3 soll 6 ausgegeben werden +# Bei Eingabe von //[###]\n10###20###30 soll 60 ausgegeben werden - +''' import unittest from src.interfaces import IStringCalculator from src.stringcalculator import StringCalculator +''' +import unittest +from others.Orlando.OrlandoInterfaces import IStringCalculator +from others.Orlando.OrlandoStringCalculator import StringCalculator class TestStringCalculator(unittest.TestCase): def setUp(self): @@ -71,8 +78,12 @@ class TestStringCalculator(unittest.TestCase): self.assertEqual(self.calculator.add("2,1001"), 2) self.assertEqual(self.calculator.add("1002,50200"), 0) + def test_add_with_custom_delimiter_multiple_characters(self): + self.assertEqual(self.calculator.add("//[**]\n1**2**3"), 6) + self.assertEqual(self.calculator.add("//[###]\n10###20###30"), 60) + if __name__ == "__main__": unittest.main() -# python -m unittest tests.test_stringcalculator +# python -m unittest tests.testStringcalculator -v # python -m unittest discover -s tests -v \ No newline at end of file diff --git a/testsOthers/testsOrlando/reportOrlandosTests.md b/testsOthers/testsOrlando/reportOrlandosTests.md new file mode 100644 index 0000000..a94c950 --- /dev/null +++ b/testsOthers/testsOrlando/reportOrlandosTests.md @@ -0,0 +1,5 @@ +| Name | Interface break | Failed Testcases | Comment | +|---------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Orlando | no | test_add_ignores_empty_entries (testsOthers.testsOrlando.OrlandoTestStringCalculator.TestStringCalculator) ... ERROR | Mit numbers.split(",") wird eine Liste mit leeren Strings wobei diese dann nicht in integer umgewandelt werden können. Lösungsansatz: Vor der Umwandlung leere Strings enfernen | +| Orlando | no | test_add_raises_exception_on_multiple_negatives (testsOthers.testsOrlando.OrlandoTestStringCalculator.TestStringCalculator) ... FAIL | | +| Orlando | no | test_add_raises_exception_on_negative_number (testsOthers.testsOrlando.OrlandoTestStringCalculator.TestStringCalculator) ... FAIL | | \ No newline at end of file -- GitLab