Skip to content

Commit

Permalink
fix(sliding_window): correction of tests (exceptions) and a typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Fahy committed Jul 24, 2019
1 parent b43761f commit 95ef017
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bff/fancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def sliding_window(sequence: Sequence, window_size: int, step: int):
try:
__ = iter(sequence)
except TypeError:
raise TypeError('Sequence must by iterable.')
raise TypeError('Sequence must be iterable.')

if not isinstance(step, int):
raise TypeError('Step must be an integer.')
Expand Down
25 changes: 17 additions & 8 deletions tests/test_fancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,35 @@ def test_sliding_window(self):
res_2 = ['abcdef', 'defghi', 'ghijkl', 'jklmno', 'mnopqr', 'pqrstu',
'stuvwx', 'vwxyz']
self.assertEqual(list(sliding_window(seq_1, 6, 3)), res_2)

# Check for exceptions.
# Should raise an exception if the sequence is not iterable.
with self.assertRaises(TypeError):
# Should raise an exception if the sequence is not iterable.
list(sliding_window(3, 2, 1))
# Should raise an exception if step is not an integer.
# Should raise an exception if step is not an integer.
with self.assertRaises(TypeError):
list(sliding_window(seq_1, 2, 1.0))
with self.assertRaises(TypeError):
list(sliding_window(seq_1, 2, '1'))
# Should raise an exception if window size is not an integer.
# Should raise an exception if window size is not an integer.
with self.assertRaises(TypeError):
list(sliding_window(seq_1, 2.0, 1))
with self.assertRaises(TypeError):
list(sliding_window(seq_1, '2', 1))
# Should raise an exception if window size is smaller
# than step or <= 0.
with self.assertRaises(ValueError):
# Should raise an exception if window size is smaller
# than step or <= 0.
list(sliding_window(seq_1, 2, 3))
with self.assertRaises(ValueError):
list(sliding_window(seq_1, -1, -1))
# Should raise an exception if the step is smaller or equal than 0.
# Should raise an exception if the step is smaller or equal than 0.
with self.assertRaises(ValueError):
list(sliding_window(seq_1, 2, 0))
with self.assertRaises(ValueError):
list(sliding_window(seq_1, 2, -1))
# Should raise an exception if length of sequence
# is smaller than the window size.
# Should raise an exception if length of sequence
# is smaller than the window size.
with self.assertRaises(ValueError):
list(sliding_window('abc', 4, 1))

def test_value_2_list(self):
Expand Down

0 comments on commit 95ef017

Please sign in to comment.