Skip to content

Commit

Permalink
added more tests which coverage revealed to be missing
Browse files Browse the repository at this point in the history
  • Loading branch information
EntilZha committed Mar 22, 2015
1 parent 99aa3a4 commit 714b5a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions functional/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def grouped(self, size):
result.append(FunctionalSequence(self.sequence[i:i+size]))
return FunctionalSequence(result)

def sorted(self, comp=None, key=None, reverse=False):
def sorted(self, key=None, reverse=False):
"""
Uses python sort and its passed arguments to sort the input.
Expand All @@ -913,7 +913,7 @@ def sorted(self, comp=None, key=None, reverse=False):
:param reverse: return list reversed or not
:return: sorted sequence
"""
return FunctionalSequence(sorted(self.sequence, cmp=comp, key=key, reverse=reverse))
return FunctionalSequence(sorted(self.sequence, key=key, reverse=reverse))

def reverse(self):
"""
Expand Down
25 changes: 25 additions & 0 deletions test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_str(self):
l = [1, 2, 3]
self.assertEqual(str(l), str(seq(l)))

def test_hash(self):
self.assertRaises(TypeError, lambda: hash(seq([1])))
t = (1, 2)
self.assertEqual(hash(t), hash(seq(t)))

def test_len(self):
l = [1, 2, 3]
s = seq(l)
Expand Down Expand Up @@ -262,6 +267,12 @@ def test_fold_right(self):
f = lambda x, y: y + [x]
self.assertEqual(l.fold_right([], f), ['c', 'b', 'a'])

def test_sorted(self):
s = seq([1, 3, 2, 5, 4])
r = s.sorted()
self.assertEqual([1, 2, 3, 4, 5], r)
self.assertType(r)

def test_reverse(self):
l = [1, 2, 3]
expect = [3, 2, 1]
Expand All @@ -284,6 +295,15 @@ def test_distinct(self):
self.assertEqual(result.size(), len(expect))
self.assertType(result)

def test_slice(self):
s = seq([1, 2, 3, 4])
result = s.slice(1, 2)
self.assertEqual(result, [2])
self.assertType(result)
result = s.slice(1, 3)
self.assertEqual(result, [2, 3])
self.assertType(result)

def test_any(self):
l = [True, False]
self.assertTrue(seq(l).any())
Expand Down Expand Up @@ -466,6 +486,11 @@ def test_to_dict(self):
d = {1: 2, 2: 10, 7: 2}
self.assertEqual(seq(l).to_dict(), d)

def test_dict(self):
l = [(1, 2), (2, 10), (7, 2)]
d = {1: 2, 2: 10, 7: 2}
self.assertEqual(seq(l).dict(), d)

def test_reduce_by_key(self):
l = [('a', 1), ('a', 2), ('a', 3), ('b', -1), ('b', 1), ('c', 10), ('c', 5)]
e = {"a": 6, "b": 0, "c": 15}.items()
Expand Down

0 comments on commit 714b5a3

Please sign in to comment.