| 46 | }; |
| 47 | |
| 48 | TEST_F(PrefixMatchTest, SingleDictFastPathMatchesTablePath) { |
| 49 | // 1. Create a single-element DictGroup wrapper around marisaDict |
| 50 | std::list<DictPtr> dicts = { marisaDict }; |
| 51 | DictPtr dictGroup(new DictGroup(dicts)); |
| 52 | |
| 53 | // 2. Create two PrefixMatch instances: |
| 54 | // - pmFast uses the single dict fast-path (unwrapped group -> marisaDict) |
| 55 | PrefixMatch pmFast(dictGroup); |
| 56 | |
| 57 | // - pmTable uses the standard table path because we pass a group of two dicts |
| 58 | std::list<DictPtr> dictsMulti = { marisaDict, textDict }; |
| 59 | DictPtr dictGroupMulti(new DictGroup(dictsMulti)); |
| 60 | PrefixMatch pmTable(dictGroupMulti); |
| 61 | |
| 62 | // Compare queries |
| 63 | const std::vector<std::string> testQueries = { |
| 64 | "清華", "清華大", "清華大學", "清", "積羽沉舟", "nowhere" |
| 65 | }; |
| 66 | |
| 67 | for (const std::string& query : testQueries) { |
| 68 | PrefixMatch::Match mFast = pmFast.MatchPrefix(query.c_str(), query.length()); |
| 69 | PrefixMatch::Match mTable = pmTable.MatchPrefix(query.c_str(), query.length()); |
| 70 | |
| 71 | EXPECT_EQ(mFast.matched, mTable.matched); |
| 72 | if (mFast.matched) { |
| 73 | EXPECT_EQ(mFast.keyLength, mTable.keyLength); |
| 74 | EXPECT_EQ(*mFast.key, *mTable.key); |
| 75 | EXPECT_EQ(*mFast.value, *mTable.value); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | TEST_F(PrefixMatchTest, MarisaLazyLoadFastPathDoesNotReconstruct) { |
| 81 | // 1. Load MarisaDict from the serialized ocd2 file (lazy load) |
nothing calls this directly
no test coverage detected