diff --git a/others/Orlando/reportOrlandosImp.md b/others/Orlando/reportOrlandosImp.md new file mode 100644 index 0000000000000000000000000000000000000000..504a41a8fe7d6264ad8191c51288ef3c9fb9d025 --- /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 4b8e76f33e53fb4ef8cdc900d5930821fb39baed..f48f2e8c85d9b1acc3b6bd36299155789d269fa1 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 a0c1d7668215796feb20d932160f840f2e5a09db..718074c4fd68c2eed352909c674200bec6964548 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 0000000000000000000000000000000000000000..a94c9501558ed94066dd150ff207521b2b73dda6 --- /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