3454a55636
cffconvert / validate (push) Has been cancelled
ci-workflow / pre-commit (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (macos-latest) (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (ubuntu-latest) (push) Has been cancelled
ci-workflow / Minimal NLTK Download Test (windows-latest) (push) Has been cancelled
ci-workflow / Python 3.10 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.11 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.12 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.13 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.14 on macos-latest (push) Has been cancelled
ci-workflow / Python 3.14t on macos-latest (push) Has been cancelled
ci-workflow / Python 3.10 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.11 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.12 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.13 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.14 on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.14t on ubuntu-latest (push) Has been cancelled
ci-workflow / Python 3.10 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.11 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.12 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.13 on windows-latest (push) Has been cancelled
ci-workflow / Python 3.14 on windows-latest (push) Has been cancelled
83 lines
1.8 KiB
Python
83 lines
1.8 KiB
Python
import pytest
|
|
|
|
from nltk.util import everygrams
|
|
|
|
|
|
@pytest.fixture
|
|
def everygram_input():
|
|
"""Form test data for tests."""
|
|
return iter(["a", "b", "c"])
|
|
|
|
|
|
def test_everygrams_without_padding(everygram_input):
|
|
expected_output = [
|
|
("a",),
|
|
("a", "b"),
|
|
("a", "b", "c"),
|
|
("b",),
|
|
("b", "c"),
|
|
("c",),
|
|
]
|
|
output = list(everygrams(everygram_input))
|
|
assert output == expected_output
|
|
|
|
|
|
def test_everygrams_max_len(everygram_input):
|
|
expected_output = [
|
|
("a",),
|
|
("a", "b"),
|
|
("b",),
|
|
("b", "c"),
|
|
("c",),
|
|
]
|
|
output = list(everygrams(everygram_input, max_len=2))
|
|
assert output == expected_output
|
|
|
|
|
|
def test_everygrams_min_len(everygram_input):
|
|
expected_output = [
|
|
("a", "b"),
|
|
("a", "b", "c"),
|
|
("b", "c"),
|
|
]
|
|
output = list(everygrams(everygram_input, min_len=2))
|
|
assert output == expected_output
|
|
|
|
|
|
def test_everygrams_pad_right(everygram_input):
|
|
expected_output = [
|
|
("a",),
|
|
("a", "b"),
|
|
("a", "b", "c"),
|
|
("b",),
|
|
("b", "c"),
|
|
("b", "c", None),
|
|
("c",),
|
|
("c", None),
|
|
("c", None, None),
|
|
(None,),
|
|
(None, None),
|
|
(None,),
|
|
]
|
|
output = list(everygrams(everygram_input, max_len=3, pad_right=True))
|
|
assert output == expected_output
|
|
|
|
|
|
def test_everygrams_pad_left(everygram_input):
|
|
expected_output = [
|
|
(None,),
|
|
(None, None),
|
|
(None, None, "a"),
|
|
(None,),
|
|
(None, "a"),
|
|
(None, "a", "b"),
|
|
("a",),
|
|
("a", "b"),
|
|
("a", "b", "c"),
|
|
("b",),
|
|
("b", "c"),
|
|
("c",),
|
|
]
|
|
output = list(everygrams(everygram_input, max_len=3, pad_left=True))
|
|
assert output == expected_output
|