|
9 | 9 | {'id': 5, 'text': 'goodbye java'} |
10 | 10 | ] |
11 | 11 |
|
12 | | -@pytest.mark.parametrize( |
13 | | - 'docs, word, res', |
14 | | - [ |
15 | | - (docs, 'java', [5]), |
16 | | - (docs, 'world', [1, 3]), |
17 | | - (docs, 'hello', [1, 2]), |
18 | | - ] |
19 | | -) |
20 | | -def test_search_single_word_found(docs, word, res): |
21 | | - """ |
22 | | - Test the search function to ensure it finds a single word correctly. |
23 | | - """ |
24 | | - assert search(docs, word) == res, f"Expected {res}, but got {search(docs, word)}" |
25 | 12 |
|
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): |
| 13 | +class TestSearchFunction: |
35 | 14 | """ |
36 | | - Test that the search function returns an empty list for absent words. |
| 15 | + Test the search function to ensure it handles various cases, including: |
| 16 | + - Finding words correctly. |
| 17 | + - Returning empty lists for absent words. |
| 18 | + - Not matching partial words. |
| 19 | + - Handling empty or whitespace-only search queries. |
37 | 20 | """ |
38 | | - assert search(docs, word) == res, f"Expected [], but got {search(docs, word)}" |
| 21 | + @pytest.mark.parametrize( |
| 22 | + 'docs, word, res', |
| 23 | + [ |
| 24 | + (docs, 'java', [5]), |
| 25 | + (docs, 'world', [1, 3]), |
| 26 | + (docs, 'hello', [1, 2]), |
| 27 | + ] |
| 28 | + ) |
| 29 | + def test_search_single_word_found(self, docs, word, res): |
| 30 | + """ |
| 31 | + Test the search function to ensure it finds a single word correctly. |
| 32 | + """ |
| 33 | + assert search(docs, word) == res, f"Expected {res}, but got {search(docs, word)}" |
39 | 34 |
|
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)}" |
| 35 | + @pytest.mark.parametrize( |
| 36 | + 'docs, word, res', |
| 37 | + [ |
| 38 | + (docs, 'javascript', []), |
| 39 | + (docs, 'goodmorning', []), |
| 40 | + (docs, 'computer', []), |
| 41 | + ] |
| 42 | + ) |
| 43 | + def test_search_absent_word_not_found(self, docs, word, res): |
| 44 | + """ |
| 45 | + Test that the search function returns an empty list for absent words. |
| 46 | + """ |
| 47 | + assert search(docs, word) == res, f"Expected [], but got {search(docs, word)}" |
53 | 48 |
|
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)}' |
| 49 | + @pytest.mark.parametrize( |
| 50 | + 'docs, word, res', |
| 51 | + [ |
| 52 | + (docs, 'he', []), |
| 53 | + (docs, 'hell', []), |
| 54 | + (docs, 'o', []), |
| 55 | + ] |
| 56 | + ) |
| 57 | + def test_search_part_of_word_not_found(self, docs, word, res): |
| 58 | + """ |
| 59 | + Test that the search function does not return results for partial words. |
| 60 | + """ |
| 61 | + assert search(docs, word) == res, f"Expected [], but got {search(docs, word)}" |
| 62 | + |
| 63 | + @pytest.mark.parametrize('word', ['', ' ', '\t', '\n']) |
| 64 | + def test_search_empty_word(self, word): |
| 65 | + """ |
| 66 | + Test that the search function returns an empty list for empty or whitespace-only queries. |
| 67 | + """ |
| 68 | + assert search(docs, word) == [], f'Expected [], but got {search(docs, word)}' |
0 commit comments