def test_calculate_total_product__if_non_list_value__exception_thrown(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with int value 3. Call calculate_total_product() Expected result: Exception thrown """ sortings = Sortings() sortings.list = 165 with self.assertRaises(Exception) as actual: sortings.calculate_total_product() self.assertEqual("Can not calculate total product for object of type not 'list'", actual.exception.message)
def test_calculate_total_product__if_list_of_lists_values__exception_thrown(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with list of lists 3. Call calculate_total_product() Expected result: Exception thrown """ sortings = Sortings() sortings.list = [[-100, -2, 10, -3, 2]] with self.assertRaises(Exception) as actual: sortings.calculate_total_product() self.assertEqual("An input list should contain only numeric values", actual.exception.message)
def test_calculate_total_product__if_empty_list__exception_thrown(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list by empty list 3. Call calculate_total_product() Expected result: Exception thrown """ sortings = Sortings() sortings.list = [] with self.assertRaises(Exception) as actual: sortings.calculate_total_product() self.assertEqual("Can not calculate total product of an empty list", actual.exception.message)
def test_calculate_total_product__if_one_positive_value__returns_this_value(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with one positive value 3. Call calculate_total_product() Expected result: This value returned """ sortings = Sortings() sortings.list = [11] actual_result = sortings.calculate_total_product() self.assertEqual(11, actual_result)
def test_calculate_total_product__if_0_among_values__returns_0(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with positive values and 0 3. Call calculate_total_product() Expected result: 0 returned """ sortings = Sortings() sortings.list = [2, 10, 3, 0] actual_result = sortings.calculate_total_product() self.assertEqual(0, actual_result)
def test_calculate_total_product__if_3_negative_values__returns_negative_product(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with mix of negative and positive values 3. Call calculate_total_product() Expected result: Correct total returned """ sortings = Sortings() sortings.list = [-2, -10, -3] actual_result = sortings.calculate_total_product() self.assertEqual(-60, actual_result)
def test_calculate_total_product__returns_total_product(self): """ Scenario: 1. Create object of Sortings class 2. Initialize list with int values 3. Call calculate_total_product() Expected result: Correct value of total product returned """ sortings = Sortings() sortings.list = [444, 1, 2, 3] actual_result = sortings.calculate_total_product() self.assertEqual(2664, actual_result)