本文整理匯總了Python中SortingStudy.Sortings.calculate_total_product方法的典型用法代碼示例。如果您正苦於以下問題:Python Sortings.calculate_total_product方法的具體用法?Python Sortings.calculate_total_product怎麽用?Python Sortings.calculate_total_product使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SortingStudy.Sortings
的用法示例。
在下文中一共展示了Sortings.calculate_total_product方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_calculate_total_product__if_non_list_value__exception_thrown
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例2: test_calculate_total_product__if_list_of_lists_values__exception_thrown
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例3: test_calculate_total_product__if_empty_list__exception_thrown
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例4: test_calculate_total_product__if_one_positive_value__returns_this_value
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例5: test_calculate_total_product__if_0_among_values__returns_0
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例6: test_calculate_total_product__if_3_negative_values__returns_negative_product
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)
示例7: test_calculate_total_product__returns_total_product
# 需要導入模塊: from SortingStudy import Sortings [as 別名]
# 或者: from SortingStudy.Sortings import calculate_total_product [as 別名]
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)