mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
fix validation condition and add tests (#7997)
* fix validation condition and add tests * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
361ddaf29e
commit
47bf3f58e0
|
@ -19,9 +19,17 @@ def get_index_of_rightmost_set_bit(number: int) -> int:
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: Input must be a non-negative integer
|
ValueError: Input must be a non-negative integer
|
||||||
|
>>> get_index_of_rightmost_set_bit('test')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Input must be a non-negative integer
|
||||||
|
>>> get_index_of_rightmost_set_bit(1.25)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Input must be a non-negative integer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if number < 0 or not isinstance(number, int):
|
if not isinstance(number, int) or number < 0:
|
||||||
raise ValueError("Input must be a non-negative integer")
|
raise ValueError("Input must be a non-negative integer")
|
||||||
|
|
||||||
intermediate = number & ~(number - 1)
|
intermediate = number & ~(number - 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user