Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ format:
lint:
$(UV) run ruff check --exit-non-zero-on-fix
$(UV) run ruff format --check --diff
$(UV) run flake8 tests fast_collections

build:
$(UV) run maturin build --release
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires-python = ">=3.8"
readme = "README.md"
license = { text = "MIT" }
authors = [
{ name = "khabib73", email = "kh73bb@yahoo.com" },
{ name = "khabib Shakhbanov", email = "kh73bb@yahoo.com" },
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -28,6 +28,7 @@ dev = [
"maturin>=1.14.1",
"pytest>=8.3.5",
"ruff>=0.15.22",
"wemake-python-styleguide>=0.17.0",
]
docs = [
"mkdocs>=1.6.1",
Expand All @@ -44,3 +45,6 @@ build-backend = "maturin"
features = ["pyo3"]
module-name = "fast_collections"
include = ["fast_collections/"]

[tool.ruff]
line-length = 80
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 80
extend-ignore = WPS410,WPS412
47 changes: 28 additions & 19 deletions tests/test_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@


def _insert_all(trie, words):
for w in words:
trie.insert(w)
for word in words:
trie.insert(word)


@pytest.mark.parametrize(
"words", [[], ["hello"], ["hello", "world"], ["", "a", "b", "c"], ["a", "a", "b"]]
"words",
[
[],
["fast-collections"],
["hi", "honey"],
["", "abc", "def", "ghi"],
],
)
def test_size_and_word_count(trie, words):
"Test that the trie has the correct size and word count"
Expand All @@ -27,36 +33,39 @@ def test_size_and_word_count(trie, words):
[
"hello",
],
["hell", "world"],
["hello!"],
),
([], [], ["hello"]),
(["a", "b", "c"], ["a", "b", "c"], []),
(["a", "a", "b"], ["a", "b"], ["c"]),
(
["cat", "car", "cart"],
["cat", "car", "cart"],
["card", "cas", "cal"],
),
(["programming", "program"], ["program", "programming"], ["programme"]),
],
)
def test_contains(trie, words, present, absent):
"Test that the trie contains the correct words"
_insert_all(trie, words)

for w in present:
assert w in trie
for word in present:
assert word in trie

for w in absent:
assert w not in trie
assert not trie.search(w)
for word in absent:
assert word not in trie
assert not trie.search(word)


@pytest.mark.parametrize(
"words, prefix, expected",
[
(["hello"], "hello", True),
(["hello"], "hell", True),
(["hello"], "h", True),
(["hello"], "", True),
(["hello"], "help", False),
(["hello", "world"], "wo", True),
(["hello", "world"], "worl", True),
(["hello", "world"], "x", False),
(["abc"], "ab", True),
(["spaces"], "paces", False),
(["complexity"], "complex", True),
(["some_string"], "some_value", False),
(["foo", "bar"], "bar", True),
(["i", "love", "python"], "pyt", True),
(["i", "love", "python"], "foo", False),
],
)
def test_starts_with(trie, words, prefix, expected):
Expand Down
Loading
Loading