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