mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add unittest
This commit is contained in:
parent
3545eef281
commit
86b78e723d
@ -13,3 +13,6 @@ ADD_SUBDIRECTORY(dicts)
|
||||
ADD_SUBDIRECTORY(scripts)
|
||||
ADD_SUBDIRECTORY(conf)
|
||||
ADD_SUBDIRECTORY(test)
|
||||
|
||||
ENABLE_TESTING()
|
||||
ADD_TEST(NAME mytest COMMAND test1)
|
||||
|
@ -1 +0,0 @@
|
||||
curl "http://127.0.0.1:11200/?key=南京市长江大桥"
|
@ -1,7 +1,11 @@
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test)
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test/lib)
|
||||
|
||||
SET(GTEST_ROOT_DIR gtest-1.6.0)
|
||||
|
||||
INCLUDE_DIRECTORIES(${GTEST_ROOT_DIR} ${GTEST_ROOT_DIR}/include)
|
||||
ADD_EXECUTABLE(test gtest_main.cc ${GTEST_ROOT_DIR}/src/gtest-all.cc)
|
||||
TARGET_LINK_LIBRARIES(test pthread)
|
||||
INCLUDE_DIRECTORIES(${GTEST_ROOT_DIR} ${GTEST_ROOT_DIR}/include ${PROJECT_SOURCE_DIR})
|
||||
ADD_LIBRARY(gtest STATIC ${GTEST_ROOT_DIR}/src/gtest-all.cc)
|
||||
ADD_EXECUTABLE(test1 gtest_main.cc TChineseFilter.cpp)
|
||||
TARGET_LINK_LIBRARIES(gtest pthread)
|
||||
TARGET_LINK_LIBRARIES(test1 gtest pthread)
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
#include "../src/ChineseFilter.hpp"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
//ChineseFilter chFilter;
|
||||
ifstream ifs(argv[1]);
|
||||
string line;
|
||||
string s;
|
||||
while(getline(ifs, line))
|
||||
{
|
||||
const char * str = line.c_str();
|
||||
uint size = line.size();
|
||||
uint offset = 0;
|
||||
while(offset < size)
|
||||
{
|
||||
uint len;
|
||||
const char* t = str+offset;
|
||||
int ret = filterAscii(t, size, len);
|
||||
s.assign(t, len);
|
||||
cout<<s<<","<<ret<<","<<len<<endl;
|
||||
offset += len;
|
||||
}
|
||||
|
||||
|
||||
//chFilter.feed(line);
|
||||
//for(ChineseFilter::iterator it = chFilter.begin(); it != chFilter.end(); it++)
|
||||
//{
|
||||
// //cout<<__FILE__<<__LINE__<<endl;
|
||||
// string tmp;
|
||||
// TransCode::encode(it.begin, it.end, tmp);
|
||||
// cout<<tmp<<endl;
|
||||
//}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
36
test/unittest/TChineseFilter.cpp
Normal file
36
test/unittest/TChineseFilter.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "src/ChineseFilter.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
TEST(ChineseFilterTest, Test1)
|
||||
{
|
||||
const char* str = "heheh你好...hh";
|
||||
string s;
|
||||
vector<string> buf;
|
||||
buf.push_back("heheh");
|
||||
buf.push_back("你好");
|
||||
buf.push_back("...hh");
|
||||
vector<string> res;
|
||||
uint size = strlen(str);
|
||||
uint offset = 0;
|
||||
while(offset < size)
|
||||
{
|
||||
uint len;
|
||||
const char* t = str + offset;
|
||||
int ret = filterAscii(t, size - offset, len);
|
||||
s.assign(t, len);
|
||||
res.push_back(s);
|
||||
//cout<<s<<","<<ret<<","<<len<<endl;
|
||||
//cout<<str<<endl;
|
||||
offset += len;
|
||||
}
|
||||
EXPECT_EQ(res, buf);
|
||||
}
|
||||
|
||||
//int main(int argc, char** argv)
|
||||
//{
|
||||
// //ChineseFilter chFilter;
|
||||
// return 0;
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user