[Groonga-commit] groonga/grnxx at 26f8f9c [master] Add tests for the new interface to create a cursor.

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Mon May 6 16:18:57 JST 2013


susumu.yata	2013-05-06 16:18:57 +0900 (Mon, 06 May 2013)

  New Revision: 26f8f9c8296e7d44edc5e9137a99718c1fd5fd64
  https://github.com/groonga/grnxx/commit/26f8f9c8296e7d44edc5e9137a99718c1fd5fd64

  Message:
    Add tests for the new interface to create a cursor.

  Modified files:
    test/test_alpha_map.cpp

  Modified: test/test_alpha_map.cpp (+148 -1)
===================================================================
--- test/test_alpha_map.cpp    2013-05-06 16:18:38 +0900 (7fe4577)
+++ test/test_alpha_map.cpp    2013-05-06 16:18:57 +0900 (cd36c3c)
@@ -189,6 +189,37 @@ void test_id_cursor(const std::unique_ptr<Map<T>> &map,
   }
   assert(!cursor->next());
 
+  cursor.reset(map->open_cursor((map->id() >= MIN_ID) && (map->id() <= MAX_ID),
+                                options));
+  for (std::int64_t i = MIN_ID; i <= MAX_ID; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    T key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(map->open_cursor(MIN_ID <= map->id(), options));
+  for (std::int64_t i = MIN_ID; i < static_cast<std::int64_t>(MAP_SIZE); ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    T key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(map->open_cursor(map->id() <= MAX_ID, options));
+  for (std::int64_t i = 0; i <= MAX_ID; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    T key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
   options.flags |= grnxx::alpha::MAP_CURSOR_EXCEPT_MIN |
                    grnxx::alpha::MAP_CURSOR_EXCEPT_MAX;
   cursor.reset(map->open_id_cursor(MIN_ID, MAX_ID, options));
@@ -201,6 +232,17 @@ void test_id_cursor(const std::unique_ptr<Map<T>> &map,
   }
   assert(!cursor->next());
 
+  cursor.reset(map->open_cursor((MIN_ID < map->id()) && (map->id() < MAX_ID),
+                                options));
+  for (std::int64_t i = MIN_ID + 1; i <= (MAX_ID - 1); ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    T key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
   options.flags = grnxx::alpha::MAP_CURSOR_ORDER_BY_KEY;
   cursor.reset(map->open_id_cursor(MIN_ID, MAX_ID, options));
   assert(cursor->next());
@@ -211,6 +253,17 @@ void test_id_cursor(const std::unique_ptr<Map<T>> &map,
     prev_key = cursor->key();
   }
   assert(!cursor->next());
+
+  cursor.reset(map->open_cursor((MAX_ID >= map->id()) && (MIN_ID <= map->id()),
+                                options));
+  assert(cursor->next());
+  prev_key = cursor->key();
+  for (std::int64_t i = MIN_ID + 1; i <= MAX_ID; ++i) {
+    assert(cursor->next());
+    assert(prev_key < cursor->key());
+    prev_key = cursor->key();
+  }
+  assert(!cursor->next());
 }
 
 template <>
@@ -232,6 +285,37 @@ void test_id_cursor(const std::unique_ptr<Map<grnxx::GeoPoint>> &map,
   }
   assert(!cursor->next());
 
+  cursor.reset(map->open_cursor((map->id() >= MIN_ID) && (map->id() <= MAX_ID),
+                                options));
+  for (std::int64_t i = MIN_ID; i <= MAX_ID; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    grnxx::GeoPoint key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(map->open_cursor(MIN_ID <= map->id(), options));
+  for (std::int64_t i = MIN_ID; i < static_cast<std::int64_t>(MAP_SIZE); ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    grnxx::GeoPoint key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
+  cursor.reset(map->open_cursor(map->id() <= MAX_ID, options));
+  for (std::int64_t i = 0; i <= MAX_ID; ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    grnxx::GeoPoint key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
+
   options.flags |= grnxx::alpha::MAP_CURSOR_EXCEPT_MIN |
                    grnxx::alpha::MAP_CURSOR_EXCEPT_MAX;
   cursor.reset(map->open_id_cursor(MIN_ID, MAX_ID, options));
@@ -243,6 +327,17 @@ void test_id_cursor(const std::unique_ptr<Map<grnxx::GeoPoint>> &map,
     assert(cursor->key() == key);
   }
   assert(!cursor->next());
+
+  cursor.reset(map->open_cursor((MIN_ID < map->id()) && (map->id() < MAX_ID),
+                                options));
+  for (std::int64_t i = MIN_ID + 1; i <= (MAX_ID - 1); ++i) {
+    assert(cursor->next());
+    assert(cursor->key_id() == i);
+    grnxx::GeoPoint key;
+    assert(map->get(i, &key));
+    assert(cursor->key() == key);
+  }
+  assert(!cursor->next());
 }
 
 template <typename T>
@@ -264,11 +359,33 @@ void test_key_cursor(const std::unique_ptr<Map<T>> &map) {
   }
   assert(!cursor->next());
 
+  cursor.reset(map->open_cursor((map->key() >= min_key) &&
+                                (map->key() <=max_key)));
+  size_t count = 0;
+  while (cursor->next()) {
+    assert(cursor->key() >= min_key);
+    assert(cursor->key() <= max_key);
+    ++count;
+  }
+  assert(!cursor->next());
+  assert(count == basic_count);
+
   grnxx::alpha::MapCursorOptions options;
   options.flags = grnxx::alpha::MAP_CURSOR_EXCEPT_MIN |
                   grnxx::alpha::MAP_CURSOR_EXCEPT_MAX;
   cursor.reset(map->open_key_cursor(min_key, max_key, options));
-  size_t count = 0;
+  count = 0;
+  while (cursor->next()) {
+    assert(cursor->key() > min_key);
+    assert(cursor->key() < max_key);
+    ++count;
+  }
+  assert(!cursor->next());
+  assert(count <= basic_count);
+
+  cursor.reset(map->open_cursor((min_key < map->key()) &&
+                                (max_key > map->key()), options));
+  count = 0;
   while (cursor->next()) {
     assert(cursor->key() > min_key);
     assert(cursor->key() < max_key);
@@ -288,6 +405,17 @@ void test_key_cursor(const std::unique_ptr<Map<T>> &map) {
   assert(!cursor->next());
   assert(count == basic_count);
 
+  cursor.reset(map->open_cursor((map->key() >= min_key) &&
+                                (map->key() <= max_key), options));
+  count = 0;
+  while (cursor->next()) {
+    assert(cursor->key() >= min_key);
+    assert(cursor->key() <= max_key);
+    ++count;
+  }
+  assert(!cursor->next());
+  assert(count == basic_count);
+
   options.flags = grnxx::alpha::MAP_CURSOR_ORDER_BY_KEY;
   cursor.reset(map->open_key_cursor(min_key, max_key, options));
   count = 0;
@@ -306,6 +434,25 @@ void test_key_cursor(const std::unique_ptr<Map<T>> &map) {
   }
   assert(!cursor->next());
   assert(count == basic_count);
+
+  cursor.reset(map->open_cursor((map->key() >= min_key) &&
+                                (map->key() <= max_key), options));
+  count = 0;
+  if (cursor->next()) {
+    assert(cursor->key() >= min_key);
+    assert(cursor->key() <= max_key);
+    ++count;
+  }
+  prev_key = cursor->key();
+  while (cursor->next()) {
+    assert(cursor->key() >= min_key);
+    assert(cursor->key() <= max_key);
+    assert(prev_key < cursor->key());
+    prev_key = cursor->key();
+    ++count;
+  }
+  assert(!cursor->next());
+  assert(count == basic_count);
 }
 
 void test_key_cursor(const std::unique_ptr<Map<grnxx::GeoPoint>> &) {
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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