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:
Alexander Pantyukhin 2022-11-29 22:07:27 +04:00 committed by GitHub
parent 361ddaf29e
commit 47bf3f58e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)