susumu.yata
null+****@clear*****
Tue Sep 16 09:36:39 JST 2014
susumu.yata 2014-09-16 09:36:39 +0900 (Tue, 16 Sep 2014) New Revision: 28fade8a5e79ce352083d0bfbab2514cac80bd1b https://github.com/groonga/grnxx/commit/28fade8a5e79ce352083d0bfbab2514cac80bd1b Message: Add a test for exact match search. Modified files: test/test_index.cpp Modified: test/test_index.cpp (+61 -0) =================================================================== --- test/test_index.cpp 2014-09-16 09:36:26 +0900 (fc12850) +++ test/test_index.cpp 2014-09-16 09:36:39 +0900 (a0317f1) @@ -208,6 +208,65 @@ void test_remove() { } } +void test_exact_match() { + 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])); + } + + // Test cursors for each value. + for (grnxx::Int value = 0; value < 100; ++value) { + auto cursor = index->create_cursor(&error, value); + 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)] == value); + } + + grnxx::Int count = 0; + for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { + if (values[i] == value) { + ++count; + } + } + assert(count == records.size()); + } +} + void test_range() { constexpr grnxx::Int NUM_ROWS = 1 << 16; @@ -337,6 +396,8 @@ int main() { test_index_and_set(); test_remove(); + test_exact_match(); + test_range(); test_reverse(); -------------- next part -------------- HTML����������������������������...Download