add more test cases for n-gram
authorPeng Wu <alexepico@gmail.com>
Mon, 18 Apr 2011 07:46:15 +0000 (15:46 +0800)
committerPeng Wu <alexepico@gmail.com>
Mon, 18 Apr 2011 07:46:15 +0000 (15:46 +0800)
tests/storage/test_flexible_ngram.cpp
tests/storage/test_ngram.cpp

index e8f6a9b2bcfc0b9ee4935d8b656afeb922a6a3a3..eefb5acb3ca163d34d582f227cff153de78df77f 100644 (file)
@@ -10,11 +10,15 @@ int main(int argc, char * argv[]) {
     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_array_item(tokens[i], freqs[i]);
+        if ( single_gram.get_array_item(tokens[i], freq) )
+            assert(single_gram.set_array_item(tokens[i], freqs[i]));
+        else
+            assert(single_gram.insert_array_item(tokens[i], freqs[i]));
     }
 
-    guint32 freq;
     single_gram.get_array_item(3, freq);
     assert(freq == 32);
 
@@ -34,9 +38,9 @@ int main(int argc, char * argv[]) {
     FlexibleBigram<guint32, guint32, guint32> bigram;
     assert(bigram.attach("/tmp/training.db"));
     bigram.store(1, &single_gram);
-    single_gram.set_array_item(5, 8);
-    single_gram.set_array_header(32);
-    single_gram.get_array_header(freq);
+    assert(single_gram.insert_array_item(5, 8));
+    assert(single_gram.set_array_header(32));
+    assert(single_gram.get_array_header(freq));
     printf("new array header:%d\n", freq);
     bigram.store(2, &single_gram);
 
index 841a0f42287471be0be4d8ff3f00fde36cd12901..b93a55df9630cc6df270f0242da78b897b72f268 100644 (file)
@@ -15,9 +15,9 @@ int main(int argc, char * argv[]){
 
     for(size_t i = 0; i < 6 ;++i){
         if ( single_gram.get_freq(tokens[i], freq))
-            single_gram.set_freq(tokens[i], freqs[i]);
+            assert(single_gram.set_freq(tokens[i], freqs[i]));
         else
-            single_gram.insert_freq(tokens[i], freqs[i]);
+            assert(single_gram.insert_freq(tokens[i], freqs[i]));
     }
 
     single_gram.get_freq(3, freq);