[Groonga-commit] groonga/grnxx at 1308247 [master] Enable a test for ColumnNode of Expression. (#104)

Zurück zum Archiv-Index

susumu.yata null+****@clear*****
Tue Dec 16 10:49:58 JST 2014


susumu.yata	2014-11-12 19:00:24 +0900 (Wed, 12 Nov 2014)

  New Revision: 130824759ef7a5b9ea9fc860c6940b51453e0351
  https://github.com/groonga/grnxx/commit/130824759ef7a5b9ea9fc860c6940b51453e0351

  Message:
    Enable a test for ColumnNode of Expression. (#104)

  Modified files:
    test/test_expression.cpp

  Modified: test/test_expression.cpp (+62 -69)
===================================================================
--- test/test_expression.cpp    2014-11-12 18:55:44 +0900 (23f294e)
+++ test/test_expression.cpp    2014-11-12 19:00:24 +0900 (3e254ee)
@@ -604,85 +604,78 @@ void test_score() try {
   throw;
 }
 
-//void test_column() {
-//  grnxx::Error error;
-
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
+void test_column() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Bool).
-//  assert(builder->push_column(&error, "Bool"));
-//  auto expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Bool).
+  builder->push_column("Bool");
+  auto expression = builder->release();
 
-//  auto records = create_input_records();
+  auto records = create_input_records();
 
-//  grnxx::Array<grnxx::Bool> bool_results;
-//  assert(expression->evaluate(&error, records, &bool_results));
-//  assert(bool_results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < bool_results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(bool_results[i] == test.bool_values[row_id]);
-//  }
+  grnxx::Array<grnxx::Bool> bool_results;
+  expression->evaluate(records, &bool_results);
+  assert(bool_results.size() == test.table->num_rows());
+  for (size_t i = 0; i < bool_results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(bool_results[i] == test.bool_values[row_id]);
+  }
 
-//  assert(expression->filter(&error, &records));
-//  grnxx::Int count = 0;
-//  for (grnxx::Int i = 1; i < test.bool_values.size(); ++i) {
-//    if (test.bool_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  size_t count = 0;
+  for (size_t i = 1; i < test.bool_values.size(); ++i) {
+    if (test.bool_values[i]) {
+      assert(records[count].row_id == grnxx::Int(i));
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Int).
-//  assert(builder->push_column(&error, "Int"));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int).
+  builder->push_column("Int");
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  grnxx::Array<grnxx::Int> int_results;
-//  assert(expression->evaluate(&error, records, &int_results));
-//  assert(int_results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < int_results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(int_results[i] == test.int_values[row_id]);
-//  }
+  grnxx::Array<grnxx::Int> int_results;
+  expression->evaluate(records, &int_results);
+  assert(int_results.size() == test.table->num_rows());
+  for (size_t i = 0; i < int_results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(int_results[i] == test.int_values[row_id]);
+  }
 
-//  // Test an expression (Float).
-//  assert(builder->push_column(&error, "Float"));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float).
+  builder->push_column("Float");
+  expression = builder->release();
 
-//  grnxx::Array<grnxx::Float> float_results;
-//  assert(expression->evaluate(&error, records, &float_results));
-//  assert(float_results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < float_results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(float_results[i] == test.float_values[row_id]);
-//  }
+  grnxx::Array<grnxx::Float> float_results;
+  expression->evaluate(records, &float_results);
+  assert(float_results.size() == test.table->num_rows());
+  for (size_t i = 0; i < float_results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(float_results[i] == test.float_values[row_id]);
+  }
 
-//  assert(expression->adjust(&error, &records));
-//  assert(records.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < records.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(records.get_score(i) == test.float_values[row_id]);
-//  }
+  expression->adjust(&records);
+  assert(records.size() == test.table->num_rows());
+  for (size_t i = 0; i < records.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(records[i].score == test.float_values[row_id]);
+  }
 
-//  // Test an expression (GeoPoint).
-//  assert(builder->push_column(&error, "GeoPoint"));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (GeoPoint).
+  builder->push_column("GeoPoint");
+  expression = builder->release();
 
-//  grnxx::Array<grnxx::GeoPoint> geo_point_results;
-//  assert(expression->evaluate(&error, records, &geo_point_results));
-//  assert(geo_point_results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < geo_point_results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(geo_point_results[i] == test.geo_point_values[row_id]);
-//  }
+  grnxx::Array<grnxx::GeoPoint> geo_point_results;
+  expression->evaluate(records, &geo_point_results);
+  assert(geo_point_results.size() == test.table->num_rows());
+  for (size_t i = 0; i < geo_point_results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(geo_point_results[i] == test.geo_point_values[row_id]);
+  }
 
 //  // Test an expression (Text).
 //  assert(builder->push_column(&error, "Text"));
@@ -803,7 +796,7 @@ void test_score() try {
 //    grnxx::Int row_id = records.get_row_id(i);
 //    assert(ref_vector_results[i] == test.ref_vector_values[row_id]);
 //  }
-//}
+}
 
 //void test_logical_not() {
 //  grnxx::Error error;
@@ -3025,7 +3018,7 @@ int main() {
   test_constant();
   test_row_id();
   test_score();
-//  test_column();
+  test_column();
 
 //  // Unary operators.
 //  test_logical_not();
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index