Skip to content

Commit de31b8f

Browse files
authored
test: cover empty inputs and duplicate boundaries in bisect (#15466)
1 parent 0a72d14 commit de31b8f

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎searches/binary_search.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def bisect_left(
4242
3
4343
>>> bisect_left([0, 5, 7, 10, 15], 6, 2)
4444
2
45+
>>> bisect_left([], 2)
46+
0
47+
>>> bisect_left([2, 2, 2], 2)
48+
0
49+
>>> bisect_left([1, 2, 2, 2, 4], 2)
50+
1
4551
"""
4652
if hi < 0:
4753
hi = len(sorted_collection)
@@ -83,6 +89,12 @@ def bisect_right(
8389
3
8490
>>> bisect_right([0, 5, 7, 10, 15], 6, 2)
8591
2
92+
>>> bisect_right([], 2)
93+
0
94+
>>> bisect_right([2, 2, 2], 2)
95+
3
96+
>>> bisect_right([1, 2, 2, 2, 4], 2)
97+
4
8698
"""
8799
if hi < 0:
88100
hi = len(sorted_collection)

0 commit comments

Comments
 (0)