diff options
author | Peng Wu <alexepico@gmail.com> | 2016-05-11 16:15:01 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-05-11 16:15:01 +0800 |
commit | 0d1aaf9cb0f4b53114422618cb61510560f4611d (patch) | |
tree | 9e6d23653650d87149a0525a029da9ae352f534c | |
parent | f76adc9bdd2235166819494f14d689dbcbc911ae (diff) | |
download | libpinyin-0d1aaf9cb0f4b53114422618cb61510560f4611d.tar.gz |
add test_matrix.cpp
-rw-r--r-- | src/storage/phonetic_key_matrix.cpp | 3 | ||||
-rw-r--r-- | tests/storage/test_matrix.cpp | 76 | ||||
-rw-r--r-- | tests/storage/test_parser2.cpp | 3 |
3 files changed, 78 insertions, 4 deletions
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp index 1f5b8ea..b0b69f9 100644 --- a/src/storage/phonetic_key_matrix.cpp +++ b/src/storage/phonetic_key_matrix.cpp @@ -79,11 +79,10 @@ bool dump_phonetic_key_matrix(PhoneticKeyMatrix * matrix) { for (size_t index = 0; index < length; ++index) { matrix->get_items(index, keys, key_rests); + assert(keys->len == key_rests->len); printf("Column:%ld:\n", index); - assert(keys->len == key_rests->len); - for (size_t i = 0; i < keys->len; ++i) { ChewingKey * key = &g_array_index(keys, ChewingKey, i); ChewingKeyRest * key_rest = &g_array_index(key_rests, diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp new file mode 100644 index 0000000..ba9b3e0 --- /dev/null +++ b/tests/storage/test_matrix.cpp @@ -0,0 +1,76 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2016 Peng Wu <alexepico@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "timer.h" +#include <stdlib.h> +#include "pinyin_internal.h" + + +using namespace pinyin; + +int main(int argc, char * argv[]) { + pinyin_option_t options = PINYIN_CORRECT_ALL; + options |= PINYIN_INCOMPLETE; + + PhoneticParser2 * parser = FullPinyinParser2(); + ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); + ChewingKeyRestVector key_rests = + g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); + + PhoneticKeyMatrix matrix; + + char* linebuf = NULL; size_t size = 0; ssize_t read; + while( (read = getline(&linebuf, &size, stdin)) != -1 ){ + if ( '\n' == linebuf[strlen(linebuf) - 1] ) { + linebuf[strlen(linebuf) - 1] = '\0'; + } + + if ( strcmp ( linebuf, "quit" ) == 0) + break; + + int len = 0; + guint32 start_time = record_time(); + for (size_t i = 0; i < bench_times; ++i) { + matrix.clear_all(); + + len = parser->parse(options, keys, key_rests, + linebuf, strlen(linebuf)); + + fill_phonetic_key_matrix_from_chewing_keys + (&matrix, keys, key_rests); + } + print_time(start_time, bench_times); + + printf("parsed %d chars, %d keys.\n", len, keys->len); + + dump_phonetic_key_matrix(&matrix); + } + + if (linebuf) + free(linebuf); + + delete parser; + + g_array_free(key_rests, TRUE); + g_array_free(keys, TRUE); + + return 0; +} diff --git a/tests/storage/test_parser2.cpp b/tests/storage/test_parser2.cpp index 8427ae8..b0a1787 100644 --- a/tests/storage/test_parser2.cpp +++ b/tests/storage/test_parser2.cpp @@ -26,8 +26,7 @@ #include <assert.h> #include <stdlib.h> #include <string.h> -#include "pinyin_parser2.h" -#include "zhuyin_parser2.h" +#include "pinyin_internal.h" static const gchar * parsername = ""; |