summaryrefslogtreecommitdiffstats
path: root/tests/storage/test_ngram.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-04-18 14:37:21 +0800
committerPeng Wu <alexepico@gmail.com>2011-04-18 14:37:21 +0800
commit643bbc2a749f9a37a915c9daedaf544478711e42 (patch)
tree7fbd4b74e8a5e5ffd13cc0f993917ce8be530113 /tests/storage/test_ngram.cpp
parentd91242f6b9577c1eeef98929c8420e1bcd18e6ec (diff)
downloadlibpinyin-643bbc2a749f9a37a915c9daedaf544478711e42.tar.gz
libpinyin-643bbc2a749f9a37a915c9daedaf544478711e42.tar.xz
libpinyin-643bbc2a749f9a37a915c9daedaf544478711e42.zip
refine insert/set freq
Diffstat (limited to 'tests/storage/test_ngram.cpp')
-rw-r--r--tests/storage/test_ngram.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/tests/storage/test_ngram.cpp b/tests/storage/test_ngram.cpp
index 1dd65a8..841a0f4 100644
--- a/tests/storage/test_ngram.cpp
+++ b/tests/storage/test_ngram.cpp
@@ -7,16 +7,19 @@ int main(int argc, char * argv[]){
const guint32 total_freq = 16;
assert(single_gram.set_total_freq(total_freq));
-
phrase_token_t tokens[6] = { 2, 6, 4, 3, 1, 3};
guint32 freqs[6] = { 1, 2, 4, 8, 16, 32};
+ guint32 freq;
+
for(size_t i = 0; i < 6 ;++i){
- single_gram.set_freq(tokens[i], freqs[i]);
+ if ( single_gram.get_freq(tokens[i], freq))
+ single_gram.set_freq(tokens[i], freqs[i]);
+ else
+ single_gram.insert_freq(tokens[i], freqs[i]);
}
- guint32 freq;
single_gram.get_freq(3, freq);
assert(freq == 32);
@@ -38,7 +41,7 @@ int main(int argc, char * argv[]){
Bigram bigram;
assert(bigram.attach(NULL, "/tmp/system.db"));
bigram.store(1, &single_gram);
- single_gram.set_freq(5, 8);
+ assert(single_gram.insert_freq(5, 8));
single_gram.set_total_freq(32);
bigram.store(2, &single_gram);