def test_window_function(self): assert [push(stack()[-2] + stack()[-1]) for i in window(range(2, 12), 0, 1)] == [ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ]
def test_stack_is_isolated_in_generator_contexts(self): push(42) def helper(): for i in range(50, 60): push(i) yield i self.assertEqual(i, pop()) push(-1) for j, i in enumerate(helper()): self.assertEqual(j - 1, pop()) push(j) self.assertEqual([42, 9], stack())
def test_stack_works(self): push(42) dup() dup() self.assertEqual([42, 42, 42], stack())
def test_discard_if_false(self): results = [(pop(), len(stack())) for i in range(10) if discard_if_false(push(i) % 2)] assert all(result[1] == 0 for result in results) assert len(results) == 5 assert [result[0] for result in results] == list(range(1, 10, 2))
def test_push_if_true(self): results = [(pop(), len(stack())) for i in range(10) if push_if_true(i % 2)] assert all(result[1] == 0 for result in results) assert len(results) == 5
def test_window_function(self): assert [push(stack()[-2] + stack()[-1]) for i in window(range(2,12), 0,1)] == [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]