From 4e594e7548cce0a0138ea5313bf93b3d7cc3920e Mon Sep 17 00:00:00 2001 From: Khabib <136262760+Khabib73@users.noreply.github.com> Date: Fri, 17 Jul 2026 16:57:36 +0300 Subject: [PATCH] Improve coverage --- fast_collections/__init__.pyi | 39 ++++++++++++++++++++ tests/test_ds/test_trie/test_trie.py | 54 ++++++++++++++++++++++++++++ tests/test_smoke.py | 8 ----- 3 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 tests/test_ds/test_trie/test_trie.py delete mode 100644 tests/test_smoke.py diff --git a/fast_collections/__init__.pyi b/fast_collections/__init__.pyi index 448fcd1..db4c350 100644 --- a/fast_collections/__init__.pyi +++ b/fast_collections/__init__.pyi @@ -38,6 +38,12 @@ class Trie: TypeError: If word is None. Complexity: O(k) where k = len(word) + + Examples: + >>> t = Trie() + >>> t.insert("hello") + >>> "hello" in t + True """ ... @@ -55,6 +61,14 @@ class Trie: TypeError: If word is None. Complexity: O(k) where k = len(word) + + Examples: + >>> t = Trie() + >>> t.insert("apple") + >>> t.search("apple") + True + >>> t.search("app") + False """ ... @@ -74,6 +88,12 @@ class Trie: TypeError: If prefix is None. Complexity: O(k) where k = len(prefix) + + Examples: + >>> t = Trie() + >>> t.insert("apple") + >>> t.starts_with("app") + True """ ... @@ -96,6 +116,12 @@ class Trie: TypeError: If word is None. Complexity: O(k) where k = len(word) + + Examples: + >>> t = Trie() + >>> t.insert("apple") + >>> t.delete("apple") + True """ ... @@ -107,6 +133,12 @@ class Trie: The count of distinct inserted words. Complexity: O(n) where n is the total number of nodes in the trie. + + Examples: + >>> t = Trie() + >>> t.insert("apple") + >>> t.word_count() + 1 """ ... @@ -123,6 +155,13 @@ class Trie: Complexity: O(m) where m is the total number of characters across all stored words. + + Examples: + >>> t = Trie() + >>> t.insert("apple") + >>> t.insert("banana") + >>> t.collect_words() + ['apple', 'banana'] """ ... diff --git a/tests/test_ds/test_trie/test_trie.py b/tests/test_ds/test_trie/test_trie.py new file mode 100644 index 0000000..dad3304 --- /dev/null +++ b/tests/test_ds/test_trie/test_trie.py @@ -0,0 +1,54 @@ +from fast_collections import Trie + + +def test_create_trie(): + Trie() + + +def test_trie_insert(): + t = Trie() + t.insert("hello") + assert "hello" in t, "insert(hello)" + t.insert("world") + assert "world" in t, "insert(world)" + + +def test_trie_remove(): + t = Trie() + t.insert("hello") + assert "hello" in t, "insert(hello)" + t.delete("hello") + assert "hello" not in t, "remove(hello)" + + +def test_trie_contains(): + t = Trie() + t.insert("hello") + assert "hello" in t, "insert(hello)" + assert "world" not in t, "contains(world)" + + +def test_trie_starts_with(): + t = Trie() + t.insert("hello") + assert t.starts_with("hello"), "starts_with(hello)" + assert not t.starts_with("world"), "starts_with(world)" + + +def test_trie_search(): + t = Trie() + t.insert("hello") + assert t.search("hello"), "search(hello)" + assert not t.search("world"), "search(world)" + + +def test_trie_size(): + t = Trie() + t.insert("hello") + assert len(t) == 1, "len()" + + +def test_trie_collect_words(): + t = Trie() + t.insert("hello") + assert t.collect_words() == ["hello"], "collect_words()" diff --git a/tests/test_smoke.py b/tests/test_smoke.py deleted file mode 100644 index 91cbcb9..0000000 --- a/tests/test_smoke.py +++ /dev/null @@ -1,8 +0,0 @@ -from fast_collections import Trie - - -def test_create_trie(): - t = Trie() - t.insert("hello") - assert "hello" in t, "contains(hello)" - assert t.starts_with("hel"), "starts_with(hel)"