From 82cbc78740e1bf34514137eddba58fa16e9788ac Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 2 Sep 2010 14:32:27 +0800 Subject: add test case for phrase table --- tests/storage/test_phrase_table.cpp | 26 ++++++++++++++++++++++++++ tests/storage/test_pinyin_index.cpp | 8 +++++--- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp index 691b1dc..08d1626 100644 --- a/tests/storage/test_phrase_table.cpp +++ b/tests/storage/test_phrase_table.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "novel_types.h" @@ -44,5 +45,30 @@ int main(int argc, char * argv[]){ largetable.load_text(gbkfile); fclose(gbkfile); + char * linebuf = NULL; + size_t size = 0; + while( getline(&linebuf, &size, stdin) ){ + linebuf[strlen(linebuf) - 1] = '\0'; + if ( strcmp ( linebuf, "quit" ) == 0) + break; + glong phrase_len = g_utf8_strlen(linebuf, -1); + utf16_t * new_phrase = g_utf8_to_utf16(linebuf, -1, NULL, NULL, NULL); + phrase_token_t token; + + guint32 start = record_time(); + for ( int i = 0; i < bench_times; ++i){ + largetable.search(phrase_len, new_phrase, token); + } + print_time(start, bench_times); + + largetable.search(phrase_len, new_phrase, token); + printf("%s:\t%d\n", linebuf, token); + + g_free(new_phrase); + } + + if ( linebuf ) + free(linebuf); + return 0; } diff --git a/tests/storage/test_pinyin_index.cpp b/tests/storage/test_pinyin_index.cpp index ab30dfd..d9a5abf 100644 --- a/tests/storage/test_pinyin_index.cpp +++ b/tests/storage/test_pinyin_index.cpp @@ -74,8 +74,8 @@ int main( int argc, char * argv[]){ largetable.store(new_chunk); largetable.load(new_chunk); - char* linebuf = (char *)malloc ( 1024 * sizeof (char) ); - size_t size = 1024; + char* linebuf = NULL; + size_t size = 0; while( getline(&linebuf, &size, stdin) ){ linebuf[strlen(linebuf)-1] = '\0'; if ( strcmp ( linebuf, "quit" ) == 0) @@ -145,5 +145,7 @@ int main( int argc, char * argv[]){ g_array_free(keys, TRUE); g_array_free(poses, TRUE); } - free(linebuf); + if (linebuf) + free(linebuf); + return 0; } -- cgit