本文整理汇总了Python中SortingStudy.Sortings.calculate_total方法的典型用法代码示例。如果您正苦于以下问题:Python Sortings.calculate_total方法的具体用法?Python Sortings.calculate_total怎么用?Python Sortings.calculate_total使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortingStudy.Sortings
的用法示例。
在下文中一共展示了Sortings.calculate_total方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_calculate_total__if_string_values__exception_thrown
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__if_string_values__exception_thrown(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with string
3. Call calculate_total()
Expected result: Exception thrown
"""
sortings = Sortings()
sortings.list = ["Test"]
with self.assertRaises(Exception) as actual:
sortings.calculate_total()
self.assertEqual("An input list should contain only numeric values", actual.exception.message)
示例2: test_calculate_total__if_non_list_value__exception_thrown
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__if_non_list_value__exception_thrown(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with int value
3. Call calculate_total()
Expected result: Exception thrown
"""
sortings = Sortings()
sortings.list = -20303
with self.assertRaises(Exception) as actual:
sortings.calculate_total()
self.assertEqual("Can not calculate total for object of type not 'list'", actual.exception.message)
示例3: test_calculate_total__if_empty_list__exception_thrown
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__if_empty_list__exception_thrown(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list by empty list
3. Call calculate_total()
Expected result: Exception thrown
"""
sortings = Sortings()
sortings.list = []
with self.assertRaises(Exception) as actual:
sortings.calculate_total()
self.assertEqual("Can not calculate total of an empty list", actual.exception.message)
示例4: test_calculate_total__if_one_negative_value__returns_this_value
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__if_one_negative_value__returns_this_value(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with one negative value
3. Call calculate_total()
Expected result: This value returned
"""
sortings = Sortings()
sortings.list = [-33012]
actual_result = sortings.calculate_total()
self.assertEqual(-33012, actual_result)
示例5: test__calculate_total__if_float_values__returns_total
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test__calculate_total__if_float_values__returns_total(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with float values and float resulting expressions
3. Call calculate_total()
Expected result: Correct total returned
"""
sortings = Sortings()
sortings.list = [0.333, 0, 1 / 3, 1.0 / 3.0]
actual_result = sortings.calculate_total()
self.assertEqual(0.6663333333333333, actual_result)
示例6: test_calculate_total__if_negative_values__returns_total
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__if_negative_values__returns_total(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with mix of negative and positive values
3. Call calculate_total()
Expected result: Correct total returned
"""
sortings = Sortings()
sortings.list = [100, -2, -10, -3, 2]
actual_result = sortings.calculate_total()
self.assertEqual(87, actual_result)
示例7: test_calculate_total__total_is_calculated
# 需要导入模块: from SortingStudy import Sortings [as 别名]
# 或者: from SortingStudy.Sortings import calculate_total [as 别名]
def test_calculate_total__total_is_calculated(self):
"""
Scenario:
1. Create object of Sortings class
2. Initialize list with int values
3. Call calculate_total()
Expected result: Total of int values returned
"""
sortings = Sortings()
sortings.list = [20202, 1, 2, 3]
actual_result = sortings.calculate_total()
self.assertEqual(20208, actual_result)