コード例 #1
0
 def test_newline_in_delimiters(self) -> None:
     """Test that input with newline in delimiter placement pass"""
     testJob = String_Calculator()
     input_ = "1\n,2\n,3"
     expected = 6
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #2
0
 def test_many_numbers(self) -> None:
     """Test many numbers as input"""
     testJob = String_Calculator()
     input_ = "1,2,3,4,5,6,7,8,9,10"
     expected = 55
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #3
0
 def test_2_numbers(self) -> None:
     """Test 2 numbers as input"""
     testJob = String_Calculator()
     input_ = "42,99"
     expected = 141
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #4
0
 def test_1_number(self) -> None:
     """Test a single number as input"""
     testJob = String_Calculator()
     input_ = "42"
     expected = 42
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #5
0
 def test_empty_string(self) -> None:
     """Test empty string as input"""
     testJob = String_Calculator()
     input_ = ""
     expected = 0
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #6
0
 def test_custom_delimiters(self) -> None:
     """Test that custom delimiters can be used with `//delim1,delim2\n` syntax"""
     testJob = String_Calculator()
     input_ = "//***,@\n1***2@3"
     expected = 6
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
     input_ = "//***,&&\n1***2&&3"
     expected = 6
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #7
0
 def test_numbers_greater_than_1000(self) -> None:
     """Test that numbers greater than 1000 are ignored"""
     testJob = String_Calculator()
     input_ = "1,1001,2"
     expected = 3
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
     input_ = "1001,2001,3001"
     expected = 0
     actual = testJob.string_calculator(input_)
     self.assertEqual(expected, actual)
コード例 #8
0
 def test_negative_numbers(self) -> None:
     """Test that input with negative numbers fails"""
     testJob = String_Calculator()
     input_ = "-1"
     self.assertRaises(ValueError, testJob.string_calculator, input_)
     input_ = "-1,2,-3"
     self.assertRaises(ValueError, testJob.string_calculator, input_)
コード例 #9
0
 def test_incorrect_input_types(self) -> None:
     """Test that non-string inputs fail"""
     testJob = String_Calculator()
     incorrect_inputs = [None, 42, 3.1415, [], {}]
     for input_ in incorrect_inputs:
         self.assertRaises(TypeError, testJob.string_calculator, input_)