Skip to content

Commit

Permalink
Added number.is_odd() method
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Oct 29, 2016
1 parent ce17584 commit 51c31ad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Changelog
- Add ``is_none()``.
- Add ``is_multiple_of()``.
- Add ``is_number()``.
- Add ``is_odd()``.
- Add ``is_string()``.
- Add ``last()``.
- Add ``random_()``.
Expand Down
5 changes: 5 additions & 0 deletions docs/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ Numbers
>>> _.is_multiple_of(1.5, 0.5)
True
>>> _.is_odd(6)
False
>>> _.is_odd(7)
True
>>> result = _.random_(5, 6)
>>> assert 5 <= result <= 6
>>> result = _.random_(5)
Expand Down
1 change: 1 addition & 0 deletions sugar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .number import (
is_even,
is_multiple_of,
is_odd,
random_
)

Expand Down
21 changes: 21 additions & 0 deletions sugar/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ def is_multiple_of(value, num):
return value % num == 0


def is_odd(num):
"""Returns True if :attr:`num` is odd.
Args:
num (int/float): Number passed in by the user.
Returns:
bool: True if :attr:`num` is odd else False
Example:
>>> is_odd(6)
False
>>> is_odd(7)
True
.. versionadded:: TODO
"""
return num % 2 != 0


def random_(n1=None, n2=None):
"""Returns a random integer/float from :attr:`n1` to :attr:`n2` (both
inclusive)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def test_is_multiple_of(value, num, expected):
assert _.is_multiple_of(value, num) == expected


@parametrize('num,expected', [
(6, False),
(7, True)
])
def test_is_odd(num, expected):
assert _.is_odd(num) == expected


@parametrize('args', [
(0, 5),
(2, 5),
Expand Down

0 comments on commit 51c31ad

Please sign in to comment.