File size: 1,222 Bytes
19b8775 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import pytest
from stanza.models.constituency.tree_stack import TreeStack
from stanza.tests import *
pytestmark = [pytest.mark.pipeline, pytest.mark.travis]
def test_simple():
stack = TreeStack(value=5, parent=None, length=1)
stack = stack.push(3)
stack = stack.push(1)
expected_values = [1, 3, 5]
for value in expected_values:
assert stack.value == value
stack = stack.pop()
assert stack is None
def test_iter():
stack = TreeStack(value=5, parent=None, length=1)
stack = stack.push(3)
stack = stack.push(1)
stack_list = list(stack)
assert list(stack) == [1, 3, 5]
def test_str():
stack = TreeStack(value=5, parent=None, length=1)
stack = stack.push(3)
stack = stack.push(1)
assert str(stack) == "TreeStack(1, 3, 5)"
def test_len():
stack = TreeStack(value=5, parent=None, length=1)
assert len(stack) == 1
stack = stack.push(3)
stack = stack.push(1)
assert len(stack) == 3
def test_long_len():
"""
Original stack had a bug where this took exponential time...
"""
stack = TreeStack(value=0, parent=None, length=1)
for i in range(1, 40):
stack = stack.push(i)
assert len(stack) == 40
|