diff --git a/test_me_on_student2.py b/test_me_on_student2.py new file mode 100644 index 0000000000000000000000000000000000000000..62056a319309a069b18b2a6191c5da8f9d2ddd2f --- /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 0000000000000000000000000000000000000000..ad6d014541c3df51cde650a07974c6b5386646a8 --- /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()