From 17cd0bd899145656ae207b5435781374c0ff0d29 Mon Sep 17 00:00:00 2001 From: aholic Date: Mon, 16 Dec 2013 23:59:37 +0800 Subject: [PATCH] add unitest for FullSegment and QuerySegment --- test/unittest/TFullSegment.cpp | 18 ++++++++++++++++++ test/unittest/TQuerySegment.cpp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/unittest/TFullSegment.cpp create mode 100644 test/unittest/TQuerySegment.cpp diff --git a/test/unittest/TFullSegment.cpp b/test/unittest/TFullSegment.cpp new file mode 100644 index 0000000..891da5c --- /dev/null +++ b/test/unittest/TFullSegment.cpp @@ -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 words; + + ASSERT_EQ(segment.init(), true); + ASSERT_EQ(segment.cut(str, words), true); + + EXPECT_EQ(words, vector(res, res + sizeof(res)/sizeof(res[0]))); +} + diff --git a/test/unittest/TQuerySegment.cpp b/test/unittest/TQuerySegment.cpp new file mode 100644 index 0000000..e1d947b --- /dev/null +++ b/test/unittest/TQuerySegment.cpp @@ -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 words; + + ASSERT_EQ(segment.init(), true); + ASSERT_EQ(segment.cut(str, words), true); + + EXPECT_EQ(words, vector(res, res + sizeof(res)/sizeof(res[0]))); +} +