Skip to content
Snippets Groups Projects
Commit bc39593d authored by Alma Berisha's avatar Alma Berisha
Browse files

Testfälle für student2 hinzugefügt

parent 0a4d0d71
No related branches found
No related tags found
No related merge requests found
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()
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment