summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-06-01 13:50:02 +0800
committerPeng Wu <alexepico@gmail.com>2016-06-01 13:50:02 +0800
commit27ec333e65de3fc881f9e62ae9c622353a0b173e (patch)
tree1260031a64d1e7aa6d107e0e7f2a161603e88776 /tests
parentb735c7d1074fb8234f555c34739d3979a5e2e3fe (diff)
downloadlibpinyin-27ec333e65de3fc881f9e62ae9c622353a0b173e.zip
libpinyin-27ec333e65de3fc881f9e62ae9c622353a0b173e.tar.gz
libpinyin-27ec333e65de3fc881f9e62ae9c622353a0b173e.tar.xz
update test_matrix.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/storage/test_matrix.cpp56
-rw-r--r--tests/tests_helper.h4
2 files changed, 57 insertions, 3 deletions
diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp
index 3c63902..d80b030 100644
--- a/tests/storage/test_matrix.cpp
+++ b/tests/storage/test_matrix.cpp
@@ -28,6 +28,57 @@ size_t bench_times = 1000;
using namespace pinyin;
+bool test_pronunciation_possibility(PhoneticKeyMatrix * matrix,
+ size_t start, size_t end,
+ FacadePhraseIndex * phrase_index,
+ PhraseIndexRanges ranges) {
+ GArray * cached_keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey));
+
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ GArray * & range = ranges[i];
+ if (!range)
+ continue;
+
+ if (range->len)
+ printf("range items number:%d\n", range->len);
+
+
+ for (size_t k = 0; k < range->len; ++k) {
+ PhraseIndexRange * onerange =
+ &g_array_index(range, PhraseIndexRange, k);
+ printf("start:%d\tend:%d\n", onerange->m_range_begin,
+ onerange->m_range_end);
+
+ PhraseItem item;
+ for (phrase_token_t token = onerange->m_range_begin;
+ token != onerange->m_range_end; ++token){
+
+ phrase_index->get_phrase_item(token, item);
+
+ gfloat origin = compute_pronunciation_possibility
+ (matrix, start, end, cached_keys, item);
+
+ bool increased = increase_pronunciation_possibility
+ (matrix, start, end, cached_keys, item, 30);
+
+ gfloat updated = compute_pronunciation_possibility
+ (matrix, start, end, cached_keys, item);
+
+ if (increased) {
+ printf("origin:%f\t updated:%f\n", origin, updated);
+ } else {
+ assert(origin == updated);
+ printf("origin:%f\n", origin);
+ }
+ }
+ }
+
+ }
+
+ g_array_free(cached_keys, TRUE);
+ return true;
+}
+
int main(int argc, char * argv[]) {
SystemTableInfo2 system_table_info;
@@ -101,8 +152,11 @@ int main(int argc, char * argv[]) {
int retval = search_matrix(&largetable, &matrix, i, j, ranges);
#if 0
- if (retval & SEARCH_OK)
+ if (retval & SEARCH_OK) {
dump_ranges(&phrase_index, ranges);
+ test_pronunciation_possibility
+ (&matrix, i, j, &phrase_index, ranges);
+ }
#endif
if (!(retval & SEARCH_CONTINUED))
diff --git a/tests/tests_helper.h b/tests/tests_helper.h
index 995d8c1..d143975 100644
--- a/tests/tests_helper.h
+++ b/tests/tests_helper.h
@@ -101,10 +101,10 @@ inline bool dump_ranges(FacadePhraseIndex * phrase_index,
onerange->m_range_end);
PhraseItem item;
- for ( phrase_token_t token = onerange->m_range_begin;
+ for (phrase_token_t token = onerange->m_range_begin;
token != onerange->m_range_end; ++token){
- phrase_index->get_phrase_item( token, item);
+ phrase_index->get_phrase_item(token, item);
/* get phrase string */
ucs4_t buffer[MAX_PHRASE_LENGTH + 1];