MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / TEST_F

Function TEST_F

src/PrefixMatchTest.cpp:48–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46};
47
48TEST_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
80TEST_F(PrefixMatchTest, MarisaLazyLoadFastPathDoesNotReconstruct) {
81 // 1. Load MarisaDict from the serialized ocd2 file (lazy load)

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
MatchPrefixViewMethod · 0.80
AddMethod · 0.80
SortMethod · 0.80
MatchPrefixMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected