Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test_me_on_student2.py 1.76 KiB
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()