Ejemplo n.º 1
0
 def test_fillvalue_as_keyword_argument_only(self):
     """Test can be called with fillvalue (but only as keyword arg)."""
     inputs = [1, 2, 3]
     outputs = [(1, 2, 3, 0)]
     self.assertIterableEqual(window(inputs, 4, fillvalue=0), outputs)
     with self.assertRaises(TypeError):
         window(inputs, 4, 0)
Ejemplo n.º 2
0
 def test_window_size_larger_than_iterable(self):
     self.assertIterableEqual(window([], 1), [(None, )])
     self.assertIterableEqual(window([1, 2], 3), [(
         1,
         2,
         None,
     )])
     self.assertIterableEqual(window([1, 2, 3], 4), [(1, 2, 3, None)])
Ejemplo n.º 3
0
 def test_returns_lazy_iterable(self):
     inputs = (n**2 for n in [1, 2, 3, 4, 5])
     iterable = window(inputs, 2)
     self.assertEqual(iter(iterable), iter(iterable))
     self.assertEqual(next(iterable), (1, 4))
     self.assertEqual(next(iterable), (4, 9))
     self.assertEqual(list(iterable), [(9, 16), (16, 25)])
Ejemplo n.º 4
0
 def test_window_size_0(self):
     self.assertIterableEqual(window([1, 2, 3], 0), [])
     self.assertIterableEqual(window([], 0), [])
Ejemplo n.º 5
0
 def test_accepts_iterator(self):
     inputs = (n**2 for n in [1, 2, 3, 4])
     outputs = [(1, 4), (4, 9), (9, 16)]
     self.assertIterableEqual(window(inputs, 2), outputs)
Ejemplo n.º 6
0
 def test_window_size_3(self):
     inputs = [1, 2, 3, 4, 5, 6]
     outputs = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]
     self.assertIterableEqual(window(inputs, 3), outputs)
Ejemplo n.º 7
0
 def test_string(self):
     inputs = "hey"
     outputs = [('h', 'e'), ('e', 'y')]
     self.assertIterableEqual(window(inputs, 2), outputs)
Ejemplo n.º 8
0
 def test_none(self):
     inputs = [None, None]
     outputs = [(None, None)]
     self.assertIterableEqual(window(inputs, 2), outputs)
Ejemplo n.º 9
0
 def test_window_size_1(self):
     self.assertIterableEqual(window([1, 2, 3], 1), [(1, ), (2, ), (3, )])
     self.assertIterableEqual(window([1], 1), [(1, )])
Ejemplo n.º 10
0
 def test_window_size_2(self):
     inputs = [1, 2, 3]
     outputs = [(1, 2), (2, 3)]
     self.assertIterableEqual(window(inputs, 2), outputs)