Skip to content

Commit b68f2ea

Browse files
committed
Add unit tests for group_contiguous_integers
This module-level utility (used by join_on_conjunctions) had no direct test coverage of its own, only indirect coverage through HumanName-level parsing tests. Add focused tests for its documented contract: empty/isolated/single values return no ranges, adjacent pairs are the smallest valid run, multiple separate runs are found independently, and out-of-order input isn't treated as contiguous (the function assumes ascending, strictly increasing input).
1 parent 1f0a6e0 commit b68f2ea

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/test_parser_util.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from nameparser.parser import group_contiguous_integers
2+
3+
4+
def test_empty_list_returns_no_ranges() -> None:
5+
assert group_contiguous_integers([]) == []
6+
7+
8+
def test_all_isolated_values_returns_no_ranges() -> None:
9+
# no two values are adjacent, so nothing counts as a "run"
10+
assert group_contiguous_integers([1, 3, 5]) == []
11+
12+
13+
def test_single_value_returns_no_ranges() -> None:
14+
# a run of length 1 isn't a contiguous "run" by this function's definition
15+
assert group_contiguous_integers([5]) == []
16+
17+
18+
def test_pair_of_adjacent_values_is_smallest_valid_run() -> None:
19+
assert group_contiguous_integers([4, 5]) == [(4, 5)]
20+
21+
22+
def test_single_contiguous_run() -> None:
23+
assert group_contiguous_integers([1, 2, 3]) == [(1, 3)]
24+
25+
26+
def test_multiple_separate_contiguous_runs() -> None:
27+
assert group_contiguous_integers([1, 2, 5, 6, 7, 9]) == [(1, 2), (5, 7)]
28+
29+
30+
def test_isolated_values_between_runs_are_excluded() -> None:
31+
assert group_contiguous_integers([1, 2, 4, 6, 7]) == [(1, 2), (6, 7)]
32+
33+
34+
def test_unsorted_input_is_not_treated_as_contiguous() -> None:
35+
# the function assumes ascending, strictly increasing input (as produced
36+
# by an `enumerate`-based index scan, which is how join_on_conjunctions
37+
# uses it); descending or out-of-order input won't find real-world runs
38+
assert group_contiguous_integers([3, 2, 1]) == []

0 commit comments

Comments
 (0)