Debian Codegraph @

tests/ut_dpinyin.cpp

raw
1 // SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #include <gtest/gtest.h>
6 #include "util/dpinyin.h"
7 #include <algorithm>
8 DCORE_USE_NAMESPACE
9
10 class ut_DPinyin : public testing::Test
11 {
12 protected:
13 void SetUp() override;
14 void TearDown() override;
15 };
16
17 void ut_DPinyin::SetUp()
18 {
19 }
20
21 void ut_DPinyin::TearDown()
22 {
23 }
24
25 TEST_F(ut_DPinyin, testChinese2Pinyin)
26 {
27 auto pinyin = Chinese2Pinyin("你好, world");
28
29 ASSERT_EQ(pinyin, "ni3hao3, world");
30 }
31
32 TEST_F(ut_DPinyin, pinyin)
33 {
34 bool ok = false;
35 QString words("深度音乐");
36 QStringList tones = {"shēndùyīnlè", "shēndùyīnyuè", "shēndùyīnyào",
37 "shēndùyīnlào", "shēnduóyīnlè", "shēnduóyīnyuè",
38 "shēnduóyīnyào", "shēnduóyīnlào"};
39 QStringList noneTones = {"shenduyinle", "shenduyinyue", "shenduyinyao",
40 "shenduyinlao", "shenduoyinle", "shenduoyinyue",
41 "shenduoyinyao", "shenduoyinlao"};
42 QStringList numTones = {"shen1du4yin1le4", "shen1du4yin1yue4", "shen1du4yin1yao4",
43 "shen1du4yin1lao4", "shen1duo2yin1le4", "shen1duo2yin1yue4",
44 "shen1duo2yin1yao4", "shen1duo2yin1lao4"};
45
46 QStringList py = pinyin(words, TS_ToneNum, &ok);
47 ASSERT_TRUE(ok);
48 bool isPermutation = std::is_permutation(py.begin() , py.end(), numTones.begin());
49 ASSERT_TRUE(isPermutation);
50
51 py = pinyin(words, TS_NoneTone, &ok);
52
53 ASSERT_TRUE(ok);
54 isPermutation = std::is_permutation(py.begin() , py.end(), noneTones.begin());
55 ASSERT_TRUE(isPermutation);
56
57 py = pinyin(words, TS_Tone, &ok);
58 ASSERT_TRUE(ok);
59 isPermutation = std::is_permutation(py.begin() , py.end(), tones.begin());
60 ASSERT_TRUE(isPermutation);
61 }
62
63 TEST_F(ut_DPinyin, firstLetters)
64 {
65 QStringList letters = {"sdyl", "sdyy"};
66 QString words("深度音乐");
67 QStringList ls = firstLetters(words);
68
69 bool isPermutation = std::is_permutation(ls.begin() , ls.end(), letters.begin());
70 ASSERT_TRUE(isPermutation);
71 }
72