Skip to content

Commit b2f0cf2

Browse files
authored
Merge pull request #210 from derek73/test/group-contiguous-integers
Add unit tests for group_contiguous_integers
2 parents 1f0a6e0 + 8ed5a9a commit b2f0cf2

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/test_parser_util.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 grouping key (enumerate index - value) only repeats for ascending,
36+
# strictly increasing runs (as produced by an `enumerate`-based index
37+
# scan, which is how join_on_conjunctions uses it); a descending
38+
# sequence changes the key at every step, so no run is ever found
39+
assert group_contiguous_integers([3, 2, 1]) == []

0 commit comments

Comments
 (0)