susumu.yata
null+****@clear*****
Mon Nov 17 10:09:08 JST 2014
susumu.yata 2014-11-17 10:09:08 +0900 (Mon, 17 Nov 2014) New Revision: 73e3b650111cfd785622d26d189db596a26f57f0 https://github.com/groonga/grnxx/commit/73e3b650111cfd785622d26d189db596a26f57f0 Message: Enable a test for subexpressions. (#62) Modified files: test/Makefile.am test/test_issue_62.cpp Modified: test/Makefile.am (+5 -5) =================================================================== --- test/Makefile.am 2014-11-15 02:38:01 +0900 (dc46cf2) +++ test/Makefile.am 2014-11-17 10:09:08 +0900 (7650523) @@ -5,13 +5,13 @@ TESTS = \ test_db \ test_table \ test_column \ - test_expression + test_expression \ + test_issue_62 # test_index \ # test_merger \ # test_sorter \ -# test_pipeline \ -# test_issue_62 +# test_pipeline check_PROGRAMS = $(TESTS) @@ -48,5 +48,5 @@ test_expression_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la #test_pipeline_SOURCES = test_pipeline.cpp #test_pipeline_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la -#test_issue_62_SOURCES = test_issue_62.cpp -#test_issue_62_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la +test_issue_62_SOURCES = test_issue_62.cpp +test_issue_62_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la Modified: test/test_issue_62.cpp (+38 -53) =================================================================== --- test/test_issue_62.cpp 2014-11-15 02:38:01 +0900 (9f2f117) +++ test/test_issue_62.cpp 2014-11-17 10:09:08 +0900 (b4a7f80) @@ -25,84 +25,69 @@ #include "grnxx/expression.hpp" #include "grnxx/table.hpp" -std::mt19937_64 mersenne_twister; +std::mt19937_64 rng; void test_scored_subexpression() { - grnxx::Error error; - // Create a database with the default options. - auto db = grnxx::open_db(&error, ""); - assert(db); + auto db = grnxx::open_db(""); // Create a table with the default options. - auto table = db->create_table(&error, "Table"); - assert(table); + auto table = db->create_table("Table"); - constexpr grnxx::Int NUM_ROWS = 1 << 16; + constexpr size_t NUM_ROWS = 1 << 16; // Generate random values. grnxx::Array<grnxx::Float> float_values; grnxx::Array<grnxx::Int> ref_values; - assert(float_values.resize(&error, NUM_ROWS + 1)); - assert(ref_values.resize(&error, NUM_ROWS + 1)); - for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { - float_values[i] = 1.0 * mersenne_twister() / mersenne_twister.max(); -// ref_values[i] = (mersenne_twister() % NUM_ROWS) + 1; - ref_values[i] = 1; + float_values.resize(NUM_ROWS); + ref_values.resize(NUM_ROWS); + for (size_t i = 0; i < NUM_ROWS; ++i) { + float_values[i] = grnxx::Float(1.0 * rng() / rng.max()); +// ref_values[i] = mersenne_twister() % NUM_ROWS; + ref_values[i] = grnxx::Int(0); } // Create columns for Float and Int values. - auto float_column = table->create_column(&error, "Float", grnxx::FLOAT_DATA); - assert(float_column); + auto float_column = table->create_column("Float", grnxx::FLOAT_DATA); grnxx::ColumnOptions options; - options.ref_table_name = "Table"; - auto ref_column = table->create_column(&error, "Ref", grnxx::INT_DATA, - options); - assert(ref_column); + options.reference_table_name = "Table"; + auto ref_column = table->create_column("Ref", grnxx::INT_DATA, options); // 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(float_column->set(&error, row_id, float_values[i])); + for (size_t i = 0; i < NUM_ROWS; ++i) { + grnxx::Int row_id = table->insert_row(); + assert(row_id.value() == grnxx::Int(i).value()); + float_column->set(row_id, float_values[i]); } - for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { - assert(ref_column->set(&error, i, ref_values[i])); + for (size_t i = 0; i < NUM_ROWS; ++i) { + ref_column->set(grnxx::Int(i), ref_values[i]); } // Generate a list of records. grnxx::Array<grnxx::Record> records; - auto cursor = table->create_cursor(&error); - assert(cursor); - auto result = cursor->read_all(&error, &records); - assert(result.is_ok); - assert(result.count == table->num_rows()); + auto cursor = table->create_cursor(); + assert(cursor->read_all(&records) == table->num_rows()); // Set scores (Float). - auto builder = grnxx::ExpressionBuilder::create(&error, table); - assert(builder); - assert(builder->push_column(&error, "Float")); - auto expression = builder->release(&error); - assert(expression); - assert(expression->adjust(&error, &records)); + auto builder = grnxx::ExpressionBuilder::create(table); + builder->push_column("Float"); + auto expression = builder->release(); + expression->adjust(&records); // Test an expression (Ref.(_score > 0.5)). - assert(builder->push_column(&error, "Ref")); - assert(builder->begin_subexpression(&error)); - assert(builder->push_score(&error)); - assert(builder->push_constant(&error, grnxx::Float(0.5))); - assert(builder->push_operator(&error, grnxx::GREATER_OPERATOR)); - assert(builder->end_subexpression(&error)); - expression = builder->release(&error); - assert(expression); - - assert(expression->filter(&error, &records)); - grnxx::Int count = 0; - for (grnxx::Int i = 1; i <= NUM_ROWS; ++i) { - if (float_values[i] > 0.5) { - assert(records.get_row_id(count) == i); + builder->push_column("Ref"); + builder->begin_subexpression(); + builder->push_score(); + builder->push_constant(grnxx::Float(0.5)); + builder->push_operator(grnxx::GREATER_OPERATOR); + builder->end_subexpression(); + expression = builder->release(); + + expression->filter(&records); + size_t count = 0; + for (size_t i = 0; i < NUM_ROWS; ++i) { + if (float_values[i].value() > 0.5) { + assert(records[count].row_id.value() == grnxx::Int(i).value()); ++count; } } -------------- next part -------------- HTML����������������������������...Télécharger