[Groonga-commit] groonga/grnxx [master] Update tests.

Back to archive index

susumu.yata null+****@clear*****
Fri Mar 15 13:20:05 JST 2013


susumu.yata	2013-03-15 13:20:05 +0900 (Fri, 15 Mar 2013)

  New Revision: d5b325583c7be9cb759f428809d2d10d4ab86f90
  https://github.com/groonga/grnxx/commit/d5b325583c7be9cb759f428809d2d10d4ab86f90

  Message:
    Update tests.

  Modified files:
    test/test_map_da_basic_trie.cpp
    test/test_map_da_large_trie.cpp

  Modified: test/test_map_da_basic_trie.cpp (+80 -1)
===================================================================
--- test/test_map_da_basic_trie.cpp    2013-03-15 13:18:55 +0900 (7e1f995)
+++ test/test_map_da_basic_trie.cpp    2013-03-15 13:20:05 +0900 (9c357e1)
@@ -21,7 +21,8 @@
 #include <unordered_set>
 #include <vector>
 
-#include "map/da/basic_trie.hpp"
+#include "map/da/basic/id_cursor.hpp"
+#include "map/da/basic/trie.hpp"
 #include "logger.hpp"
 #include "time/time.hpp"
 
@@ -348,6 +349,82 @@ void test_defrag() {
   }
 }
 
+void test_id_cursor() {
+  constexpr std::size_t NUM_KEYS = 1 << 12;
+  constexpr std::size_t MIN_SIZE = 1;
+  constexpr std::size_t MAX_SIZE = 10;
+
+  std::mt19937 random;
+
+  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));
+
+  std::unordered_set<std::string> both_keys;
+  std::vector<grnxx::Slice> true_keys;
+  std::vector<grnxx::Slice> false_keys;
+  create_keys(NUM_KEYS, MIN_SIZE, MAX_SIZE,
+              &both_keys, &true_keys, &false_keys);
+
+  for (std::size_t i = 0; i < NUM_KEYS; ++i) {
+    std::int64_t key_id;
+    assert(trie->insert(true_keys[i], &key_id));
+    assert(key_id == static_cast<std::int64_t>(i));
+  }
+
+  std::unique_ptr<grnxx::MapCursor> cursor(
+      grnxx::map::da::basic::IDCursor::open(
+          trie.get(), grnxx::MapCursorFlags(), 0, -1, 0, -1));
+  for (std::size_t i = 0; i < NUM_KEYS; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == static_cast<std::int64_t>(i));
+    assert(cursor->key() == true_keys[i]);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(grnxx::map::da::basic::IDCursor::open(
+      trie.get(), grnxx::MapCursorFlags(), 0, -1, NUM_KEYS / 2, -1));
+  for (std::size_t i = NUM_KEYS / 2; i < NUM_KEYS; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == static_cast<std::int64_t>(i));
+    assert(cursor->key() == true_keys[i]);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(grnxx::map::da::basic::IDCursor::open(
+      trie.get(), grnxx::MapCursorFlags(), 0, -1, 0, NUM_KEYS / 2));
+  for (std::size_t i = 0; i < NUM_KEYS / 2; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == static_cast<std::int64_t>(i));
+    assert(cursor->key() == true_keys[i]);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(grnxx::map::da::basic::IDCursor::open(
+      trie.get(), grnxx::MAP_CURSOR_DESCENDING, 0, -1, 0, -1));
+  for (std::size_t i = 0; i < NUM_KEYS; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == static_cast<std::int64_t>(NUM_KEYS - i - 1));
+    assert(cursor->key() == true_keys[NUM_KEYS - i - 1]);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(grnxx::map::da::basic::IDCursor::open(
+      trie.get(), grnxx::MAP_CURSOR_EXCEPT_MIN, 0, 1, 0, -1));
+  assert(cursor->next());
+  assert(cursor->key_id() == 1);
+  assert(!cursor->next());
+
+  cursor.reset(grnxx::map::da::basic::IDCursor::open(
+      trie.get(), grnxx::MAP_CURSOR_EXCEPT_MAX, 2, 3, 0, -1));
+  assert(cursor->next());
+  assert(cursor->key_id() == 2);
+  assert(!cursor->next());
+}
+
 int main() {
   grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
                            grnxx::LOGGER_ENABLE_COUT);
@@ -362,5 +439,7 @@ int main() {
 
   test_defrag();
 
+  test_id_cursor();
+
   return 0;
 }

  Modified: test/test_map_da_large_trie.cpp (+1 -1)
===================================================================
--- test/test_map_da_large_trie.cpp    2013-03-15 13:18:55 +0900 (e0b5fc0)
+++ test/test_map_da_large_trie.cpp    2013-03-15 13:20:05 +0900 (864e2b6)
@@ -21,7 +21,7 @@
 #include <unordered_set>
 #include <vector>
 
-#include "map/da/large_trie.hpp"
+#include "map/da/large/trie.hpp"
 #include "logger.hpp"
 #include "time/time.hpp"
 
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index