|
| 1 | +import pytest |
| 2 | + |
| 3 | +from leetcode_py import logged_test |
| 4 | + |
| 5 | +from .helpers import assert_word_dictionary, run_word_dictionary |
| 6 | +from .solution import WordDictionary |
| 7 | + |
| 8 | + |
| 9 | +class TestDesignAddAndSearchWordsDataStructure: |
| 10 | + |
| 11 | + @logged_test |
| 12 | + @pytest.mark.parametrize( |
| 13 | + "operations, inputs, expected", |
| 14 | + [ |
| 15 | + ( |
| 16 | + [ |
| 17 | + "WordDictionary", |
| 18 | + "addWord", |
| 19 | + "addWord", |
| 20 | + "addWord", |
| 21 | + "search", |
| 22 | + "search", |
| 23 | + "search", |
| 24 | + "search", |
| 25 | + ], |
| 26 | + [[], ["bad"], ["dad"], ["mad"], ["pad"], ["bad"], [".ad"], ["b.."]], |
| 27 | + [None, None, None, None, False, True, True, True], |
| 28 | + ), |
| 29 | + ( |
| 30 | + ["WordDictionary", "addWord", "search", "search", "search"], |
| 31 | + [[], ["a"], ["a"], ["."], ["aa"]], |
| 32 | + [None, None, True, True, False], |
| 33 | + ), |
| 34 | + ( |
| 35 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 36 | + [[], ["at"], ["and"], ["an"], [".at"], ["an."]], |
| 37 | + [None, None, None, False, False, True], |
| 38 | + ), |
| 39 | + ( |
| 40 | + ["WordDictionary", "addWord", "addWord", "search", "search"], |
| 41 | + [[], ["word"], ["world"], ["word"], ["wor."]], |
| 42 | + [None, None, None, True, True], |
| 43 | + ), |
| 44 | + ( |
| 45 | + ["WordDictionary", "addWord", "search", "search"], |
| 46 | + [[], ["test"], ["test"], ["t..t"]], |
| 47 | + [None, None, True, True], |
| 48 | + ), |
| 49 | + ( |
| 50 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 51 | + [[], ["a"], ["b"], ["a"], ["."], ["c"]], |
| 52 | + [None, None, None, True, True, False], |
| 53 | + ), |
| 54 | + ( |
| 55 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 56 | + [[], ["abc"], ["def"], ["..."], ["a.."], ["..f"]], |
| 57 | + [None, None, None, True, True, True], |
| 58 | + ), |
| 59 | + ( |
| 60 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 61 | + [ |
| 62 | + [], |
| 63 | + ["programming"], |
| 64 | + ["algorithm"], |
| 65 | + ["prog......."], |
| 66 | + ["algo....."], |
| 67 | + ["........ing"], |
| 68 | + ], |
| 69 | + [None, None, None, True, True, True], |
| 70 | + ), |
| 71 | + ( |
| 72 | + ["WordDictionary", "addWord", "addWord", "search", "search"], |
| 73 | + [[], ["x"], ["xy"], ["."], [".."]], |
| 74 | + [None, None, None, True, True], |
| 75 | + ), |
| 76 | + ( |
| 77 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 78 | + [[], ["hello"], ["world"], ["hi"], ["word"], ["......"]], |
| 79 | + [None, None, None, False, False, False], |
| 80 | + ), |
| 81 | + ( |
| 82 | + [ |
| 83 | + "WordDictionary", |
| 84 | + "addWord", |
| 85 | + "addWord", |
| 86 | + "addWord", |
| 87 | + "search", |
| 88 | + "search", |
| 89 | + "search", |
| 90 | + "search", |
| 91 | + ], |
| 92 | + [[], ["cat"], ["car"], ["card"], ["c.."], ["ca."], ["c..d"], ["....."]], |
| 93 | + [None, None, None, None, True, True, True, False], |
| 94 | + ), |
| 95 | + ( |
| 96 | + [ |
| 97 | + "WordDictionary", |
| 98 | + "addWord", |
| 99 | + "addWord", |
| 100 | + "addWord", |
| 101 | + "search", |
| 102 | + "search", |
| 103 | + "search", |
| 104 | + ], |
| 105 | + [ |
| 106 | + [], |
| 107 | + ["run"], |
| 108 | + ["runner"], |
| 109 | + ["running"], |
| 110 | + ["run"], |
| 111 | + ["run..."], |
| 112 | + ["run....."], |
| 113 | + ], |
| 114 | + [None, None, None, None, True, True, False], |
| 115 | + ), |
| 116 | + ( |
| 117 | + ["WordDictionary", "addWord", "addWord", "search", "search", "search"], |
| 118 | + [[], ["abc"], ["xyz"], ["..."], [".."], ["...."]], |
| 119 | + [None, None, None, True, False, False], |
| 120 | + ), |
| 121 | + ], |
| 122 | + ) |
| 123 | + def test_word_dictionary( |
| 124 | + self, |
| 125 | + operations: list[str], |
| 126 | + inputs: list[list[str]], |
| 127 | + expected: list[bool | None], |
| 128 | + ): |
| 129 | + result = run_word_dictionary(WordDictionary, operations, inputs) |
| 130 | + assert_word_dictionary(result, expected) |
0 commit comments