susumu.yata
null+****@clear*****
Fri Sep 12 18:10:15 JST 2014
susumu.yata 2014-09-12 18:10:15 +0900 (Fri, 12 Sep 2014) New Revision: a148d6e239e672aeec7abd0dc57b0bbea0f2f46c https://github.com/groonga/grnxx/commit/a148d6e239e672aeec7abd0dc57b0bbea0f2f46c Message: Add a test for reverse cursor. (#47) Modified files: test/test_index.cpp Modified: test/test_index.cpp (+63 -0) =================================================================== --- test/test_index.cpp 2014-09-12 18:09:34 +0900 (29872be) +++ test/test_index.cpp 2014-09-12 18:10:15 +0900 (fc12850) @@ -268,6 +268,68 @@ void test_range() { assert(count == records.size()); } +void test_reverse() { + constexpr grnxx::Int NUM_ROWS = 1 << 16; + + grnxx::Error error; + + // Create a database with the default options. + auto db = grnxx::open_db(&error, ""); + assert(db); + + // Create a table with the default options. + auto table = db->create_table(&error, "Table"); + assert(table); + + // Create a column. + auto column = table->create_column(&error, "Int", grnxx::INT_DATA); + assert(column); + + // Create an index. + auto index = column->create_index(&error, "Index", grnxx::TREE_INDEX); + assert(index); + + // Generate random values. + // Int: [0, 100). + grnxx::Array<grnxx::Int> values; + assert(values.resize(&error, NUM_ROWS + 1)); + for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { + values.set(i, mersenne_twister() % 100); + } + + // Store generated values into columns. + for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { + grnxx::Int row_id; + assert(table->insert_row(&error, grnxx::NULL_ROW_ID, + grnxx::Datum(), &row_id)); + assert(row_id == i); + assert(column->set(&error, row_id, values[i])); + } + + // Create a cursor. + grnxx::IndexRange range; + range.set_lower_bound(grnxx::Int(10), grnxx::INCLUSIVE_END_POINT); + range.set_upper_bound(grnxx::Int(90), grnxx::EXCLUSIVE_END_POINT); + grnxx::CursorOptions options; + options.order_type = grnxx::REVERSE_ORDER; + auto cursor = index->create_cursor(&error, range, options); + assert(cursor); + + grnxx::Array<grnxx::Record> records; + assert(cursor->read_all(&error, &records) != -1); + for (grnxx::Int i = 1; i < records.size(); ++i) { + assert(values[records.get_row_id(i)] >= values[records.get_row_id(i)]); + } + + grnxx::Int count = 0; + for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { + if ((values[i] >= 10) && (values[i] < 90)) { + ++count; + } + } + assert(count == records.size()); +} + int main() { test_index(); @@ -276,6 +338,7 @@ int main() { test_remove(); test_range(); + test_reverse(); return 0; } -------------- next part -------------- HTML����������������������������... Descargar