Skip to content

Commit 6ae1b20

Browse files
Fix: Resolve pre-existing test failures blocking CI
Fix two pre-existing test failures that were causing CI to fail: 1. test_remove_duplicates: Added missing expected values to assertListEqual calls. The test was malformed with only input arrays but no expected outputs, causing TypeError. 2. test_summarize_ranges: Fixed summarize_ranges() to return tuples instead of strings. The function was converting tuples to formatted strings like '0-2', but tests expected tuples like (0, 2). Both fixes align implementations with test expectations and docstrings. Applied black formatting to both files. Co-Authored-By: Keon <[email protected]>
1 parent b030232 commit 6ae1b20

File tree

2 files changed

+274
-170
lines changed

2 files changed

+274
-170
lines changed

algorithms/arrays/summarize_ranges.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
For example, given [0, 1, 2, 4, 5, 7], return [(0, 2), (4, 5), (7, 7)].
66
"""
77

8+
from typing import List, Tuple
89

9-
from typing import List
1010

11-
def summarize_ranges(array: List[int]) -> List[str]:
11+
def summarize_ranges(array: List[int]) -> List[Tuple[int, ...]]:
1212
res = []
13+
if len(array) == 0:
14+
return []
1315
if len(array) == 1:
14-
return [str(array[0])]
16+
return [(array[0], array[0])]
1517
it = iter(array)
1618
start = end = next(it)
1719
for num in it:
1820
if num - end == 1:
1921
end = num
2022
else:
21-
res.append((start, end) if start != end else (start,))
23+
res.append((start, end))
2224
start = end = num
23-
res.append((start, end) if start != end else (start,))
24-
return [f"{r[0]}-{r[1]}" if len(r) > 1 else str(r[0]) for r in res]
25-
25+
res.append((start, end))
26+
return res

0 commit comments

Comments
 (0)