示例#1
0
def test_push():
    stack = Stack()
    stack.push('foo')
    stack.push('baar')
    assert_equal(stack.current, 'baar')
    stack.push('baz')
    assert_equal(list(stack.lookup()), ['foo', 'baar', 'baz'])
示例#2
0
def test_complete_stack():
    l = list
    stack = Stack()
    assert_true(stack.current is _undefined)
    for i, token in enumerate(TEST_TOKENS):
        stack.push(token)
        assert_true(isinstance(token, str))
        assert_equal(stack.current, token)
    for expected, received in zip(TEST_TOKENS, stack.flush()):
        assert_equal(expected, received)
    assert_equal(l(stack._stack), [])
示例#3
0
def test_complete_stack():
    l = list
    stack = Stack()
    assert_true(stack.current is _undefined)
    for i, token in enumerate(TEST_TOKENS):
        stack.push(token)
        assert_true(isinstance(token, str))
        assert_equal(stack.current, token)
    for expected, received in zip(TEST_TOKENS, stack.flush()):
        assert_equal(expected, received)
    assert_equal(l(stack._stack), [])
示例#4
0
def test_current():
    stack = Stack()
    assert_true(stack.current is _undefined)
    stack.push('foo')
    assert_equal(stack.current, 'foo')
    stack.pop()
    assert_true(stack.current is _undefined)
    stack.push('foo, part 2')
    stack.flush()
    assert_true(stack.current is _undefined)
    stack = Stack(['foo', 'bar', 'baz'])
    assert_equal(stack.current, 'baz')
示例#5
0
def test_push():
    stack = Stack()
    stack.push('foo')
    stack.push('baar')
    assert_equal(stack.current, 'baar')
    stack.push('baz')
    assert_equal(list(stack.lookup()), ['foo', 'baar', 'baz'])
示例#6
0
def test_flush():
    stack = Stack(['foo', 'bar'])
    flushed = stack.flush()
    assert_true(isinstance(flushed, Stack))
    assert_equal(list(flushed), ['foo', 'bar'])
示例#7
0
def test_pop():
    stack = Stack(['foo'])
    assert_equal(stack.current, 'foo')
    assert_equal(stack.pop(), 'foo')
    assert_equal(stack.current, _undefined)
    assert_raises(StackEmpty, stack.pop)
示例#8
0
def test_lookup():
    stack = Stack(['foo', 'bar', 'fooz', 'baz'])
    assert_equal(list(stack.lookup()), ['foo', 'bar', 'fooz', 'baz'])
示例#9
0
def test_current():
    stack = Stack()
    assert_true(stack.current is _undefined)
    stack.push('foo')
    assert_equal(stack.current, 'foo')
    stack.pop()
    assert_true(stack.current is _undefined)
    stack.push('foo, part 2')
    stack.flush()
    assert_true(stack.current is _undefined)
    stack = Stack(['foo', 'bar', 'baz'])
    assert_equal(stack.current, 'baz')
示例#10
0
def test_flush():
    stack = Stack(['foo', 'bar'])
    flushed = stack.flush()
    assert_true(isinstance(flushed, Stack))
    assert_equal(list(flushed), ['foo', 'bar'])
示例#11
0
def test_pop():
    stack = Stack(['foo'])
    assert_equal(stack.current, 'foo')
    assert_equal(stack.pop(), 'foo')
    assert_equal(stack.current, _undefined)
    assert_raises(StackEmpty, stack.pop)
示例#12
0
def test_lookup():
    stack = Stack(['foo', 'bar', 'fooz', 'baz'])
    assert_equal(list(stack.lookup()), ['foo', 'bar', 'fooz', 'baz'])