add unitest for FullSegment and QuerySegment

This commit is contained in:
aholic 2013-12-16 23:59:37 +08:00
parent 670c7e4a13
commit 17cd0bd899
2 changed files with 36 additions and 0 deletions

View 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])));
}

View 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])));
}