[Groonga-commit] groonga/grnxx [master] Add tests for lcp_search().

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Mon Feb 18 14:50:54 JST 2013


susumu.yata	2013-02-18 14:50:54 +0900 (Mon, 18 Feb 2013)

  New Revision: 37b9ef892def3e90559d214a88394d4a89ff88d7
  https://github.com/groonga/grnxx/commit/37b9ef892def3e90559d214a88394d4a89ff88d7

  Log:
    Add tests for lcp_search().

  Modified files:
    test/test_map.cpp
    test/test_map_da_basic_trie.cpp
    test/test_map_double_array.cpp

  Modified: test/test_map.cpp (+43 -8)
===================================================================
--- test/test_map.cpp    2013-02-18 14:44:22 +0900 (6f190cc)
+++ test/test_map.cpp    2013-02-18 14:50:54 +0900 (bf25408)
@@ -31,8 +31,7 @@ void test_basics() {
 
   grnxx::MapOptions options;
   options.type = grnxx::MAP_DOUBLE_ARRAY;
-  std::unique_ptr<grnxx::Map> map(
-      grnxx::Map::create(options, pool));
+  std::unique_ptr<grnxx::Map> map(grnxx::Map::create(options, pool));
 
   std::vector<grnxx::Slice> keys;
   keys.push_back("apple");
@@ -90,6 +89,44 @@ void test_basics() {
   }
 }
 
+void test_lcp_search() {
+  grnxx::io::Pool pool;
+  pool.open(grnxx::io::POOL_TEMPORARY);
+
+  grnxx::MapOptions options;
+  options.type = grnxx::MAP_DOUBLE_ARRAY;
+  std::unique_ptr<grnxx::Map> map(grnxx::Map::create(options, pool));
+
+  assert(map->insert("AB"));
+  assert(map->insert("ABCD"));
+  assert(map->insert("ABE"));
+
+  std::int64_t key_id;
+  grnxx::Slice key;
+
+  assert(!map->lcp_search("", &key_id, &key));
+  assert(!map->lcp_search("A", &key_id, &key));
+  assert(map->lcp_search("AB", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(map->lcp_search("ABC", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(map->lcp_search("ABCD", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(map->lcp_search("ABCDE", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(map->lcp_search("ABE", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(map->lcp_search("ABEF", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(!map->lcp_search("BCD", &key_id, &key));
+}
+
 void create_keys(std::size_t num_keys,
                  std::size_t min_size, std::size_t max_size,
                  std::unordered_set<std::string> *both_keys,
@@ -129,8 +166,7 @@ void test_insert() {
 
   grnxx::MapOptions options;
   options.type = grnxx::MAP_DOUBLE_ARRAY;
-  std::unique_ptr<grnxx::Map> map(
-      grnxx::Map::create(options, pool));
+  std::unique_ptr<grnxx::Map> map(grnxx::Map::create(options, pool));
 
   std::unordered_set<std::string> both_keys;
   std::vector<grnxx::Slice> true_keys;
@@ -171,8 +207,7 @@ void test_remove() {
 
   grnxx::MapOptions options;
   options.type = grnxx::MAP_DOUBLE_ARRAY;
-  std::unique_ptr<grnxx::Map> map(
-      grnxx::Map::create(options, pool));
+  std::unique_ptr<grnxx::Map> map(grnxx::Map::create(options, pool));
 
   std::unordered_set<std::string> both_keys;
   std::vector<grnxx::Slice> true_keys;
@@ -228,8 +263,7 @@ void test_update() {
 
   grnxx::MapOptions options;
   options.type = grnxx::MAP_DOUBLE_ARRAY;
-  std::unique_ptr<grnxx::Map> map(
-      grnxx::Map::create(options, pool));
+  std::unique_ptr<grnxx::Map> map(grnxx::Map::create(options, pool));
 
   std::unordered_set<std::string> both_keys;
   std::vector<grnxx::Slice> true_keys;
@@ -270,6 +304,7 @@ int main() {
   grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
 
   test_basics();
+  test_lcp_search();
 
   test_insert();
   test_remove();

  Modified: test/test_map_da_basic_trie.cpp (+39 -0)
===================================================================
--- test/test_map_da_basic_trie.cpp    2013-02-18 14:44:22 +0900 (92f4374)
+++ test/test_map_da_basic_trie.cpp    2013-02-18 14:50:54 +0900 (c069fc9)
@@ -89,6 +89,44 @@ void test_basics() {
   }
 }
 
+void test_lcp_search() {
+  grnxx::io::Pool pool;
+  pool.open(grnxx::io::POOL_TEMPORARY);
+
+  grnxx::map::da::TrieOptions options;
+  std::unique_ptr<grnxx::map::da::basic::Trie> trie(
+      grnxx::map::da::basic::Trie::create(options, pool));
+
+  assert(trie->insert("AB"));
+  assert(trie->insert("ABCD"));
+  assert(trie->insert("ABE"));
+
+  std::int64_t key_id;
+  grnxx::Slice key;
+
+  assert(!trie->lcp_search("", &key_id, &key));
+  assert(!trie->lcp_search("A", &key_id, &key));
+  assert(trie->lcp_search("AB", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(trie->lcp_search("ABC", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(trie->lcp_search("ABCD", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(trie->lcp_search("ABCDE", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(trie->lcp_search("ABE", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(trie->lcp_search("ABEF", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(!trie->lcp_search("BCD", &key_id, &key));
+}
+
 void create_keys(std::size_t num_keys,
                  std::size_t min_size, std::size_t max_size,
                  std::unordered_set<std::string> *both_keys,
@@ -313,6 +351,7 @@ int main() {
   grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
 
   test_basics();
+  test_lcp_search();
 
   test_insert();
   test_remove();

  Modified: test/test_map_double_array.cpp (+39 -0)
===================================================================
--- test/test_map_double_array.cpp    2013-02-18 14:44:22 +0900 (9ed99b5)
+++ test/test_map_double_array.cpp    2013-02-18 14:50:54 +0900 (c733ea8)
@@ -89,6 +89,44 @@ void test_basics() {
   }
 }
 
+void test_lcp_search() {
+  grnxx::io::Pool pool;
+  pool.open(grnxx::io::POOL_TEMPORARY);
+
+  grnxx::MapOptions options;
+  std::unique_ptr<grnxx::map::DoubleArray> da(
+      grnxx::map::DoubleArray::create(options, pool));
+
+  assert(da->insert("AB"));
+  assert(da->insert("ABCD"));
+  assert(da->insert("ABE"));
+
+  std::int64_t key_id;
+  grnxx::Slice key;
+
+  assert(!da->lcp_search("", &key_id, &key));
+  assert(!da->lcp_search("A", &key_id, &key));
+  assert(da->lcp_search("AB", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(da->lcp_search("ABC", &key_id, &key));
+  assert(key_id == 0);
+  assert(key == "AB");
+  assert(da->lcp_search("ABCD", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(da->lcp_search("ABCDE", &key_id, &key));
+  assert(key_id == 1);
+  assert(key == "ABCD");
+  assert(da->lcp_search("ABE", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(da->lcp_search("ABEF", &key_id, &key));
+  assert(key_id == 2);
+  assert(key == "ABE");
+  assert(!da->lcp_search("BCD", &key_id, &key));
+}
+
 void create_keys(std::size_t num_keys,
                  std::size_t min_size, std::size_t max_size,
                  std::unordered_set<std::string> *both_keys,
@@ -266,6 +304,7 @@ int main() {
   grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
 
   test_basics();
+  test_lcp_search();
 
   test_insert();
   test_remove();
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る