Skip to content

Commit 1f3b829

Browse files
committed
test: adding more tests to missing number algorithm
1 parent d96029e commit 1f3b829

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: bit_manipulation/missing_number.py

+14
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ def find_missing_number(nums: list[int]) -> int:
1111
Example:
1212
>>> find_missing_number([0, 1, 3, 4])
1313
2
14+
>>> find_missing_number([4, 3, 1, 0])
15+
2
16+
>>> find_missing_number([-2, 0, 1, 3, 4])
17+
Traceback (most recent call last):
18+
...
19+
ValueError: negative values not supported
1420
"""
1521
n = len(nums)
1622
missing_number = n
1723

1824
for i in range(n):
25+
if nums[i] < 0:
26+
raise ValueError("negative values not supported")
1927
missing_number ^= i ^ nums[i]
2028

2129
return missing_number
30+
31+
32+
if __name__ == "__main__":
33+
import doctest
34+
35+
doctest.testmod()

0 commit comments

Comments
 (0)