def test_get_new_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator._get_new_delimiter("//;\n1;2;17\n5") # Verify assert ';' == result
def test_call_add_with_new_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("//;\n1;2;17\n5") # Verify assert 25 == result
def test_add_with_new_line(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2\n17") # Verify assert 20 == result
def test_add_five_numbers(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2,17,4,1,1") # Verify assert 26 == result
def test_add_one_and_two(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2") # Verify assert 3 == result
def test_add_one(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1") # Verify assert 1 == result
def test_add_empty_string(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("") # Verify assert 0 == result
def test_get_new_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator._get_new_delimiter("//;\n1;2;17\n5") # Verify assert ';' == result
def test_add_with_new_line(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2\n17") # Verify assert 20 == result
def test_get_string_without_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator._get_string_without_delimiter("//;\n1,2") # Verify assert "1,2" == result
def test_add_one_and_two(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2") # Verify assert 3 == result
def test_add_five_numbers(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1,2,17,4,1,1") # Verify assert 26 == result
def test_get_string_without_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator._get_string_without_delimiter("//;\n1,2") # Verify assert "1,2" == result
def test_add_one(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("1") # Verify assert 1 == result
def test_call_add_with_new_delimiter(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("//;\n1;2;17\n5") # Verify assert 25 == result
def test_add_empty_string(self): # Setup string_calculator = StringCalculator() # Exercise result = string_calculator.add("") # Verify assert 0 == result
def test_create_error_message_for_negative_numbers(self): # Setup string_calculator = StringCalculator() negative_numbers = [-1, -2, -3] # Exercise result = string_calculator._create_error_message(negative_numbers) # Verify assert 'negatives not allowed: -1, -2, -3' == result
def test_create_error_message_for_negative_numbers(self): # Setup string_calculator = StringCalculator() negative_numbers = [-1, -2, -3] # Exercise result = string_calculator._create_error_message(negative_numbers) # Verify assert 'negatives not allowed: -1, -2, -3' == result
def test_is_new_delimiter_set(self): # Setup string_calculator = StringCalculator() # Exercise result1 = string_calculator._is_new_delimiter_set("//;\n1;2;17\n5") result2 = string_calculator._is_new_delimiter_set("1;2;17\n5") # Verify assert True == result1 assert False == result2
def test_is_new_delimiter_set(self): # Setup string_calculator = StringCalculator() # Exercise result1 = string_calculator._is_new_delimiter_set("//;\n1;2;17\n5") result2 = string_calculator._is_new_delimiter_set("1;2;17\n5") # Verify assert True == result1 assert False == result2
def test_negative_numbers_raises_exception(self): # Setup string_calculator = StringCalculator() exception_raised = False # Exercise try: result = string_calculator.add("-1") except Exception: exception_raised = True # Verify assert True == exception_raised
def test_negative_numbers_raises_exception(self): # Setup string_calculator = StringCalculator() exception_raised = False # Exercise try: result = string_calculator.add("-1") except Exception: exception_raised = True # Verify assert True == exception_raised
def test_multiple_negative_numbers(self): # Setup string_calculator = StringCalculator() exception_raised = False exception_message = "" # Exercise try: result = string_calculator.add("2,-1,4,-2") except Exception as err: exception_message = err exception_raised = True # Verify assert True == exception_raised assert 'negatives not allowed: -1, -2' == exception_message.args[0]
def test_multiple_negative_numbers(self): # Setup string_calculator = StringCalculator() exception_raised = False exception_message = "" # Exercise try: result = string_calculator.add("2,-1,4,-2") except Exception as err: exception_message = err exception_raised = True # Verify assert True == exception_raised assert 'negatives not allowed: -1, -2' == exception_message.args[0]
def setUp(self): self.stringCalculator = StringCalculator()
class TestStringCalculator(unittest.TestCase): def setUp(self): self.stringCalculator = StringCalculator() def test_for_empty_string_input(self): self.assertEqual(0,self.stringCalculator.add("")) def test_for_string_input_with_one_char(self): self.assertEqual(1,self.stringCalculator.add("1")) def test_for_string_input_with_more_than_one_chars(self): self.assertEqual(6,self.stringCalculator.add("1,2,3")) def test_for_string_input_delimited_by_new_lines(self): self.assertEqual(6,self.stringCalculator.add("1\n2,3")) def test_for_string_input_with_different_delimiters(self): self.assertEqual(3,self.stringCalculator.add("//;\n1;2")) def test_for_string_input_with_a_negative_number(self): try: self.stringCalculator.add("-1,2") except ValueError as ve: self.assertEqual("negatives not allowed -1", ve.args[0]) def test_for_string_input_with_multiple_negatives(self): try: self.stringCalculator.add("-1,2,-3") except ValueError as ve: self.assertEqual("negatives not allowed -1 -3", ve.args[0]) def test_for_how_many_times_add_was_invoked(self): tmp = StringCalculator() for _ in range(10): _ = tmp.add("") self.assertEqual(10,tmp.get_called_count()) def test_whether_numbers_greater_than_1000_are_ignored(self): self.assertEqual(2,self.stringCalculator.add("2,1001")) def test_for_delimiters_of_any_length(self): self.assertEqual(6,self.stringCalculator.add("//[***]\n1***2***3")) def test_for_multiple_delimiters(self): self.assertEqual(6,self.stringCalculator.add("//[*][%]\n1*2%3")) def test_for_multiple_multilength_delimeters(self): self.assertEqual(6,self.stringCalculator.add("//[***][\\%\\%\\%]\n1***2\\%\\%\\%3"))
def test_for_how_many_times_add_was_invoked(self): tmp = StringCalculator() for _ in range(10): _ = tmp.add("") self.assertEqual(10,tmp.get_called_count())