File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -84,8 +84,12 @@ def get_value_for_operator(operator, values):
84
84
avg = total_sum / len (values )
85
85
return round_number (avg )
86
86
elif operator == "min" :
87
+ if not values :
88
+ return 0
87
89
return min (values )
88
90
elif operator == "max" :
91
+ if not values :
92
+ return 0
89
93
return max (values )
90
94
else :
91
95
raise ValueError ("Unsupported operator: {}" .format (operator ))
Original file line number Diff line number Diff line change 122
122
values = [10 , 3 , 45 , 7 ]
123
123
result = get_value_for_operator ('min' , values )
124
124
expect (result ).to (equal (3 ))
125
+ with context ('if sequence is empty' ):
126
+ with it ('should return 0' ):
127
+ values = []
128
+ result = get_value_for_operator ('min' , values )
129
+ expect (result ).to (equal (0 ))
125
130
126
131
with context ('when operator is "max"' ):
127
132
with it ('should return the maximum value' ):
128
133
values = [10 , 3 , 45 , 7 ]
129
134
result = get_value_for_operator ('max' , values )
130
135
expect (result ).to (equal (45 ))
136
+ with context ('if sequence is empty' ):
137
+ with it ('should return 0' ):
138
+ values = []
139
+ result = get_value_for_operator ('max' , values )
140
+ expect (result ).to (equal (0 ))
131
141
132
142
with context ('when an unsupported operator is provided' ):
133
143
with it ('should raise a ValueError' ):
You can’t perform that action at this time.
0 commit comments