MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / TEST

Function TEST

external/sentencepiece/src/trainer_interface_test.cc:36–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36TEST(TrainerInterfaceTest, IsValidSentencePieceTest) {
37 TrainerSpec trainer_spec;
38 NormalizerSpec normalizer_spec;
39 NormalizerSpec denormalizer_spec;
40 trainer_spec.set_model_prefix("model");
41 trainer_spec.add_input("input");
42
43 // Calls the default method for better coverage.
44 TrainerInterface trainer(trainer_spec, normalizer_spec, denormalizer_spec);
45 EXPECT_TRUE(trainer.Train().ok());
46
47 auto IsValid = [&trainer_spec, &normalizer_spec,
48 &denormalizer_spec](const std::string &str) {
49 TrainerInterface trainer(trainer_spec, normalizer_spec, denormalizer_spec);
50 const string_util::UnicodeText text = string_util::UTF8ToUnicodeText(str);
51 return trainer.IsValidSentencePiece(text);
52 };
53
54 EXPECT_FALSE(trainer.IsValidSentencePiece({0x01, 0x00, 0x01}));
55 EXPECT_FALSE(trainer.IsValidSentencePiece({0x01, 0x00}));
56 EXPECT_FALSE(trainer.IsValidSentencePiece({0x00, 0x01}));
57 EXPECT_FALSE(trainer.IsValidSentencePiece({0x00}));
58
59 // Default trainer spec.
60 EXPECT_FALSE(IsValid(""));
61 EXPECT_FALSE(IsValid("12345678912345678")); // too long
62 EXPECT_TRUE(IsValid("a"));
63 EXPECT_TRUE(IsValid(WS));
64 EXPECT_TRUE(IsValid(WS "a"));
65 EXPECT_FALSE(IsValid("a" WS));
66 EXPECT_FALSE(IsValid(WS "a" WS));
67 EXPECT_FALSE(IsValid("a" WS "b"));
68 EXPECT_FALSE(IsValid("a" WS "b" WS));
69 EXPECT_TRUE(IsValid("あいう"));
70 EXPECT_TRUE(IsValid("グーグル")); // "ー" is a part of Katakana
71 EXPECT_TRUE(IsValid("食べる"));
72 EXPECT_FALSE(IsValid("漢字ABC")); // mixed CJK scripts
73 EXPECT_FALSE(IsValid("F1"));
74 EXPECT_FALSE(IsValid("1F"));
75 EXPECT_FALSE(IsValid("1A2"));
76 EXPECT_TRUE(IsValid("$10")); // $ and 1 are both "common" script.
77 EXPECT_FALSE(IsValid("$ABC"));
78 EXPECT_FALSE(IsValid("ab\tbc")); // "\t" is UPP boundary.
79 EXPECT_FALSE(IsValid("ab cd"));
80 EXPECT_FALSE(IsValid("\0\0"));
81 EXPECT_FALSE(IsValid("\0"));
82 EXPECT_TRUE(IsValid("proteïni")); // Combining Diaeresis should inherit
83 // script from base character.
84 EXPECT_TRUE(IsValid("ثَبَّتَ")); // Arabic Fatha and Shadda should inherit script
85 // from base character.
86
87 trainer_spec.set_split_by_whitespace(false);
88 EXPECT_TRUE(IsValid(WS));
89 EXPECT_TRUE(IsValid(WS WS WS "a"));
90 EXPECT_TRUE(IsValid(WS "a"));
91 EXPECT_FALSE(IsValid("a" WS));
92 EXPECT_FALSE(IsValid(WS "a" WS));
93 EXPECT_TRUE(IsValid("a" WS "b")); // "a b" is a valid piece.

Callers

nothing calls this directly

Calls 15

UTF8ToUnicodeTextFunction · 0.85
JoinPathFunction · 0.85
TempDirFunction · 0.85
NewWritableFileFunction · 0.85
ToChar32Function · 0.85
set_model_prefixMethod · 0.80
add_inputMethod · 0.80
okMethod · 0.80
IsValidSentencePieceMethod · 0.80

Tested by

no test coverage detected