Skip to content

Commit 1a351e7

Browse files
test(unittest.util): Add tests for sorted_list_difference tail deduplication
Exercise the except-IndexError path where one list is exhausted and the remaining tail of the other list contains duplicates. These cases were previously untested and would have passed even without the fix in the preceding commit.
1 parent 919b41a commit 1a351e7

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/test_unittest/test_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def test_sorted_list_difference(self):
2626
self.assertEqual(sorted_list_difference([2], [1, 1]), ([2], [1]))
2727
self.assertEqual(sorted_list_difference([1, 2], [1, 1]), ([2], []))
2828

29+
def test_sorted_list_difference_tail_deduplication(self):
30+
# Tail deduplication when one list is exhausted before the other.
31+
# These exercise the except-IndexError path in sorted_list_difference.
32+
self.assertEqual(sorted_list_difference([], [0, 0]), ([], [0]))
33+
self.assertEqual(sorted_list_difference([0, 0], []), ([0], []))
34+
self.assertEqual(sorted_list_difference([], [1, 1, 2, 2]), ([], [1, 2]))
35+
self.assertEqual(sorted_list_difference([1, 1, 2, 2], []), ([1, 2], []))
36+
# One list exhausts mid-way, leaving duplicated tail in the other.
37+
self.assertEqual(sorted_list_difference([1], [1, 2, 2, 3, 3]), ([], [2, 3]))
38+
self.assertEqual(sorted_list_difference([1, 2, 2, 3, 3], [1]), ([2, 3], []))
39+
2940
def test_unorderable_list_difference(self):
3041
self.assertEqual(unorderable_list_difference([], []), ([], []))
3142
self.assertEqual(unorderable_list_difference([1, 2], []), ([2, 1], []))

0 commit comments

Comments
 (0)