|
14 | 14 | [ |
15 | 15 | (docs, 'java', [5]), |
16 | 16 | (docs, 'world', [1, 3]), |
| 17 | + (docs, 'hello', [1, 2]), |
17 | 18 | ] |
18 | 19 | ) |
19 | 20 | def test_search_single_word_found(docs, word, res): |
20 | 21 | """ |
21 | 22 | Test the search function to ensure it finds a single word correctly. |
22 | 23 | """ |
23 | | - |
24 | 24 | assert search(docs, word) == res, f"Expected {res}, but got {search(docs, word)}" |
25 | 25 |
|
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)}" |
33 | 39 |
|
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)}" |
37 | 53 |
|
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