diff options
author | Peng Wu <alexepico@gmail.com> | 2011-08-22 18:23:12 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-08-22 18:37:35 +0800 |
commit | 806ee677ed908de317f0bbf377279d2083dce731 (patch) | |
tree | 8ff0e588fb086cc29d7adf1fa2e38e861055ca5e /tests/storage | |
parent | fe1980851c95afa18300c5cf9d8bbda842b784d2 (diff) | |
download | libpinyin-806ee677ed908de317f0bbf377279d2083dce731.tar.gz libpinyin-806ee677ed908de317f0bbf377279d2083dce731.tar.xz libpinyin-806ee677ed908de317f0bbf377279d2083dce731.zip |
write test case for phrase index logger
Diffstat (limited to 'tests/storage')
-rw-r--r-- | tests/storage/test_phrase_index_logger.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/storage/test_phrase_index_logger.cpp b/tests/storage/test_phrase_index_logger.cpp index 4248db4..965d2c6 100644 --- a/tests/storage/test_phrase_index_logger.cpp +++ b/tests/storage/test_phrase_index_logger.cpp @@ -22,7 +22,46 @@ #include "pinyin.h" +/* TODO: check whether gb_char.bin and gb_char2.bin should be the same. */ + int main(int argc, char * argv[]){ - + FacadePhraseIndex phrase_index; + MemoryChunk * chunk = new MemoryChunk; + chunk->load("../../data/gb_char.bin"); + phrase_index.load(1, chunk); + + PhraseIndexRange range; + phrase_index.get_range(1, range); + for (size_t i = range.m_range_begin; i < range.m_range_end; ++i ) { + phrase_index.add_unigram_frequency(i, 1); + } + + printf("total freq:%d\n", phrase_index.get_phrase_index_total_freq()); + + MemoryChunk * new_chunk = new MemoryChunk; + phrase_index.store(1, new_chunk); + new_chunk->save("/tmp/gb_char.bin"); + delete new_chunk; + + chunk = new MemoryChunk; + chunk->load("../../data/gb_char.bin"); + new_chunk = new MemoryChunk; + phrase_index.diff(1, chunk, new_chunk); + new_chunk->save("/tmp/gb_char.dbin"); + delete new_chunk; + + chunk = new MemoryChunk; + chunk->load("../../data/gb_char.bin"); + phrase_index.load(1, chunk); + new_chunk = new MemoryChunk; + new_chunk->load("/tmp/gb_char.dbin"); + phrase_index.merge(1, new_chunk); + chunk = new MemoryChunk; + phrase_index.store(1, chunk); + chunk->save("/tmp/gb_char2.bin"); + delete chunk; + + printf("total freq:%d\n", phrase_index.get_phrase_index_total_freq()); + return 0; } |