mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add unitest for FullSegment and QuerySegment
This commit is contained in:
parent
670c7e4a13
commit
17cd0bd899
18
test/unittest/TFullSegment.cpp
Normal file
18
test/unittest/TFullSegment.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "src/FullSegment.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
TEST(FullSegment, Test1)
|
||||
{
|
||||
FullSegment segment("../dicts/jieba.dict.utf8");
|
||||
const char* str = "我来自北京邮电大学。。。 学号 123456";
|
||||
const char* res[] = {"我", "来自", "北京", "北京邮电", "北京邮电大学", "邮电", "邮电大学", "电大", "大学", "。", "。", "。", " ", "学号", " 123456"};
|
||||
vector<string> words;
|
||||
|
||||
ASSERT_EQ(segment.init(), true);
|
||||
ASSERT_EQ(segment.cut(str, words), true);
|
||||
|
||||
EXPECT_EQ(words, vector<string>(res, res + sizeof(res)/sizeof(res[0])));
|
||||
}
|
||||
|
18
test/unittest/TQuerySegment.cpp
Normal file
18
test/unittest/TQuerySegment.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "src/QuerySegment.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
TEST(QuerySegment, Test1)
|
||||
{
|
||||
QuerySegment segment("../dicts/jieba.dict.utf8", "../dicts/hmm_model.utf8", 3);
|
||||
const char* str = "小明硕士毕业于中国科学院计算所,后在日本京都大学深造";
|
||||
const char* res[] = {"小明", "硕士", "毕业", "于", "中国", "中国科学院", "科学", "科学院", "学院", "计算所", ",", "后", "在", "日本", "日本京都大学", "京都", "京都大学", "大学", "深造"};
|
||||
vector<string> words;
|
||||
|
||||
ASSERT_EQ(segment.init(), true);
|
||||
ASSERT_EQ(segment.cut(str, words), true);
|
||||
|
||||
EXPECT_EQ(words, vector<string>(res, res + sizeof(res)/sizeof(res[0])));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user