From 29e085904dd61f9fc54f84547cb23a03dc6168f7 Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Mon, 18 Apr 2016 14:55:42 +0800 Subject: [PATCH] add log and unittest --- include/cppjieba/PreFilter.hpp | 2 +- test/unittest/segments_test.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/cppjieba/PreFilter.hpp b/include/cppjieba/PreFilter.hpp index 7d6bdee..ecb81c0 100644 --- a/include/cppjieba/PreFilter.hpp +++ b/include/cppjieba/PreFilter.hpp @@ -18,7 +18,7 @@ class PreFilter { const string& sentence) : symbols_(symbols) { if (!DecodeRunesInString(sentence, sentence_)) { - XLOG(ERROR) << "decode string: " << sentence << " failed"; + XLOG(ERROR) << "decode failed. "; } cursor_ = sentence_.begin(); } diff --git a/test/unittest/segments_test.cpp b/test/unittest/segments_test.cpp index ccb065a..66eafef 100644 --- a/test/unittest/segments_test.cpp +++ b/test/unittest/segments_test.cpp @@ -103,6 +103,23 @@ TEST(MixSegmentTest, TestUserDict) { segment.Cut("忽如一夜春风来,千树万树梨花开", words); res = limonp::Join(words.begin(), words.end(), "/"); ASSERT_EQ("忽如一夜春风来/,/千树/万树/梨花/开", res); + + // rand input + { + const size_t ITERATION = 16; + const size_t MAX_LEN = 256; + string s; + srand(time(NULL)); + + for (size_t i = 0; i < ITERATION; i++) { + size_t len = rand() % MAX_LEN; + s.resize(len); + for (size_t j = 0; j < len; j++) { + s[rand() % len] = rand(); + } + segment.Cut(s, words); + } + } } TEST(MixSegmentTest, TestMultiUserDict) {