susumu.yata
null+****@clear*****
Tue Dec 2 11:28:25 JST 2014
susumu.yata 2014-12-02 11:28:25 +0900 (Tue, 02 Dec 2014) New Revision: 87400f47a1a8415b9bc8c6e6e4633d4252333b45 https://github.com/groonga/grnxx/commit/87400f47a1a8415b9bc8c6e6e4633d4252333b45 Message: Add a test for TreeIndex<Float>::find_in_range(). (#124) Modified files: test/test_index.cpp Modified: test/test_index.cpp (+50 -52) =================================================================== --- test/test_index.cpp 2014-12-02 11:28:00 +0900 (afc1276) +++ test/test_index.cpp 2014-12-02 11:28:25 +0900 (43121de) @@ -591,66 +591,64 @@ void test_int_range() { assert(count == records.size()); } -//void test_float_range() { -// constexpr grnxx::Int NUM_ROWS = 1 << 16; - -// grnxx::Error error; +void test_float_range() { + constexpr size_t NUM_ROWS = 1 << 16; -// // Create a database with the default options. -// auto db = grnxx::open_db(&error, ""); -// assert(db); + // Create a database with the default options. + auto db = grnxx::open_db(""); -// // Create a table with the default options. -// auto table = db->create_table(&error, "Table"); -// assert(table); + // Create a table with the default options. + auto table = db->create_table("Table"); -// // Create a column. -// auto column = table->create_column(&error, "Float", grnxx::FLOAT_DATA); -// assert(column); + // Create a column. + auto column = table->create_column("Float", grnxx::FLOAT_DATA); -// // Create an index. -// auto index = column->create_index(&error, "Index", grnxx::TREE_INDEX); -// assert(index); + // Create an index. + auto index = column->create_index("Index", grnxx::TREE_INDEX); -// // Generate random values. -// // Float: [0.0, 1.0). -// grnxx::Array<grnxx::Float> values; -// assert(values.resize(&error, NUM_ROWS + 1)); -// for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { -// values.set(i, (mersenne_twister() % 256) / 256.0); -// } + // Generate random values. + // Float: [0.0, 1.0). + grnxx::Array<grnxx::Float> values; + values.resize(NUM_ROWS); + for (size_t i = 0; i < NUM_ROWS; ++i) { + if ((mersenne_twister() % 100) == 0) { + values[i] = grnxx::Float::na(); + } else { + values[i] = grnxx::Float((mersenne_twister() % 256) / 256.0); + } + } -// // 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])); -// } + // Store generated values into columns. + for (size_t i = 0; i < NUM_ROWS; ++i) { + grnxx::Int row_id = table->insert_row(); + column->set(row_id, values[i]); + } -// // Create a cursor. -// grnxx::IndexRange range; -// range.set_lower_bound(grnxx::Float(64 / 256.0), grnxx::INCLUSIVE_END_POINT); -// range.set_upper_bound(grnxx::Float(192 / 256.0), grnxx::EXCLUSIVE_END_POINT); -// auto cursor = index->find_in_range(&error, range); -// assert(cursor); + // Create a cursor. + grnxx::IndexRange range; + range.set_lower_bound(grnxx::Float(0.25), grnxx::INCLUSIVE_END_POINT); + range.set_upper_bound(grnxx::Float(0.75), grnxx::EXCLUSIVE_END_POINT); + auto cursor = index->find_in_range(range); -// grnxx::Array<grnxx::Record> records; -// auto result = cursor->read_all(&error, &records); -// assert(result.is_ok); -// for (grnxx::Int i = 1; i < records.size(); ++i) { -// assert(values[records.get_row_id(i - 1)] <= values[records.get_row_id(i)]); -// } + grnxx::Array<grnxx::Record> records; + size_t count = cursor->read_all(&records); + for (size_t i = 1; i < records.size(); ++i) { + size_t lhs_row_id = records[i - 1].row_id.raw(); + size_t rhs_row_id = records[i].row_id.raw(); + assert(!values[lhs_row_id].is_na()); + assert(!values[rhs_row_id].is_na()); + assert((values[lhs_row_id] <= values[rhs_row_id]).is_true()); + } -// grnxx::Int count = 0; -// for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { -// if ((values[i] >= (64 / 256.0)) && (values[i] < (192 / 256.0))) { -// ++count; -// } -// } -// assert(count == records.size()); -//} + count = 0; + for (size_t i = 0; i < NUM_ROWS; ++i) { + if ((values[i] >= grnxx::Float(0.25)).is_true() && + (values[i] < grnxx::Float(0.75)).is_true()) { + ++count; + } + } + assert(count == records.size()); +} //void test_text_range() { // constexpr grnxx::Int NUM_ROWS = 1 << 16; @@ -1058,7 +1056,7 @@ int main() { test_text_exact_match(); test_int_range(); -// test_float_range(); + test_float_range(); // test_text_range(); // test_text_find_starts_with(); -------------- next part -------------- HTML����������������������������... Download