Skip to content

Commit

Permalink
Updated the sequence function and added test cases (#1012)
Browse files Browse the repository at this point in the history
* updated the sequence function and added test cases

* updated according to the PEP style
  • Loading branch information
thesagarsehgal authored and antmarakis committed Jan 30, 2019
1 parent 06d690d commit 44ea2ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
from utils import *
import random

def test_sequence():
assert sequence(1) == (1,)
assert sequence("helloworld") == "helloworld"
assert sequence({"hello":4, "world":5}) == ({"hello":4, "world":5},)
assert sequence([1, 2, 3]) == [1, 2, 3]
assert sequence((4, 5, 6)) == (4, 5, 6)
assert sequence([(1, 2),(2, 3),(4, 5)]) == [(1, 2), (2, 3),(4, 5)]
assert sequence(([1, 2],[3, 4],[5, 6])) == ([1, 2], [3, 4],[5, 6])

def test_removeall_list():
assert removeall(4, []) == []
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


def sequence(iterable):
"""Coerce iterable to sequence, if it is not already one."""
"""Converts iterable to sequence, if it is not already one."""
return (iterable if isinstance(iterable, collections.abc.Sequence)
else tuple(iterable))
else tuple([iterable]))


def removeall(item, seq):
Expand Down

0 comments on commit 44ea2ee

Please sign in to comment.