Skip to content

Commit f70f60f

Browse files
author
shmelevik
committed
update tests
1 parent f585780 commit f70f60f

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

tests/basic_test.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,46 @@
1414
[
1515
(docs, 'java', [5]),
1616
(docs, 'world', [1, 3]),
17+
(docs, 'hello', [1, 2]),
1718
]
1819
)
1920
def test_search_single_word_found(docs, word, res):
2021
"""
2122
Test the search function to ensure it finds a single word correctly.
2223
"""
23-
2424
assert search(docs, word) == res, f"Expected {res}, but got {search(docs, word)}"
2525

26-
def test_search_single_words_found_2():
27-
result = search(docs, 'hello')
28-
assert result == [1, 2], f"Expected [1, 2], but got {result}"
29-
30-
def test_search_absent_word_not_found():
31-
result = search(docs, 'goodmorning')
32-
assert result == [], f"Expected [], but got {result}"
26+
@pytest.mark.parametrize(
27+
'docs, word, res',
28+
[
29+
(docs, 'javascript', []),
30+
(docs, 'goodmorning', []),
31+
(docs, 'computer', []),
32+
]
33+
)
34+
def test_search_absent_word_not_found(docs, word, res):
35+
"""
36+
Test that the search function returns an empty list for absent words.
37+
"""
38+
assert search(docs, word) == res, f"Expected [], but got {search(docs, word)}"
3339

34-
def test_search_part_of_word_not_found():
35-
result = search(docs, 'he')
36-
assert result == [], f"Expected [], but got {result}"
40+
@pytest.mark.parametrize(
41+
'docs, word, res',
42+
[
43+
(docs, 'he', []),
44+
(docs, 'hell', []),
45+
(docs, 'o', []),
46+
]
47+
)
48+
def test_search_part_of_word_not_found(docs, word, res):
49+
"""
50+
Test that the search function does not return results for partial words.
51+
"""
52+
assert search(docs, word) == res, f"Expected [], but got {search(docs, word)}"
3753

38-
def test_search_empty_word():
39-
result = search(docs, '')
40-
assert result == [], f"Expected [], but got {result}"
54+
@pytest.mark.parametrize('word', ['', ' ', '\t', '\n'])
55+
def test_search_empty_word(word):
56+
"""
57+
Test that the search function returns an empty list for empty or whitespace-only queries.
58+
"""
59+
assert search(docs, word) == [], f'Expected [], but got {search(docs, word)}'

0 commit comments

Comments
 (0)