From 5b02300b4b48cf32a8022a973e7891070394cc5c Mon Sep 17 00:00:00 2001 From: Almmaa <Alma.Berisha@student.reutlingen-university.de> Date: Sun, 6 Apr 2025 01:45:17 +0200 Subject: [PATCH] =?UTF-8?q?Testf=C3=A4lle=20f=C3=BCr=20student3=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_me_on_student3.py | 49 ++++++++++++++++++++++++++++++++++++++++++ test_student3_on_me.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test_me_on_student3.py create mode 100644 test_student3_on_me.py 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_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() -- GitLab