Skip to content

Commit

Permalink
Added arrays.is_equal() method
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Oct 25, 2016
1 parent 40c8a9f commit bf88eb2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changelog
- Add ``is_array()``.
- Add ``is_boolean()``.
- Add ``is_empty()``.
- Add ``is_equal()``.
- Add ``is_number()``.
- Add ``is_string()``.

Expand Down
11 changes: 11 additions & 0 deletions docs/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ Arrays
>>> _.is_empty([None])
False
>>> is_equal([1, 2], [1, 2])
True
>>> is_equal(['1'], [str(1)])
True
>>> is_equal([None], [])
False
>>> is_equal([1, 2], [2, 1])
False
>>> is_equal([], [])
True
>>> _.subtract([1, 2, 3], 2)
[1, 3]
>>> _.subtract ([1, 2, 3], [1, 3])
Expand Down
1 change: 1 addition & 0 deletions sugar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from_,
includes,
is_empty,
is_equal,
subtract
)

Expand Down
28 changes: 28 additions & 0 deletions sugar/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,34 @@ def is_empty(array):
return True if not array else False


def is_equal(array_one, array_two):
"""Returns True if :attr:`array_one` is equal to :attr:`array_two`.
Args:
array_one (list): First list of values provided by the user.
array_two (list): Second list of values provided by the user.
Returns:
bool: True if both the arrays are equal else False.
Example:
>>> is_equal([1, 2], [1, 2])
True
>>> is_equal(['1'], [str(1)])
True
>>> is_equal([None], [])
False
>>> is_equal([1, 2], [2, 1])
False
>>> is_equal([], [])
True
.. versionadded:: TODO
"""
return array_one == array_two


def subtract(array, item):
"""Subtracts :attr:`item` from the :attr:`array` and returns the result
as a new array. If :attr:`item` is also an array, all elements in it will
Expand Down
11 changes: 11 additions & 0 deletions tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ def test_is_empty(array, expected):
assert _.is_empty(array) == expected


@parametrize('array_one,array_two,expected', [
([1, 2], [1, 2], True),
([1, 2], [2, 1], False),
([], [], True),
([None], [], False),
(['1'], [str(1)], True)
])
def test_is_equal(array_one, array_two, expected):
assert _.is_equal(array_one, array_two) == expected


@parametrize('array,item,expected', [
([1, 2, 3], 3, [1, 2]),
([1, 2, 3], [1, 3], [2]),
Expand Down

0 comments on commit bf88eb2

Please sign in to comment.