Skip to content

Commit bcac1c8

Browse files
author
richie.p
committed
improve -Wrote the test for the remove_min algorithm. fix -Fixed some bugs in remove min algorithm.
1 parent 433c5c7 commit bcac1c8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

remove_min.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"""
77

88
def remove_min(array: list[int]) -> int:
9-
min_value = 0
9+
if len(array) == 0:
10+
return 0
1011

12+
min_value = array[0]
1113
for value in array:
1214
if min_value > value:
1315
min_value = value
14-
return min_value
1516

17+
return min_value

tests/test_remove_min.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from ..remove_min import remove_min
2+
3+
4+
class TestRemoveMin:
5+
def test_remove_min(self):
6+
assert remove_min([4, 5, 2, 8, -2, 5, 1, 9]) == -2
7+
assert remove_min([0, -9, 4, 5, 2, 8, -2]) == -9
8+
assert remove_min([0, 4, 5, 2, 8]) == 0
9+
assert remove_min([1]) == 1
10+
assert remove_min([]) == 0

0 commit comments

Comments
 (0)