From 9cb0a2d4c391ce688415487439e79234e9f04cf2 Mon Sep 17 00:00:00 2001 From: Almmaa <Alma.Berisha@student.reutlingen-university.de> Date: Sun, 6 Apr 2025 00:28:36 +0200 Subject: [PATCH] =?UTF-8?q?Testf=C3=A4lle=20f=C3=BCr=20student1=20ausgef?= =?UTF-8?q?=C3=BChrt=20=20Fehler=20dokumentiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../my_string_calculator.cpython-313.pyc | Bin 0 -> 6781 bytes ld | 270 ++++++++++++++++++ my_string_calculator.py | 88 ++++++ other/student1/Calculator.py | 152 ++++++++++ .../__pycache__/Calculator.cpython-313.pyc | Bin 0 -> 8196 bytes other/student2/Calculator.py | 97 +++++++ .../__pycache__/Calculator.cpython-313.pyc | Bin 0 -> 6376 bytes other/student3/Calculator.py | 109 +++++++ .../__pycache__/Calculator.cpython-313.pyc | Bin 0 -> 9362 bytes other/student4/Calculator.py | 127 ++++++++ .../__pycache__/Calculator.cpython-313.pyc | Bin 0 -> 8756 bytes other/student5/Calculator_combined.py | 96 +++++++ .../Calculator_combined.cpython-313.pyc | Bin 0 -> 7779 bytes other/student6/Calculator_combined.py | 97 +++++++ .../Calculator_combined.cpython-313.pyc | Bin 0 -> 7719 bytes other/student7/Calculator.py | 88 ++++++ .../__pycache__/Calculator.cpython-313.pyc | Bin 0 -> 6786 bytes report.md | 0 test_me_on_student1.py | 50 ++++ test_me_on_student2.py | 52 ++++ test_me_on_student3.py | 49 ++++ test_me_on_student4.py | 49 ++++ test_me_on_student5.py | 30 ++ test_me_on_student6.py | 53 ++++ test_me_on_student7.py | 23 ++ test_student1_on_me.py | 69 +++++ test_student2_on_me.py | 47 +++ test_student3_on_me.py | 49 ++++ test_student4_on_me.py | 55 ++++ test_student5_on_me.py | 57 ++++ test_student6_on_me.py | 53 ++++ test_student7_on_me.py | 35 +++ 32 files changed, 1795 insertions(+) create mode 100644 __pycache__/my_string_calculator.cpython-313.pyc create mode 100644 ld create mode 100644 my_string_calculator.py create mode 100644 other/student1/Calculator.py create mode 100644 other/student1/__pycache__/Calculator.cpython-313.pyc create mode 100644 other/student2/Calculator.py create mode 100644 other/student2/__pycache__/Calculator.cpython-313.pyc create mode 100644 other/student3/Calculator.py create mode 100644 other/student3/__pycache__/Calculator.cpython-313.pyc create mode 100644 other/student4/Calculator.py create mode 100644 other/student4/__pycache__/Calculator.cpython-313.pyc create mode 100644 other/student5/Calculator_combined.py create mode 100644 other/student5/__pycache__/Calculator_combined.cpython-313.pyc create mode 100644 other/student6/Calculator_combined.py create mode 100644 other/student6/__pycache__/Calculator_combined.cpython-313.pyc create mode 100644 other/student7/Calculator.py create mode 100644 other/student7/__pycache__/Calculator.cpython-313.pyc create mode 100644 report.md create mode 100644 test_me_on_student1.py create mode 100644 test_me_on_student2.py create mode 100644 test_me_on_student3.py create mode 100644 test_me_on_student4.py create mode 100644 test_me_on_student5.py create mode 100644 test_me_on_student6.py create mode 100644 test_me_on_student7.py create mode 100644 test_student1_on_me.py create mode 100644 test_student2_on_me.py create mode 100644 test_student3_on_me.py create mode 100644 test_student4_on_me.py create mode 100644 test_student5_on_me.py create mode 100644 test_student6_on_me.py create mode 100644 test_student7_on_me.py diff --git a/__pycache__/my_string_calculator.cpython-313.pyc b/__pycache__/my_string_calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..43497a3f65d0fe1ca3c2b54461add7f147d2419c GIT binary patch literal 6781 zcmd^ET}&I<6~5z{vBy8e{3e(LFyz;Xff$=43n71Gn@v(k!mN|*;_lQjgX66k(>udv zgR*M0Qd6R;+O68`QfZ}T_oYGY1AQv5S?xm~jT{7;uG&>wRi#oT7E?vrr=BzR7%(>3 zeOVrQk-xcf=iHz3bI&>VlC7w45GX&||7HB&E<*l>FJ|HMmFy=_c|=4aGMC9EhBB8d z)Z)c=%Vn0b^`w=EYy%Ow2-C&p`cTej<)PIY;R>z1(Q1QMA;J#Ae8r_eX^RM=z56C1 z(P~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6jmMY~i<dMLFZ>OJdf8?&!a#tVum=2XV8j!iGHGvH=d?|C<$~W}G@;5W z-4D~R3xO!`Tw-gN-;T*+czB(*7|~z1#ZrnUzpdrZ!MQx3HmCo5CTqqC-xdnrNZJb% zssjKJDJ!ZLDw^ghnm(F%R&n@Ae9=|;-j#<}7F^A9uI9(WGnel<OLiQA!*DL3epEAc zW1+EquCYDi=|~5@J1_J<=Ye3p;_!d7n8|#w=d71~>UErLw{1u{{tqn!d_7o38+iMP z#<IrY_qGM;AX-2ewSrs2n@{(e3^lLYpSfdIAutBZE4*x{b2!P@QN8n-%fF@Sug(kC z3aY2C!MGdr{q3cg6Sj_y9!H?3lOl6lMby~1s-;GywS(an5w)210t#-c`0;wib7B^< z%afbE;<qRZdtMffAiY#p8m)$56?3>TydE!aTw8X;S+|U{-^+M<W+4wdy{&R`c68ix z1nza-3*HMY;qkt--5l9MQfqrGf5my`n~JP>g#H)V*c%zo$=O@;!r5(=owd^+IC?Zd z;jXTX*m9oBOvB<-j^fpfb~~y_(DSIih36{U=_<~K653YY9k{<bdtShQ$S|9-tmJlD z@ix*gmbag8IFyKDikY(VF-Ed6;HxQlUxU{Yv<KldLLUNpJ9-)63c?M9A%r&&q6i}h z34|m<scRnmUjjwII}#)6JRmD@Pu;d+W%w?HV+bb@P9yXn^f4<|mLFhN94tQw$nd?` zd<L2s{+xk5|1la2OE4zD%lXl0LXjl6VPvDXVidE`-0izCt|T;6NbX7<uak5EMco&L z3khS5c#WlVI6%=&l`fpj-SnTLD$p?SQ?CImvkb%hh3x$kaj$YLQ!&M^5_qgS_As9G zu0yK?o~tL@m@~}OiG|(%x!wL%f^W;;X9(w-oXD`AMb7n;{&)L-d}Wy>T!X>N{{Tg* BVI}|o literal 0 HcmV?d00001 diff --git a/ld b/ld new file mode 100644 index 0000000..5972578 --- /dev/null +++ b/ld @@ -0,0 +1,270 @@ + + SSUUMMMMAARRYY OOFF LLEESSSS CCOOMMMMAANNDDSS + + Commands marked with * may be preceded by a number, _N. + Notes in parentheses indicate the behavior if _N is given. + A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K. + + h H Display this help. + q :q Q :Q ZZ Exit. + --------------------------------------------------------------------------- + + MMOOVVIINNGG + + e ^E j ^N CR * Forward one line (or _N lines). + y ^Y k ^K ^P * Backward one line (or _N lines). + f ^F ^V SPACE * Forward one window (or _N lines). + b ^B ESC-v * Backward one window (or _N lines). + z * Forward one window (and set window to _N). + w * Backward one window (and set window to _N). + ESC-SPACE * Forward one window, but don't stop at end-of-file. + d ^D * Forward one half-window (and set half-window to _N). + u ^U * Backward one half-window (and set half-window to _N). + ESC-) RightArrow * Right one half screen width (or _N positions). + ESC-( LeftArrow * Left one half screen width (or _N positions). + ESC-} ^RightArrow Right to last column displayed. + ESC-{ ^LeftArrow Left to first column. + F Forward forever; like "tail -f". + ESC-F Like F but stop when search pattern is found. + r ^R ^L Repaint screen. + R Repaint screen, discarding buffered input. + --------------------------------------------------- + Default "window" is the screen height. + Default "half-window" is half of the screen height. + --------------------------------------------------------------------------- + + SSEEAARRCCHHIINNGG + + /_p_a_t_t_e_r_n * Search forward for (_N-th) matching line. + ?_p_a_t_t_e_r_n * Search backward for (_N-th) matching line. + n * Repeat previous search (for _N-th occurrence). + N * Repeat previous search in reverse direction. + ESC-n * Repeat previous search, spanning files. + ESC-N * Repeat previous search, reverse dir. & spanning files. + ESC-u Undo (toggle) search highlighting. + ESC-U Clear search highlighting. + &_p_a_t_t_e_r_n * Display only matching lines. + --------------------------------------------------- + A search pattern may begin with one or more of: + ^N or ! Search for NON-matching lines. + ^E or * Search multiple files (pass thru END OF FILE). + ^F or @ Start search at FIRST file (for /) or last file (for ?). + ^K Highlight matches, but don't move (KEEP position). + ^R Don't use REGULAR EXPRESSIONS. + ^W WRAP search if no match found. + --------------------------------------------------------------------------- + + JJUUMMPPIINNGG + + g < ESC-< * Go to first line in file (or line _N). + G > ESC-> * Go to last line in file (or line _N). + p % * Go to beginning of file (or _N percent into file). + t * Go to the (_N-th) next tag. + T * Go to the (_N-th) previous tag. + { ( [ * Find close bracket } ) ]. + } ) ] * Find open bracket { ( [. + ESC-^F _<_c_1_> _<_c_2_> * Find close bracket _<_c_2_>. + ESC-^B _<_c_1_> _<_c_2_> * Find open bracket _<_c_1_>. + --------------------------------------------------- + Each "find close bracket" command goes forward to the close bracket + matching the (_N-th) open bracket in the top line. + Each "find open bracket" command goes backward to the open bracket + matching the (_N-th) close bracket in the bottom line. + + m_<_l_e_t_t_e_r_> Mark the current top line with <letter>. + M_<_l_e_t_t_e_r_> Mark the current bottom line with <letter>. + '_<_l_e_t_t_e_r_> Go to a previously marked position. + '' Go to the previous position. + ^X^X Same as '. + ESC-m_<_l_e_t_t_e_r_> Clear a mark. + --------------------------------------------------- + A mark is any upper-case or lower-case letter. + Certain marks are predefined: + ^ means beginning of the file + $ means end of the file + --------------------------------------------------------------------------- + + CCHHAANNGGIINNGG FFIILLEESS + + :e [_f_i_l_e] Examine a new file. + ^X^V Same as :e. + :n * Examine the (_N-th) next file from the command line. + :p * Examine the (_N-th) previous file from the command line. + :x * Examine the first (or _N-th) file from the command line. + :d Delete the current file from the command line list. + = ^G :f Print current file name. + --------------------------------------------------------------------------- + + MMIISSCCEELLLLAANNEEOOUUSS CCOOMMMMAANNDDSS + + -_<_f_l_a_g_> Toggle a command line option [see OPTIONS below]. + --_<_n_a_m_e_> Toggle a command line option, by name. + __<_f_l_a_g_> Display the setting of a command line option. + ___<_n_a_m_e_> Display the setting of an option, by name. + +_c_m_d Execute the less cmd each time a new file is examined. + + !_c_o_m_m_a_n_d Execute the shell command with $SHELL. + |XX_c_o_m_m_a_n_d Pipe file between current pos & mark XX to shell command. + s _f_i_l_e Save input to a file. + v Edit the current file with $VISUAL or $EDITOR. + V Print version number of "less". + --------------------------------------------------------------------------- + + OOPPTTIIOONNSS + + Most options may be changed either on the command line, + or from within less by using the - or -- command. + Options may be given in one of two forms: either a single + character preceded by a -, or a name preceded by --. + + -? ........ --help + Display help (from command line). + -a ........ --search-skip-screen + Search skips current screen. + -A ........ --SEARCH-SKIP-SCREEN + Search starts just after target line. + -b [_N] .... --buffers=[_N] + Number of buffers. + -B ........ --auto-buffers + Don't automatically allocate buffers for pipes. + -c ........ --clear-screen + Repaint by clearing rather than scrolling. + -d ........ --dumb + Dumb terminal. + -D xx_c_o_l_o_r . --color=xx_c_o_l_o_r + Set screen colors. + -e -E .... --quit-at-eof --QUIT-AT-EOF + Quit at end of file. + -f ........ --force + Force open non-regular files. + -F ........ --quit-if-one-screen + Quit if entire file fits on first screen. + -g ........ --hilite-search + Highlight only last match for searches. + -G ........ --HILITE-SEARCH + Don't highlight any matches for searches. + -h [_N] .... --max-back-scroll=[_N] + Backward scroll limit. + -i ........ --ignore-case + Ignore case in searches that do not contain uppercase. + -I ........ --IGNORE-CASE + Ignore case in all searches. + -j [_N] .... --jump-target=[_N] + Screen position of target lines. + -J ........ --status-column + Display a status column at left edge of screen. + -k [_f_i_l_e] . --lesskey-file=[_f_i_l_e] + Use a lesskey file. + -K ........ --quit-on-intr + Exit less in response to ctrl-C. + -L ........ --no-lessopen + Ignore the LESSOPEN environment variable. + -m -M .... --long-prompt --LONG-PROMPT + Set prompt style. + -n ......... --line-numbers + Suppress line numbers in prompts and messages. + -N ......... --LINE-NUMBERS + Display line number at start of each line. + -o [_f_i_l_e] . --log-file=[_f_i_l_e] + Copy to log file (standard input only). + -O [_f_i_l_e] . --LOG-FILE=[_f_i_l_e] + Copy to log file (unconditionally overwrite). + -p [_p_a_t_t_e_r_n] --pattern=[_p_a_t_t_e_r_n] + Start at pattern (from command line). + -P [_p_r_o_m_p_t] --prompt=[_p_r_o_m_p_t] + Define new prompt. + -q -Q .... --quiet --QUIET --silent --SILENT + Quiet the terminal bell. + -r -R .... --raw-control-chars --RAW-CONTROL-CHARS + Output "raw" control characters. + -s ........ --squeeze-blank-lines + Squeeze multiple blank lines. + -S ........ --chop-long-lines + Chop (truncate) long lines rather than wrapping. + -t [_t_a_g] .. --tag=[_t_a_g] + Find a tag. + -T [_t_a_g_s_f_i_l_e] --tag-file=[_t_a_g_s_f_i_l_e] + Use an alternate tags file. + -u -U .... --underline-special --UNDERLINE-SPECIAL + Change handling of backspaces. + -V ........ --version + Display the version number of "less". + -w ........ --hilite-unread + Highlight first new line after forward-screen. + -W ........ --HILITE-UNREAD + Highlight first new line after any forward movement. + -x [_N[,...]] --tabs=[_N[,...]] + Set tab stops. + -X ........ --no-init + Don't use termcap init/deinit strings. + -y [_N] .... --max-forw-scroll=[_N] + Forward scroll limit. + -z [_N] .... --window=[_N] + Set size of window. + -" [_c[_c]] . --quotes=[_c[_c]] + Set shell quote characters. + -~ ........ --tilde + Don't display tildes after end of file. + -# [_N] .... --shift=[_N] + Set horizontal scroll amount (0 = one half screen width). + --file-size + Automatically determine the size of the input file. + --follow-name + The F command changes files if the input file is renamed. + --header=[_N[,_M]] + Use N lines and M columns to display file headers. + --incsearch + Search file as each pattern character is typed in. + --line-num-width=N + Set the width of the -N line number field to N characters. + --mouse + Enable mouse input. + --no-keypad + Don't send termcap keypad init/deinit strings. + --no-histdups + Remove duplicates from command history. + --no-number-headers + Don't give line numbers to header lines. + --redraw-on-quit + Redraw final screen when quitting. + --rscroll=C + Set the character used to mark truncated lines. + --save-marks + Retain marks across invocations of less. + --search-options=[EFKNRW-] + Set default options for every search. + --status-col-width=N + Set the width of the -J status column to N characters. + --status-line + Highlight or color the entire line containing a mark. + --use-backslash + Subsequent options use backslash as escape char. + --use-color + Enables colored text. + --wheel-lines=N + Each click of the mouse wheel moves N lines. + + + --------------------------------------------------------------------------- + + LLIINNEE EEDDIITTIINNGG + + These keys can be used to edit text being entered + on the "command line" at the bottom of the screen. + + RightArrow ..................... ESC-l ... Move cursor right one character. + LeftArrow ...................... ESC-h ... Move cursor left one character. + ctrl-RightArrow ESC-RightArrow ESC-w ... Move cursor right one word. + ctrl-LeftArrow ESC-LeftArrow ESC-b ... Move cursor left one word. + HOME ........................... ESC-0 ... Move cursor to start of line. + END ............................ ESC-$ ... Move cursor to end of line. + BACKSPACE ................................ Delete char to left of cursor. + DELETE ......................... ESC-x ... Delete char under cursor. + ctrl-BACKSPACE ESC-BACKSPACE ........... Delete word to left of cursor. + ctrl-DELETE .... ESC-DELETE .... ESC-X ... Delete word under cursor. + ctrl-U ......... ESC (MS-DOS only) ....... Delete entire line. + UpArrow ........................ ESC-k ... Retrieve previous command line. + DownArrow ...................... ESC-j ... Retrieve next command line. + TAB ...................................... Complete filename & cycle. + SHIFT-TAB ...................... ESC-TAB Complete filename & reverse cycle. + ctrl-L ................................... Complete filename, list all. diff --git a/my_string_calculator.py b/my_string_calculator.py new file mode 100644 index 0000000..b525ef2 --- /dev/null +++ b/my_string_calculator.py @@ -0,0 +1,88 @@ +from abc import ABC, abstractmethod +import unittest + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: + pass + +class StringCalculator(IStringCalculator): + def add(self, numbers: str) -> int: + if not numbers: + return 0 + + # Überprüfe, ob ein benutzerdefiniertes Trennzeichen angegeben ist + if numbers.startswith("//"): + delimiter_line_end = numbers.find("\n") + delimiter = numbers[2:delimiter_line_end] # Extrahiere das Trennzeichen + numbers = numbers[delimiter_line_end + 1:] # Entferne die erste Zeile mit dem Trennzeichen + else: + delimiter = ',' # Standard-Trennzeichen ist Komma + + # Ersetze alle Vorkommen des Trennzeichens und teile die Eingabe + numbers = numbers.replace("\n", delimiter) + nums = numbers.split(delimiter) + + # Filtere alle Zahlen, die größer als 1000 sind + nums = [int(num) for num in nums if int(num) <= 1000] + + # Prüfe auf negative Zahlen + negatives = [num for num in nums if num < 0] + + if negatives: + # Wenn negative Zahlen vorhanden sind, werfe eine Ausnahme + raise ValueError(f"Negatives not allowed: {', '.join(map(str, negatives))}") + + # Berechne die Summe der Zahlen, die <= 1000 sind + return sum(nums) + +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.calculator = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calculator.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calculator.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calculator.add("1\n2,3"), 6) + + def test_numbers_with_multiple_newlines(self): + self.assertEqual(self.calculator.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("1,-2,3") + self.assertEqual(str(context.exception), "Negatives not allowed: -2") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("1,-2,-3,4") + self.assertEqual(str(context.exception), "Negatives not allowed: -2, -3") + + def test_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calculator.add("//;\n1;2\n3"), 6) + + def test_custom_delimiter_with_multiple_numbers(self): + self.assertEqual(self.calculator.add("//|\n1|2|3|4"), 10) + + def test_numbers_greater_than_1000(self): + self.assertEqual(self.calculator.add("2,1001"), 2) + + def test_numbers_greater_than_1000_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n2;1001"), 2) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/other/student1/Calculator.py b/other/student1/Calculator.py new file mode 100644 index 0000000..ddc60c6 --- /dev/null +++ b/other/student1/Calculator.py @@ -0,0 +1,152 @@ +import unittest +from abc import ABC, abstractmethod #Daniel Rafeh + + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: + pass + +class StringCalculator(IStringCalculator): + def add(self, numbers: str) -> int: + + '''Leere Eingabe soll 0 ausgeben''' + if numbers == "": + return 0 + + '''Standard-Trennzeichen''' + delimiter = ";" + + '''Es wird geprüft ob ein benutzerdefiniertes Trennzeichen vorhanden ist.''' + if numbers.startswith("//"): + sep = numbers.split("\n", 1) + delimiter_sep = sep[0][2:] + + '''Für den Fall, dass das Trennzeichen in eckigen Klammern steht werden die Klammern entfernt und das Trennzeichen gespeichert''' + if delimiter_sep.startswith("[") and delimiter_sep.endswith("]"): + delimiter = delimiter_sep[1:-1] + + else: + delimiter = delimiter_sep[0] + + '''Entfernen der ersten Zeile, damit nur noch Zahlen übrig bleiben''' + numbers = sep[1] + + '''Ersetzen von Zeilenumbrüchen mit Delimiter und ersetzen von Delimiter durch ",", um splitten zu können''' + numbers = numbers.replace("\n", delimiter).replace(delimiter, ",") + + list = numbers.split(",") + result = 0 + + negative_numbers = [] + + for num in list: + num = num.strip() + if num == "": + continue + + '''Sicherstellen dass Floats nicht berücksichtigt werden''' + if "." in num: + return "only integers allowed" + + '''Sicherstellen, dass keine Buchstaben verwendet werden dürfen''' + try: + number = int(num) + except ValueError: + return "only integers allowed" + + '''Konvertirung von Strings zu Integer''' + if number < 0: + negative_numbers.append(number) + + if number > 1000: + continue + + result += number + + if len(negative_numbers) > 1: + return "negatives not allowed " + str(negative_numbers) + elif negative_numbers: + return "negatives not allowed" + + return result + + +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.c = StringCalculator() + + def test_empty(self): + res = self.c.add("") + self.assertEqual(res, 0) + + def test_oneNumber(self): + res = self.c.add("1") + self.assertEqual(res, 1) + + def test_addingTwoNumbers(self): + res = self.c.add("1,2") + self.assertEqual(res, 3) + + def test_addingTwoNumbersWithZero(self): + res = self.c.add("0,5") + self.assertEqual(res, 5) + + def test_handleFloat(self): + res = self.c.add("3.5") + self.assertEqual(res, "only integers allowed") + + def test_handleLetter(self): + res = self.c.add("1, z") + self.assertEqual(res, "only integers allowed") + + def test_addWithBackslashN(self): + res = self.c.add("1\n2,3") + self.assertEqual(res, 6) + + def test_negativeValues(self): + res = self.c.add("-3") + self.assertEqual(res, "negatives not allowed") + + def test_delimiter(self): + res = self.c.add("//;\n1;2") + self.assertEqual(res, 3) + + def test_thousandone(self): + res = self.c.add("2, 1001") + self.assertEqual(res, 2) + + def test_multidelimiter(self): + res = self.c.add("//[***]\n1***2***3") + self.assertEqual(res, 6) + + def test_multi_negative(self): + res = self.c.add("-3, -4") + self.assertEqual(res, "negatives not allowed " + str([-3, -4])) + + def test_space_between_numbers(self): + res = self.c.add(" 4 , 5") + self.assertEqual(res, 9) + + def test_multiple_num_with_thousandone(self): + res = self.c.add(" 2, 1001, 5") + self.assertEqual(res, 7) + + def test_empty_text(self): + res = self.c.add("//;\n") + self.assertEqual(res, 0) + + def test_one_number_with_empty_string(self): + res = self.c.add("1,") + self.assertEqual(res, 1) + + def test_negative_with_positive(self): + res = self.c.add("-2, 5") + self.assertEqual(res, "negatives not allowed") + + def test_mixture(self): + res = self.c.add("//;\n-1;2;1001;-3") + self.assertEqual(res, "negatives not allowed " + str([-1, -3])) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/other/student1/__pycache__/Calculator.cpython-313.pyc b/other/student1/__pycache__/Calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e4e08953a9e4aefe974df4cc26c82e769f8ca559 GIT binary patch literal 8196 zcmd5>Yit|G5#D={JiaATZ%gv&5!-Y~QIssFwUe~9;zu1@Ms;E0R!Z3ub)xA|M|SUI z$12jgFGq<`I7VtjMgIu>Wdr@up9b0=0onrnDS{2eT!U6X{#5^zNJR^yMLTnRNPH<N zP}Ew0-|g+r?(ELa&dd$B-EIegGIHdT#3>&kALC1@Sc;YHUqIzPk%+{+NGLwp7nzGJ zWiN7+6G;c@Clc31Bz~G5;|gOaZ?;;X)jG|WTP<d*4O)e1GU+NY+I^NOZPS8eKXsK5 z8CC_ffYqg+j1`+il3)@{z_E$%69LxXzH(;V@W?ZoPUW~hujtp(v+=#-%Uc_U*89MK zG7_Pz#87UUm)L2G#7$dI@DkreuJa`})FxS|kgx`9M)OxCohH@9xSWbFq+~r!H*reC zrY_9SC{#17RM8ix8fW)#WuT7o+2#T6lLUFlOgtp8TwYUBb5wv<4e3SExDr1#9o1kW z6Q^HLwAb`>W*YVbOhfT9*N}2UPA$lKGObRh^=k?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!m<7>xY8bL%|(lzHVJ*3GZ53%yFH0-u33? QA6)+Nl`W3&UFL571LRhAdH?_b literal 0 HcmV?d00001 diff --git a/other/student2/Calculator.py b/other/student2/Calculator.py new file mode 100644 index 0000000..05449ba --- /dev/null +++ b/other/student2/Calculator.py @@ -0,0 +1,97 @@ +import unittest +from abc import ABC, abstractmethod #Wasili + +#Interface für StringCalculator +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers:str) -> int: + pass + +#Implementierung der Calculator Klasse +class StringCalculator(IStringCalculator): + def add(self, numbers:str) -> int: + if numbers == "": + return 0 + + #Prüfen, ob ein benutzerdefiniertes Trennzeichen definiert wurde + + if numbers.startswith("//"): + delimiter_end_index = numbers.index("\n") #Zeilenumbruchs Position finden + delimiter = numbers[2:delimiter_end_index] # Trennzeichen, also alles zwischen "//" und "\n" extrahieren + + if delimiter.startswith("[") and delimiter.endswith("]"): + delimiter = delimiter[1:-1] # "[" und "]" entfernen + + numbers = numbers[delimiter_end_index + 1:] #Zahlen nach "\n" extrahieren + numbers = numbers.replace(delimiter,",") #Benutzerdefiniertes Trennzeichen durch "," ersetzen + + #Zeilenumbrüche ebenfals durch "," ersetzen + numbers = numbers.replace("\n",",") + + # String anhand von Kommas splitten, eine Liste der einzelnen Zahlen(in str) erzeugen und in Int umwandeln -> Ergebnis wäre z.B. bei add("1\n2,3,4") -> [1,2,3,4] + num_list = list(map(int, numbers.split(",",))) + + #Prüfung auf negative Zahlen + negatives = [n for n in num_list if n<0] + if negatives: + raise ValueError(f"negatives not allowed: {','.join(map(str, negatives))}") #Alle negativen Zahlen durch Kommas in getrennte Strings darstellen + + #Zahlen größer als 1000 aus Liste entfernen + num_list = [n for n in num_list if n <= 1000] + + return sum(num_list) #Summe berechnen (bei einer Zahln wird immernoch dieselbe Zahl ausgegeben) + + +#mplementierung der Testklasse für StringCalculator +class TestStringCalculator(unittest.TestCase): + def test_add_empty(self): + c = StringCalculator() + self.assertEqual(c.add(""), 0) + + def test_add_one_string(self): + c = StringCalculator() + self.assertEqual(c.add("1"), 1) + + def test_add_two_string(self): + c = StringCalculator() + self.assertEqual(c.add("1,2"), 3) + + def test_add_multiple_string(self): + c = StringCalculator() + self.assertEqual(c.add("1,2,3,4,5,6,7"), 28) + + def test_add_new_lines(self): + c = StringCalculator() + self.assertEqual(c.add("1\n2,3,4"), 10) + + def test_add_exception(self): + c = StringCalculator() + with self.assertRaises(ValueError) as context: + c.add("-5") + self.assertEqual(str(context.exception), "negatives not allowed: -5") + + def test_add_negative_numbers(self): + c = StringCalculator() + with self.assertRaises(ValueError) as context: + c.add("-5,-2,-2") + self.assertEqual(str(context.exception), "negatives not allowed: -5,-2,-2") + + def test_add_different_delimiters(self): + c = StringCalculator() + self.assertEqual(c.add("//;\n1;2"), 3) + + def test_add_numbers_greater_than_1000(self): + c = StringCalculator() + self.assertEqual(c.add("2,1001"),2) + self.assertEqual(c.add("2,10022\n6"),8) + + def test_delimiters_of_any_length(self): + c = StringCalculator() + self.assertEqual(c.add("//[***]\n1***2***3"), 6) + + def test_delimiters_of_any_length2(self): + c = StringCalculator() + self.assertEqual(c.add("//[*+*+*]\n1*+*+*2*+*+*3*+*+*220"), 226) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/other/student2/__pycache__/Calculator.cpython-313.pyc b/other/student2/__pycache__/Calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b8ea3ae8c73d007501c8384c94b321840b9e2cad GIT binary patch literal 6376 zcmd^DT~Hg>6~6l?t%L+N!Zu(FWN>4ICB&bw<0N$mc4NmePFQ27MVaj)EwWs(B6pXV zXxeF}GfC;BGj$$3CbefO=Oy@!KJ_(i{m@4-G6S>qw3)UK<&6NHO#0HEvyzq{BZwbT zKlFmW-MxG6y=Tuk_q*rbHLurApgazKnY>X=$lvjyT!hli+NW@Hn@B`rE)t4Y_9F8d zOWD^r$^}S0X(1BVNF+YSM!8}e%3HMp)H-6kT`O3%PN)@QWXMw<Xya;2I%A^bI{g+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91cd9e --- /dev/null +++ b/other/student3/Calculator.py @@ -0,0 +1,109 @@ +import unittest +import re #Momo + +class StringCalculator: + def __init__(self): + self.called_count = 0 + def add (self, numbers : str)-> int: #Erwartet Integer + if not numbers: + return 0 + + if numbers.startswith("//"): + delimiter_end_index = numbers.index("\n") + delimiter_section = numbers[2:delimiter_end_index] + numbers = numbers[delimiter_end_index +1:] + + if delimiter_section.startswith("[")and delimiter_section.endswith("]"): + delimiters = re.findall(r'\[([^\]]+)\]',delimiter_section) + else: + delimiters= [delimiter_section] + + for delimiters in delimiters: + numbers = numbers.replace(delimiters,",") + + numbers = numbers.replace("\n",",") + + number_list = numbers.split(',')#aufteilung der strings + negative = [] #array für die negativen nummern + numbers_to_add = [] + #total_sum = 0 + for number_str in number_list: #jedes element in der liste wird durch genommen + #if number_str: + number = int(number_str)# summierung der integer + if number <0: + negative.append(number) + elif number > 1000: + continue + else: + numbers_to_add.append(number) + #total_sum += number + + if negative: + print(f"Negative Zahlen:{negative} ")#ausgabe negative zahlen + raise ValueError(f"negatives not allowed: {','.join(map(str, negative))}") + self.called_count += 1 + return sum(numbers_to_add) + def get_called_count(self): + return self.called_count + + +class TestStingCalculator(unittest.TestCase): + def setUp(self): + self.calculator = StringCalculator() + def test_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) #leerer string + 0 + def test_single_number(self): + self.assertEqual(self.calculator.add("5"),5) #eingabe von einem String + def test_multiple_numbers(self): + self.assertEqual(self.calculator.add("5,5"),10)#eingabe mehrere strings + def test_unknowen_amount_of_numbers(self): + self.assertEqual(self.calculator.add("1,2,3"),6) + self.assertEqual(self.calculator.add("10,20,30,40"),100) + self.assertEqual(self.calculator.add("1,2,3,4,5,6"),21) + def test_numbers_seperated_by_newline(self): + self.assertEqual(self.calculator.add("1\n2"),3) + self.assertEqual(self.calculator.add("1\n2\n3"),6) + self.assertEqual(self.calculator.add("10,20\n30"),60) + + def test_negative_number_exception(self): + + with self.assertRaises(ValueError) as e: + self.calculator.add("-1,2") + self.assertEqual(str(e.exception), "negatives not allowed: -1") + def test_multiple_negative_numbers_exception(self): + with self.assertRaises(ValueError)as e: + self.calculator.add("-1,-2,3") + self.assertEqual(str(e.exception),"negatives not allowed: -1,-2") + with self.assertRaises(ValueError) as e: + self.calculator.add("-1,-3,4") + self.assertEqual(str(e.exception),"negatives not allowed: -1,-3") + + with self.assertRaises(ValueError) as e: + self.calculator.add("-1\n-3,4") + self.assertEqual(str(e.exception),"negatives not allowed: -1,-3") + def test_add_numbers_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2;3"),6) + self.assertEqual(self.calculator.add("//;\n1,2,3"),6) + with self.assertRaises(ValueError) as e: + self.calculator.add("//;\n-3,4") + self.assertEqual(str(e.exception),"negatives not allowed: -3") + + def test_add_numbers_greater_than_1000(self): + self.assertEqual(self.calculator.add("1,1001,2,3"),6) + def test_add_numbers_greater_than_1000_1002(self): + self.assertEqual(self.calculator.add("1002,1,2,3"),6) + def test_add_numbers_greater_1000_and_minus(self): + with self.assertRaises(ValueError) as e: + self.calculator.add("//;\n-3,4;1001") + self.assertEqual(str(e.exception),"negatives not allowed: -3") + def test_custom_delimiter(self): + self.assertEqual(self.calculator.add("//[***]\n1***2***3"),6) + def test_custom_del(self): + self.assertEqual(self.calculator.add("//[+++]\n1+++2+++3"),6) + def test_custom_del2(self): + self.assertEqual(self.calculator.add("//[aa]\n1aa2aa3"),6) + + + +if __name__=='__main__': + unittest.main() \ No newline at end of file diff --git a/other/student3/__pycache__/Calculator.cpython-313.pyc b/other/student3/__pycache__/Calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1394af73c7b584d4b136e8c64570dba56c2e12b0 GIT binary patch literal 9362 zcmeGiTTC3+_0G=h?l3GY4?kGKW5Lgb#k{eDW5+gr#BPmiChMeLoaqF{c#~xycZS49 zl@e7-OIx+In<gPuR8#e%_8*lh)t^c0k9;m&2y|jqDCtM}vmvRaeD$2!nSp%)sTHS{ zdeNS_bMLv2^F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f --- /dev/null +++ b/other/student4/Calculator.py @@ -0,0 +1,127 @@ +import re +import unittest #Marvin + +class StringCalculator: + def add(self, numbers: str) -> int: + # Feature 1: Leerer String ergibt 0 + if not numbers: + return 0 + + + + # Vorbereitung für weiter features + delimiters = [",", "\n"] + if numbers.startswith("//"): + delimiter_end_index = numbers.index("\n") + delimiter_section = numbers[2:delimiter_end_index] + numbers = numbers[delimiter_end_index + 1:] + + # Feature 7: Delimiter beliebiger Länge im Format //[***] + if delimiter_section.startswith("[") and delimiter_section.endswith("]"): + delimiter = re.escape(delimiter_section[1:-1]) + else: + delimiter = re.escape(delimiter_section) + + delimiters.append(delimiter) + + # Feature 3: Erlaube Zeilenumbrüche als Trenner + split_pattern = "|".join(delimiters) + number_list = re.split(split_pattern, numbers) + + + + + # Feature 4: Negativzahlen abfangen + negatives = [] + for num in number_list: + if num.strip() != "": + value = int(num) + if value < 0: + negatives.append(value) + + # Exception bei negativen Zahlen + if negatives: + raise ValueError(f"Negative numbers are not allowed: {', '.join(map(str, negatives))}") + + # Feature 2: Beliebig viele Zahlen summieren + return sum(int(n) for n in number_list if n.strip() != "" and int(n) <= 1000) + + + +class TestStringCalculator(unittest.TestCase): + """Test suite for the StringCalculator class.""" + + def setUp(self): + """neue Instanz des StringCalculators vor jedem Test""" + self.calculator = StringCalculator() + + def test_empty_string_returns_zero(self): + """Feature 1: Leerer String soll 0 ergeben""" + self.assertEqual(self.calculator.add(""), 0) + + def test_single_number_returns_value(self): + """Ein einzelner Wert soll zurückgegeben werden""" + self.assertEqual(self.calculator.add("1"), 1) + + def test_two_numbers_return_sum(self): + """Zwei Zahlen sollen summiert werden""" + self.assertEqual(self.calculator.add("1,2"), 3) + + def test_add_multiple_numbers(self): + """Feature 2: Mehrere Zahlen summieren""" + self.assertEqual(self.calculator.add("1,2,3,4,5"), 15) + + def test_add_numbers_with_newlines(self): + """Feature 3: Zeilenumbrüche als Trennzeichen""" + self.assertEqual(self.calculator.add("1\n2\n3"), 6) + + def test_add_negative_numbers(self): + """Feature 4: Negative Zahlen sollen Fehler werfen""" + with self.assertRaises(ValueError) as e: + self.calculator.add("-1,2,-3") + self.assertEqual(str(e.exception), "Negative numbers are not allowed: -1, -3") + + def test_add_numbers_with_custom_delimiter(self): + """Feature 5: Benutzerdefiniertes Trennzeichen""" + self.assertEqual(self.calculator.add("//;\n1;2;3"), 6) + + def test_add_numbers_with_custom_delimiter_different_symbol(self): + """Feature 5: Benutzerdefiniertes Trennzeichen mit anderem Symbol""" + self.assertEqual(self.calculator.add("//#\n4#5#6"), 15) + + def test_custom_delimiter_with_multiple_numbers(self): + """ + Kombinierter Test für: + feature 5 und feature 2 + Erwartet wird die korrekte Addition von sechs durch ein benutzerdefiniertes Zeichen getrennten Zahlen. + """ + self.assertEqual(self.calculator.add("//:\n1:2:3:4:5:6"), 21) + + def test_add_numbers_greater_than_1000(self): + """Feature6 test""" + self.assertEqual(self.calculator.add("1,1001,2,3"), 6) + + def test_add_numbers_with_newlines_and_ignore_above_1000(self): + """Feature 3 und 6 test Zeilenumbruch als trenner, Zahlen>1000 ignorieren""" + self.assertEqual(self.calculator.add("1\n2\n1000\n1001"), 1003) + + def test_add_numbers_with_custom_delimiter_long_length(self): + """Benutzerdefinierte Trennzeichen beliebig lang """ + self.assertEqual(self.calculator.add("//[***]\n1***2***3"), 6) + + def test_custom_long_delimiter_with_large_number_ignored(self): + """FEature 6 und 7 test Benutzerdefinierte Delimiter Länge und zahl über 1000 wird ignoriert""" + self.assertEqual(self.calculator.add("//[***]\n1***1001***2"), 3) + + def test_custom_long_delimiter_with_negative_numbers(self): + """Feature 4 und 7: Benutzerdefinierter Delimiter beliebiger Länge + negative Zahlen""" + with self.assertRaises(ValueError) as e: + self.calculator.add("//[***]\n1***-2***3***-4") + self.assertEqual(str(e.exception), "Negative numbers are not allowed: -2, -4") + + + + + +if __name__ == '__main__': + unittest.main() diff --git a/other/student4/__pycache__/Calculator.cpython-313.pyc b/other/student4/__pycache__/Calculator.cpython-313.py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IU8C?n4^!YVp?iV;>#P?qD+R~gYmHVYv10wXdb7a3uDpi_*%heEXW`vN;! zrHruic!i<=Ci<hL<Dtc5ZG6a^tX@Vs8QIUsAw~{7<So{-+(Sp^{W<O-Uu5m)9&XMw zJP!>f>oJ|a!2Mn4*6mK8iG4kp2uQLhx{GNI%&74(S%NQMa9nKBUzzNV1mLt;Umb%- zv#=g(7O(LK(%)Ws=r@1|jsTEy49KFH<G4?e?Nj7>WNF~ea9<!szkG%3<G8cj%>KFU np5%7Vmq>qIJYzx@$8<bpu9~+vzJ2nIliwO#G$Tv3zT*D?!NKWc literal 0 HcmV?d00001 diff --git a/other/student5/Calculator_combined.py b/other/student5/Calculator_combined.py new file mode 100644 index 0000000..09214d2 --- /dev/null +++ b/other/student5/Calculator_combined.py @@ -0,0 +1,96 @@ +from abc import ABC, abstractmethod +import unittest #Orlandos test kombiniert aus 2 dateien,da fehlerhafte meldung mit scr hat anders nicht geklappt + + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: + pass + + +class StringCalculator(IStringCalculator): + def add(self, numbers: str) -> int: + if not numbers: + return 0 + + delimiter = "," + + if numbers.startswith("//"): + header, numbers = numbers.split("\n", 1) + + if header.startswith("//[") and header.endswith("]"): + delimiter = header[3:-1] + else: + delimiter = header[2:] + + numbers = numbers.replace("\n", ",") + numbers = numbers.replace(delimiter, ",") + + number_list = numbers.split(",") + cleaned_numbers = [ + int(n.strip()) for n in number_list if n.strip() != "" + ] + + negatives = [n for n in cleaned_numbers if n < 0] + if negatives: + raise ValueError(f"negatives not allowed: {', '.join(map(str, negatives))}") + + cleaned_numbers = [n for n in cleaned_numbers if n <= 1000] + + return sum(cleaned_numbers) + +# --- TESTS --- +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_add_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_add_ignores_empty_entries(self): + self.assertEqual(self.calc.add("1,,2"), 3) + self.assertEqual(self.calc.add("1, ,2"), 3) + self.assertEqual(self.calc.add(",,1,,2,,,"), 3) + + def test_add_with_newlines(self): + 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_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2") + self.assertIn("negatives not allowed: -2", str(context.exception)) + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-1,-2,3") + self.assertIn("negatives not allowed: -1, -2", str(context.exception)) + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + self.assertEqual(self.calc.add("//|\n4|5|6"), 15) + self.assertEqual(self.calc.add("//_\n7_8_9"), 24) + + def test_ignores_large_numbers(self): + self.assertEqual(self.calc.add("2,1001"), 2) + self.assertEqual(self.calc.add("1000,1"), 1001) + self.assertEqual(self.calc.add("1234,1001,3"), 3) + + def test_multi_char_delimiter(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + self.assertEqual(self.calc.add("//[abc]\n4abc5abc6"), 15) + self.assertEqual(self.calc.add("//[+]\n1+2+3"), 6) + + +if __name__ == "__main__": + unittest.main() diff --git a/other/student5/__pycache__/Calculator_combined.cpython-313.pyc b/other/student5/__pycache__/Calculator_combined.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..58da210273e9ccdba83d4985845021ab109a6672 GIT binary patch literal 7779 zcmeHMYfK#16~42xkJ%S%UbYt-du@oFg@t8zc^F6&D0Uj#VM&;5;+C~W%Q9YXx(|G3 zHpE-EvMMFT>Lal#*F>shl3(zvSdA37zuLw>`V+Ju&@@U(+aKj0F|MMtKiYF<AHXtf zD@9dQHFve&+_}$l&pG$pbM9=}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z1&F4;(hJ~lDZxj8g1fOZ9sxUH3}&n0qPC@_<+8;G=!buRz6c%F^2m7fvZWKS3;qSm zVTJas(7M&%x{oiJ4-?fxL5N<B&>g0uLYS!4UOlA7fEvwsV)1l;&iT}X$TByep$dgs zFd%~(wX@&LIlCV)D_oyyK-`S#AO+pknzx4-*U$lkvk2cnxQGx$7)3xTselkgxPlNz z(7I~u#tH<yvy%n@-XxFUbJXcaM#kVp=s@rz^gc4OhBJ>Wtf3p>B7-=hVjpJv{sz#m zu0kCWzq%zO@suFAE%4!PJW64Y!~G+G!evr%8Mkr%TNz$rDjaUzp$OcHsZ`<RsiMaL z%090t+*A2acu&(wXoLDBy#TPuG7R%a()0)7cx+@D`waV-z~iy4k!fB$^yFg#&&LCd skLjN|vwFm{bj0(Rz{}=UhUjh6*&OR!)7yS9{QcoKM&PDd-=MDKUr<%QPyhe` literal 0 HcmV?d00001 diff --git a/other/student6/Calculator_combined.py b/other/student6/Calculator_combined.py new file mode 100644 index 0000000..35f4531 --- /dev/null +++ b/other/student6/Calculator_combined.py @@ -0,0 +1,97 @@ +from abc import ABC, abstractmethod +import re +import unittest + + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: + pass + + + +class StringCalculator(IStringCalculator): + def add(self, numbers: str) -> int: + if not numbers: + return 0 + + if numbers.startswith("//"): + if "\n" not in numbers: + raise ValueError("Ungültiges Format: Nicht vollständig") + delimiter_end_index = numbers.index("\n") + 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, ",") + + numbers = numbers.replace("\n", ",") + + # Split the string by commas, convert each value to an integer, and sum them up + try: + numbers_list = list(map(int, numbers.split(","))) + except ValueError: + raise ValueError("Ungültiges Zahlenformat: Enthält nicht-numerische Werte") + + negative_numbers = [num for num in numbers_list if num < 0] + if negative_numbers: + raise ValueError(f"Negative nicht erlaubt: {negative_numbers}") + + numbers_list = [num for num in numbers_list if num <= 1000] + + return sum(numbers_list) + + +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.calculator: IStringCalculator = StringCalculator() # Zugriff über das Interface + + def test_add_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calculator.add("10,20"), 30) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calculator.add("1,2,3"), 6) + self.assertEqual(self.calculator.add("10,20,30,40"), 100) + + def test_add_with_newline_separator(self): + self.assertEqual(self.calculator.add("1\n2,3"), 6) + self.assertEqual(self.calculator.add("10\n20\n30"), 60) + + def test_add_single_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("1,-2,3") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-2]") + + def test_add_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("-10\n-20,-30") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-10, -20, -30]") + + def test_add_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2"), 3) + self.assertEqual(self.calculator.add("//x\n7x8\n9"), 24) + + def test_invalid_custom_delimiter_format(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("//;1;2") + self.assertTrue("Ungültiges Format" in str(context.exception)) + + def test_ignore_numbers_greater_than_1000(self): + 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() diff --git a/other/student6/__pycache__/Calculator_combined.cpython-313.pyc b/other/student6/__pycache__/Calculator_combined.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..63f3b5d384042ba48f47a641f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)m~#kaaxoPCuJouA#5F(JNH&v$w8>AJtO<|jN{n- z=0)yA>Bz3--r*(g^d6D@Pq4;+Ph{tHUp2P(0^j*KkLQ#<qI>tY=njeny(aOT`}kFl z%S2y-4@J>jwPZv6OEf8F55oZ@ddzhXX%-NZ;I=sy5sD2!$X)`e$9K1bCk!2iRpl!H zzD_iM$NsiGRqOr*yKsK_$l3Ifvl-vHbnUq%?tH<2<y<&#VLxfH^!av%^KZQ?8~yGM zpRa@B*<{KBUBA1_=lA)vBW>w2?WwFHqf&zA4{fp#rD6zg$CUAqB)~L2wPz1aK4I)t zRORWcD)Sk4$MN>7lx%%V+{wos`&+NDa<6x!t?h=Tqpi)~)|NZ=R0FcLwH2^Fc=!=? z`Y1X>X%+f472*v<$-pWUa%6ZMO7AczR#wmNuFtPE(FiK{%<jrfc}`{=r#{}d$n}>D z+bPdL#&PyzILuzs)azoj%5uoHujKVy4+`Nl0xb9F1q9C{cmV<YI!GwqtI-ew5y3cu zR}qxD%flNkiU2Rg<Z}RSlXdv*=rpr#WDH#hx)JoQ8+C>=%sQvTPaJD_ky*E}h9E$l zp-;nH(E6wT0wjZswij(;{Gn_j6q5wOWrg3`M#B`-Z1$Hh9TinBDa902VD=|2yf0Ka zR8D^gZl5&%Fn+6goTTU~Qsqu$e|bAeWuSpFpU4=l;d+!|eoI<EBj(SDebdM?Wi#w1 zfyZWf6VseJaCnozb8~=cX9k&>W6KBK>4WY~f^Tc14AI-Br!uT#MQ{7T<?mho{*^VB J=<BpC{R^mK9q9l7 literal 0 HcmV?d00001 diff --git a/other/student7/Calculator.py b/other/student7/Calculator.py new file mode 100644 index 0000000..b525ef2 --- /dev/null +++ b/other/student7/Calculator.py @@ -0,0 +1,88 @@ +from abc import ABC, abstractmethod +import unittest + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: + pass + +class StringCalculator(IStringCalculator): + def add(self, numbers: str) -> int: + if not numbers: + return 0 + + # Überprüfe, ob ein benutzerdefiniertes Trennzeichen angegeben ist + if numbers.startswith("//"): + delimiter_line_end = numbers.find("\n") + delimiter = numbers[2:delimiter_line_end] # Extrahiere das Trennzeichen + numbers = numbers[delimiter_line_end + 1:] # Entferne die erste Zeile mit dem Trennzeichen + else: + delimiter = ',' # Standard-Trennzeichen ist Komma + + # Ersetze alle Vorkommen des Trennzeichens und teile die Eingabe + numbers = numbers.replace("\n", delimiter) + nums = numbers.split(delimiter) + + # Filtere alle Zahlen, die größer als 1000 sind + nums = [int(num) for num in nums if int(num) <= 1000] + + # Prüfe auf negative Zahlen + negatives = [num for num in nums if num < 0] + + if negatives: + # Wenn negative Zahlen vorhanden sind, werfe eine Ausnahme + raise ValueError(f"Negatives not allowed: {', '.join(map(str, negatives))}") + + # Berechne die Summe der Zahlen, die <= 1000 sind + return sum(nums) + +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.calculator = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calculator.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calculator.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calculator.add("1\n2,3"), 6) + + def test_numbers_with_multiple_newlines(self): + self.assertEqual(self.calculator.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("1,-2,3") + self.assertEqual(str(context.exception), "Negatives not allowed: -2") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calculator.add("1,-2,-3,4") + self.assertEqual(str(context.exception), "Negatives not allowed: -2, -3") + + def test_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calculator.add("//;\n1;2\n3"), 6) + + def test_custom_delimiter_with_multiple_numbers(self): + self.assertEqual(self.calculator.add("//|\n1|2|3|4"), 10) + + def test_numbers_greater_than_1000(self): + self.assertEqual(self.calculator.add("2,1001"), 2) + + def test_numbers_greater_than_1000_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n2;1001"), 2) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/other/student7/__pycache__/Calculator.cpython-313.pyc b/other/student7/__pycache__/Calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f61d4aee076afc81ec36544859b8b4244ff90ae4 GIT binary patch literal 6786 zcmd^ET}&I<6~5z{vBy8efFZ#ofFZw548+(ZSqPgSvdtzbkTB~cySO`b%s{*~V|r)U zY*1E;Dm5jls@<y1E|pelc3&FQKG3J~n$<q^(a1rd>8f3|RaGigVlh>;ed;-5j{#$o z-IwK|H{zQ+$LIc>pL@=kn`}jegFw63`{n4rU4;A%U(CkmJK0a5^N5H<WUi3Q3}r4` zsKtlxmMbh}>qrX`*?J;!QKpm4jiH=D<$-FAas?`HP;EdJqU<27SKJDmwx}T5yKWK^ zt0n|^0gGD;>CBUSWYjWh@jI6B-EYy^bLV^YU9nrLMq_bpOxA9vhWq0i#}`C94%9~^ zN+=@|Y7rUAMmf<E<wZ7X4Raz_Pu}9pWvET$sW58w+w`hSqDB+SXm2bTpGd~E6kX<E zCf%k?jNOu{s#~e7O;9Cn*{~`Debi4DSs#&6GQ;%G;C?w(PL5Cks4DXNeELAVD;iN@ zA_JorWc3GHYCH-8!J@74!m6$E+p*+COiQGcXiB>+Q(&1GmKE(}bbV`W<9Bs7Hax7? zZrODkkWm*Z!hQ0E;L1XWP&7@y->wUiq{PN#NzxsXG?p5kNMhe5Nk5#3CG)?yC21r< zRV|rNWF;j@)X)SAd)3*5qER=@rPoT5s=+?vQcMFOZcS*i3aq#etwPv^U^M}!P+I^V zkR{%;Vqy4->Cg&+$Ky~IA6b@IYqChs4abq2EQ~W?%N_#QY+<l32lnMn`%){|)n?eW za*J8*Fx)T=#oi`+BEhid=U~}KB*Gj40=8jzA7vuUAX>briI&bh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_ z)t$8?5IlZ7Na3!ojM{RM%Phl2sT{+r8SQpVkznL;eVfQtcF<K^4K=i*vODm6b#%W# z{;=UTWkt!IwBlo=Un=iE-*74s)f6{%<!6jyqu=i-d0&Iq60{rP3_>pgMmu^1VF2L< z!Vton2r+~agakqoq0}`G{)YlZz&jEn>pUQ<a8KR3YGwFNgcAs-5Y8ZUBlI$>R+jH) zRvj!q2*~g~NInZ>hCgp$_kRq6;R(h9csV~7ODK{AH;ioTR-9rLn!9}$CX|GR2FYEi z<8_iQpsIUga3Nvr5wEdy4kswOsnUhhxtso%sR}#{{HfOfR#=8%{zCTuiMZD|mZ_L# z*9bh;9Qzn=de4zH0?)P6t;|_w`qbjy!2I688o{@f?=ysRO-*K4?-J+wN#Bq9emt<k J60Y75<$t()V$J{n literal 0 HcmV?d00001 diff --git a/report.md b/report.md new file mode 100644 index 0000000..e69de29 diff --git a/test_me_on_student1.py b/test_me_on_student1.py new file mode 100644 index 0000000..fd33f2f --- /dev/null +++ b/test_me_on_student1.py @@ -0,0 +1,50 @@ +import unittest +from other.student1.Calculator import StringCalculator # dani + +class TestMyCalcOnStudent1(unittest.TestCase): + def setUp(self): + self.calculator = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calculator.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calculator.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calculator.add("1\n2,3"), 6) + + def test_numbers_with_multiple_newlines(self): + self.assertEqual(self.calculator.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError): + self.calculator.add("1,-2,3") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError): + self.calculator.add("1,-2,-3,4") + + def test_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calculator.add("//;\n1;2\n3"), 6) + + def test_custom_delimiter_with_multiple_numbers(self): + self.assertEqual(self.calculator.add("//|\n1|2|3|4"), 10) + + def test_numbers_greater_than_1000(self): + self.assertEqual(self.calculator.add("2,1001"), 2) + + def test_numbers_greater_than_1000_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n2;1001"), 2) + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student2.py b/test_me_on_student2.py new file mode 100644 index 0000000..62056a3 --- /dev/null +++ b/test_me_on_student2.py @@ -0,0 +1,52 @@ +import unittest +from other.student2.Calculator import StringCalculator #wasili + +class TestMeOnStudent2(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + + def test_numbers_with_multiple_newlines(self): + self.assertEqual(self.calc.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2,3") + self.assertEqual(str(context.exception), "negatives not allowed: -2") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2,-3,4") + self.assertEqual(str(context.exception), "negatives not allowed: -2, -3") + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calc.add("//;\n1;2\n3"), 6) + + def test_custom_delimiter_with_multiple_numbers(self): + self.assertEqual(self.calc.add("//|\n1|2|3|4"), 10) + + def test_numbers_greater_than_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + + def test_numbers_greater_than_1000_with_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n2;1001"), 2) + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student3.py b/test_me_on_student3.py new file mode 100644 index 0000000..1219fa4 --- /dev/null +++ b/test_me_on_student3.py @@ -0,0 +1,49 @@ +import unittest +from other.student3.Calculator import StringCalculator #momo + +class TestMyCasesOnStudent3(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + + def test_multiple_newlines(self): + self.assertEqual(self.calc.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError) as e: + self.calc.add("1,-2,3") + self.assertEqual(str(e.exception), "negatives not allowed: -2") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as e: + self.calc.add("1,-2,-3,4") + self.assertEqual(str(e.exception), "negatives not allowed: -2,-3") + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calc.add("//;\n1;2\n3"), 6) + + def test_ignore_numbers_over_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + + def test_custom_delimiter_any_length(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student4.py b/test_me_on_student4.py new file mode 100644 index 0000000..751d20e --- /dev/null +++ b/test_me_on_student4.py @@ -0,0 +1,49 @@ +import unittest +from other.student4.Calculator import StringCalculator # Marvin + +class TestMyCasesOnStudent4(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + + def test_multiple_newlines(self): + self.assertEqual(self.calc.add("1\n2\n3\n4\n5"), 15) + + def test_negative_number(self): + with self.assertRaises(ValueError) as e: + self.calc.add("1,-2,3") + self.assertEqual(str(e.exception), "Negative numbers are not allowed: -2") + + def test_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as e: + self.calc.add("1,-2,-3,4") + self.assertEqual(str(e.exception), "Negative numbers are not allowed: -2, -3") + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + + def test_custom_delimiter_with_newline(self): + self.assertEqual(self.calc.add("//;\n1;2\n3"), 6) + + def test_ignore_numbers_over_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + + def test_custom_delimiter_any_length(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student5.py b/test_me_on_student5.py new file mode 100644 index 0000000..c66995b --- /dev/null +++ b/test_me_on_student5.py @@ -0,0 +1,30 @@ +import unittest +from other.student5.Calculator_combined import StringCalculator #orlando + +class TestMeOnStudent5(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_ignores_empty_entries(self): + self.assertEqual(self.calc.add("1,,2"), 3) + self.assertEqual(self.calc.add(",,1,,2,,"), 3) + + def test_add_multi_char_delimiter(self): + self.assertEqual(self.calc.add("//[abc]\n4abc5abc6"), 15) + + def test_newlines_mixed_with_commas(self): + self.assertEqual(self.calc.add("1,2\n3"), 6) + + def test_single_number(self): + self.assertEqual(self.calc.add("5"), 5) + + def test_custom_delimiters_varied(self): + self.assertEqual(self.calc.add("//_\n7_8_9"), 24) + + def test_multiple_negatives(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-1,-2") + self.assertIn("negatives not allowed", str(context.exception)) + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student6.py b/test_me_on_student6.py new file mode 100644 index 0000000..9e6e723 --- /dev/null +++ b/test_me_on_student6.py @@ -0,0 +1,53 @@ +import unittest +from other.student6.Calculator_combined import StringCalculator #lasse + +class TestStudent6OnMe(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_add_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calc.add("10,20"), 30) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3"), 6) + self.assertEqual(self.calc.add("10,20,30,40"), 100) + + def test_add_with_newline_separator(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + self.assertEqual(self.calc.add("10\n20\n30"), 60) + + def test_add_single_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2,3") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-2]") + + def test_add_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-10\n-20,-30") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-10, -20, -30]") + + def test_add_with_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + self.assertEqual(self.calc.add("//x\n7x8\n9"), 24) + + def test_invalid_custom_delimiter_format(self): + with self.assertRaises(ValueError): + self.calc.add("//;1;2") + + def test_ignore_numbers_greater_than_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + self.assertEqual(self.calc.add("1002,50200"), 0) + + def test_add_with_custom_delimiter_multiple_characters(self): + self.assertEqual(self.calc.add("//[**]\n1**2**3"), 6) + self.assertEqual(self.calc.add("//[###]\n10###20###30"), 60) + + +if __name__ == "__main__": + unittest.main() diff --git a/test_me_on_student7.py b/test_me_on_student7.py new file mode 100644 index 0000000..e320a61 --- /dev/null +++ b/test_me_on_student7.py @@ -0,0 +1,23 @@ +import unittest +from other.student7.Calculator import StringCalculator # Student 7s Code wird getestet + +class TestMeOnStudent7(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//|\n1|2|3|4"), 10) + + def test_newlines_and_large_numbers(self): + self.assertEqual(self.calc.add("1\n2,1001"), 3) + + def test_negative_handling(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2,-3") + self.assertEqual(str(context.exception), "Negatives not allowed: -2, -3") + +if __name__ == "__main__": + unittest.main() diff --git a/test_student1_on_me.py b/test_student1_on_me.py new file mode 100644 index 0000000..41a50da --- /dev/null +++ b/test_student1_on_me.py @@ -0,0 +1,69 @@ +import unittest +from my_string_calculator import StringCalculator + +class TestStudent1OnMyCalc(unittest.TestCase): + def setUp(self): + self.c = StringCalculator() + + def test_empty(self): + self.assertEqual(self.c.add(""), 0) + + def test_oneNumber(self): + self.assertEqual(self.c.add("1"), 1) + + def test_addingTwoNumbers(self): + self.assertEqual(self.c.add("1,2"), 3) + + def test_addingTwoNumbersWithZero(self): + self.assertEqual(self.c.add("0,5"), 5) + + def test_handleFloat(self): + with self.assertRaises(Exception): + self.c.add("3.5") + + def test_handleLetter(self): + with self.assertRaises(Exception): + self.c.add("1, z") + + def test_addWithBackslashN(self): + self.assertEqual(self.c.add("1\n2,3"), 6) + + def test_negativeValues(self): + with self.assertRaises(ValueError): + self.c.add("-3") + + def test_delimiter(self): + self.assertEqual(self.c.add("//;\n1;2"), 3) + + def test_thousandone(self): + self.assertEqual(self.c.add("2, 1001"), 2) + + def test_multidelimiter(self): + self.assertEqual(self.c.add("//[***]\n1***2***3"), 6) + + def test_multi_negative(self): + with self.assertRaises(ValueError): + self.c.add("-3, -4") + + def test_space_between_numbers(self): + self.assertEqual(self.c.add(" 4 , 5"), 9) + + def test_multiple_num_with_thousandone(self): + self.assertEqual(self.c.add(" 2, 1001, 5"), 7) + + def test_empty_text(self): + self.assertEqual(self.c.add("//;\n"), 0) + + def test_one_number_with_empty_string(self): + self.assertEqual(self.c.add("1,"), 1) + + def test_negative_with_positive(self): + with self.assertRaises(ValueError): + self.c.add("-2, 5") + + def test_mixture(self): + with self.assertRaises(ValueError): + self.c.add("//;\n-1;2;1001;-3") + +if __name__ == "__main__": + unittest.main() diff --git a/test_student2_on_me.py b/test_student2_on_me.py new file mode 100644 index 0000000..ad6d014 --- /dev/null +++ b/test_student2_on_me.py @@ -0,0 +1,47 @@ +import unittest +from my_string_calculator import StringCalculator # Wasili + +class TestStudent2OnMe(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_add_empty(self): + self.assertEqual(self.calc.add(""), 0) + + def test_add_one_string(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_add_two_string(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_add_multiple_string(self): + self.assertEqual(self.calc.add("1,2,3,4,5,6,7"), 28) + + def test_add_new_lines(self): + self.assertEqual(self.calc.add("1\n2,3,4"), 10) + + def test_add_exception(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-5") + self.assertEqual(str(context.exception), "Negatives not allowed: -5") + + def test_add_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-5,-2,-2") + self.assertEqual(str(context.exception), "Negatives not allowed: -5, -2, -2") + + def test_add_different_delimiters(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + + def test_add_numbers_greater_than_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + self.assertEqual(self.calc.add("2,10022\n6"), 8) + + def test_delimiters_of_any_length(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + + def test_delimiters_of_any_length2(self): + self.assertEqual(self.calc.add("//[*+*+*]\n1*+*+*2*+*+*3*+*+*220"), 226) + +if __name__ == "__main__": + unittest.main() diff --git a/test_student3_on_me.py b/test_student3_on_me.py new file mode 100644 index 0000000..a498fc0 --- /dev/null +++ b/test_student3_on_me.py @@ -0,0 +1,49 @@ +import unittest +from my_string_calculator import StringCalculator #Momo + +class TestStudent3CasesOnMe(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calc.add("5"), 5) + + def test_multiple_numbers(self): + self.assertEqual(self.calc.add("5,5"), 10) + + def test_unknown_amount_of_numbers(self): + self.assertEqual(self.calc.add("1,2,3"), 6) + self.assertEqual(self.calc.add("10,20,30,40"), 100) + self.assertEqual(self.calc.add("1,2,3,4,5,6"), 21) + + def test_numbers_separated_by_newline(self): + self.assertEqual(self.calc.add("1\n2"), 3) + self.assertEqual(self.calc.add("1\n2\n3"), 6) + self.assertEqual(self.calc.add("10,20\n30"), 60) + + def test_negative_number_exception(self): + with self.assertRaises(ValueError) as e: + self.calc.add("-1,2") + self.assertEqual(str(e.exception), "Negatives not allowed: -1") + + def test_multiple_negative_numbers_exception(self): + with self.assertRaises(ValueError) as e: + self.calc.add("-1,-2,3") + self.assertEqual(str(e.exception), "Negatives not allowed: -1, -2") + + def test_add_numbers_with_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2;3"), 6) + + def test_ignore_numbers_over_1000(self): + self.assertEqual(self.calc.add("1,1001,2,3"), 6) + + def test_custom_delimiter_with_long_pattern(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + self.assertEqual(self.calc.add("//[+++]\n1+++2+++3"), 6) + self.assertEqual(self.calc.add("//[aa]\n1aa2aa3"), 6) + +if __name__ == "__main__": + unittest.main() diff --git a/test_student4_on_me.py b/test_student4_on_me.py new file mode 100644 index 0000000..70cde1e --- /dev/null +++ b/test_student4_on_me.py @@ -0,0 +1,55 @@ +import unittest +from my_string_calculator import StringCalculator + +class TestStudent4CasesOnMe(unittest.TestCase): + def setUp(self): + self.calculator = StringCalculator() + + def test_empty_string_returns_zero(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_single_number_returns_value(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_two_numbers_return_sum(self): + self.assertEqual(self.calculator.add("1,2"), 3) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calculator.add("1,2,3,4,5"), 15) + + def test_add_numbers_with_newlines(self): + self.assertEqual(self.calculator.add("1\n2\n3"), 6) + + def test_add_negative_numbers(self): + with self.assertRaises(ValueError) as e: + self.calculator.add("-1,2,-3") + self.assertEqual(str(e.exception), "Negatives not allowed: -1, -3") + + def test_add_numbers_with_custom_delimiter(self): + self.assertEqual(self.calculator.add("//;\n1;2;3"), 6) + + def test_add_numbers_with_custom_delimiter_different_symbol(self): + self.assertEqual(self.calculator.add("//#\n4#5#6"), 15) + + def test_custom_delimiter_with_multiple_numbers(self): + self.assertEqual(self.calculator.add("//:\n1:2:3:4:5:6"), 21) + + def test_add_numbers_greater_than_1000(self): + self.assertEqual(self.calculator.add("1,1001,2,3"), 6) + + def test_add_numbers_with_newlines_and_ignore_above_1000(self): + self.assertEqual(self.calculator.add("1\n2\n1000\n1001"), 1003) + + def test_add_numbers_with_custom_delimiter_long_length(self): + self.assertEqual(self.calculator.add("//[***]\n1***2***3"), 6) + + def test_custom_long_delimiter_with_large_number_ignored(self): + self.assertEqual(self.calculator.add("//[***]\n1***1001***2"), 3) + + def test_custom_long_delimiter_with_negative_numbers(self): + with self.assertRaises(ValueError) as e: + self.calculator.add("//[***]\n1***-2***3***-4") + self.assertEqual(str(e.exception), "Negatives not allowed: -2, -4") + +if __name__ == "__main__": + unittest.main() diff --git a/test_student5_on_me.py b/test_student5_on_me.py new file mode 100644 index 0000000..f612723 --- /dev/null +++ b/test_student5_on_me.py @@ -0,0 +1,57 @@ +import unittest +from my_string_calculator import StringCalculator + +class TestStudent5OnMyCode(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_add_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3"), 6) + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_add_ignores_empty_entries(self): + self.assertEqual(self.calc.add("1,,2"), 3) + self.assertEqual(self.calc.add("1, ,2"), 3) + self.assertEqual(self.calc.add(",,1,,2,,,"), 3) + + def test_add_with_newlines_between_numbers(self): + 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): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2") + self.assertIn("Negatives not allowed", str(context.exception)) + + def test_add_raises_exception_on_multiple_negatives(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-1,-2,3") + self.assertIn("Negatives not allowed", str(context.exception)) + + def test_add_with_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + self.assertEqual(self.calc.add("//|\n4|5|6"), 15) + self.assertEqual(self.calc.add("//_\n7_8_9"), 24) + + def test_add_ignores_numbers_greater_than_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + self.assertEqual(self.calc.add("1000,1"), 1001) + self.assertEqual(self.calc.add("1234,1001,3"), 3) + + def test_add_with_multi_char_delimiter(self): + self.assertEqual(self.calc.add("//[***]\n1***2***3"), 6) + self.assertEqual(self.calc.add("//[abc]\n4abc5abc6"), 15) + self.assertEqual(self.calc.add("//[+]\n1+2+3"), 6) + +if __name__ == "__main__": + unittest.main() diff --git a/test_student6_on_me.py b/test_student6_on_me.py new file mode 100644 index 0000000..f21ca8b --- /dev/null +++ b/test_student6_on_me.py @@ -0,0 +1,53 @@ +import unittest +from my_string_calculator import StringCalculator # lasse + +class TestStudent6OnMe(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_add_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calc.add("10,20"), 30) + + def test_add_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3"), 6) + self.assertEqual(self.calc.add("10,20,30,40"), 100) + + def test_add_with_newline_separator(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + self.assertEqual(self.calc.add("10\n20\n30"), 60) + + def test_add_single_negative_number(self): + with self.assertRaises(ValueError) as context: + self.calc.add("1,-2,3") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-2]") + + def test_add_multiple_negative_numbers(self): + with self.assertRaises(ValueError) as context: + self.calc.add("-10\n-20,-30") + self.assertEqual(str(context.exception), "Negative nicht erlaubt: [-10, -20, -30]") + + def test_add_with_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + self.assertEqual(self.calc.add("//x\n7x8\n9"), 24) + + def test_invalid_custom_delimiter_format(self): + with self.assertRaises(ValueError): + self.calc.add("//;1;2") + + def test_ignore_numbers_greater_than_1000(self): + self.assertEqual(self.calc.add("2,1001"), 2) + self.assertEqual(self.calc.add("1002,50200"), 0) + + def test_add_with_custom_delimiter_multiple_characters(self): + self.assertEqual(self.calc.add("//[**]\n1**2**3"), 6) + self.assertEqual(self.calc.add("//[###]\n10###20###30"), 60) + + +if __name__ == "__main__": + unittest.main() diff --git a/test_student7_on_me.py b/test_student7_on_me.py new file mode 100644 index 0000000..626f263 --- /dev/null +++ b/test_student7_on_me.py @@ -0,0 +1,35 @@ +import unittest +from my_string_calculator import StringCalculator # Hatice und ich hatten den selben code + +class TestStudent7OnMe(unittest.TestCase): + def setUp(self): + self.calc = StringCalculator() + + def test_empty_string(self): + self.assertEqual(self.calc.add(""), 0) + + def test_single_number(self): + self.assertEqual(self.calc.add("1"), 1) + + def test_two_numbers(self): + self.assertEqual(self.calc.add("1,2"), 3) + + def test_multiple_numbers(self): + self.assertEqual(self.calc.add("1,2,3,4,5"), 15) + + def test_numbers_with_newline(self): + self.assertEqual(self.calc.add("1\n2,3"), 6) + + def test_negative_number(self): + with self.assertRaises(ValueError) as e: + self.calc.add("1,-2") + self.assertEqual(str(e.exception), "Negatives not allowed: -2") + + def test_custom_delimiter(self): + self.assertEqual(self.calc.add("//;\n1;2"), 3) + + def test_large_numbers_ignored(self): + self.assertEqual(self.calc.add("2,1001"), 2) + +if __name__ == "__main__": + unittest.main() -- GitLab