[Groonga-commit] groonga/grnxx at eea97b6 [master] Enable tests for comparison operators. (#106)

Back to archive index

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


susumu.yata	2014-11-13 22:02:36 +0900 (Thu, 13 Nov 2014)

  New Revision: eea97b6d2aff38b1d1610bbf4beaf12db75c68de
  https://github.com/groonga/grnxx/commit/eea97b6d2aff38b1d1610bbf4beaf12db75c68de

  Message:
    Enable tests for comparison operators. (#106)

  Modified files:
    test/test_expression.cpp

  Modified: test/test_expression.cpp (+455 -545)
===================================================================
--- test/test_expression.cpp    2014-11-13 21:49:25 +0900 (d9c4f0b)
+++ test/test_expression.cpp    2014-11-13 22:02:36 +0900 (3c8ea6b)
@@ -624,7 +624,7 @@ void test_column() {
 
   expression->filter(&records);
   size_t count = 0;
-  for (size_t i = 1; i < test.bool_values.size(); ++i) {
+  for (size_t i = 0; i < test.bool_values.size(); ++i) {
     if (test.bool_values[i].is_true()) {
       assert(records[count].row_id.value() == grnxx::Int(i).value());
       ++count;
@@ -1076,148 +1076,141 @@ void test_logical_or() {
   assert(records.size() == count);
 }
 
-//void test_equal() {
-//  grnxx::Error error;
-
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
+void test_equal() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Bool == Bool2).
-//  assert(builder->push_column(&error, "Bool"));
-//  assert(builder->push_column(&error, "Bool2"));
-//  assert(builder->push_operator(&error, grnxx::EQUAL_OPERATOR));
-//  auto expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Bool == Bool2).
+  builder->push_column("Bool");
+  builder->push_column("Bool2");
+  builder->push_operator(grnxx::EQUAL_OPERATOR);
+  auto expression = builder->release();
 
-//  auto records = create_input_records();
+  auto records = create_input_records();
 
-//  grnxx::Array<grnxx::Bool> results;
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.bool_values[row_id] == test.bool2_values[row_id]));
-//  }
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.bool_values[row_id] == test.bool2_values[row_id]).value());
+  }
 
-//  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] == test.bool2_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 = 0; i < test.bool_values.size(); ++i) {
+    if ((test.bool_values[i] == test.bool2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Int == Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int == Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::EQUAL_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] == test.int2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] == test.int2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] == test.int2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] == test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Float == Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
-//  assert(builder->push_operator(&error, grnxx::EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float == Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::EQUAL_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] == test.float2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] == test.float2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] == test.float2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] == test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (GeoPoint == GeoPoint2).
-//  assert(builder->push_column(&error, "GeoPoint"));
-//  assert(builder->push_column(&error, "GeoPoint2"));
-//  assert(builder->push_operator(&error, grnxx::EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (GeoPoint == GeoPoint2).
+  builder->push_column("GeoPoint");
+  builder->push_column("GeoPoint2");
+  builder->push_operator(grnxx::EQUAL_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.geo_point_values[row_id] == test.geo_point2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.geo_point_values[row_id] ==
+            test.geo_point2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.geo_point_values.size(); ++i) {
-//    if (test.geo_point_values[i] == test.geo_point2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.geo_point_values.size(); ++i) {
+    if ((test.geo_point_values[i] == test.geo_point2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
 //  // Test an expression (Text == Text2).
-//  assert(builder->push_column(&error, "Text"));
-//  assert(builder->push_column(&error, "Text2"));
-//  assert(builder->push_operator(&error, grnxx::EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+//  builder->push_column("Text");
+//  builder->push_column("Text2");
+//  builder->push_operator(grnxx::EQUAL_OPERATOR);
+//  expression = builder->release();
 
 //  records = create_input_records();
 
 //  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
+//  expression->evaluate(records, &results);
 //  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.text_values[row_id] == test.text2_values[row_id]));
+//  for (size_t i = 0; i < results.size(); ++i) {
+//    size_t row_id = records[i].row_id.value();
+//    assert(results[i].value() ==
+//           (test.text_values[row_id] == test.text2_values[row_id]).value());
 //  }
 
-//  assert(expression->filter(&error, &records));
+//  expression->filter(&records);
 //  count = 0;
-//  for (grnxx::Int i = 1; i < test.text_values.size(); ++i) {
-//    if (test.text_values[i] == test.text2_values[i]) {
-//      assert(records.get_row_id(count) == i);
+//  for (size_t i = 1; i < test.text_values.size(); ++i) {
+//    if ((test.text_values[i] == test.text2_values[i]).is_true()) {
+//      assert(records[count].row_id.value() == grnxx::Int(i).value());
 //      ++count;
 //    }
 //  }
@@ -1362,46 +1355,151 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
+}
 
-//void test_not_equal() {
-//  grnxx::Error error;
+void test_not_equal() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
+  // Test an expression (Bool != Bool2).
+  builder->push_column("Bool");
+  builder->push_column("Bool2");
+  builder->push_operator(grnxx::NOT_EQUAL_OPERATOR);
+  auto expression = builder->release();
 
-//  // Test an expression (Bool != Bool2).
-//  assert(builder->push_column(&error, "Bool"));
-//  assert(builder->push_column(&error, "Bool2"));
+  auto records = create_input_records();
+
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.bool_values[row_id] != test.bool2_values[row_id]).value());
+  }
+
+  expression->filter(&records);
+  size_t count = 0;
+  for (size_t i = 0; i < test.bool_values.size(); ++i) {
+    if ((test.bool_values[i] != test.bool2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
+
+  // Test an expression (Int != Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::NOT_EQUAL_OPERATOR);
+  expression = builder->release();
+
+  records = create_input_records();
+
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] != test.int2_values[row_id]).value());
+  }
+
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] != test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
+
+  // Test an expression (Float != Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::NOT_EQUAL_OPERATOR);
+  expression = builder->release();
+
+  records = create_input_records();
+
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] != test.float2_values[row_id]).value());
+  }
+
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] != test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
+
+  // Test an expression (GeoPoint != GeoPoint2).
+  builder->push_column("GeoPoint");
+  builder->push_column("GeoPoint2");
+  builder->push_operator(grnxx::NOT_EQUAL_OPERATOR);
+  expression = builder->release();
+
+  records = create_input_records();
+
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() == (test.geo_point_values[row_id] !=
+                                  test.geo_point2_values[row_id]).value());
+  }
+
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.geo_point_values.size(); ++i) {
+    if ((test.geo_point_values[i] != test.geo_point2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
+
+//  // Test an expression (Text != Text2).
+//  assert(builder->push_column(&error, "Text"));
+//  assert(builder->push_column(&error, "Text2"));
 //  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
-//  auto expression = builder->release(&error);
+//  expression = builder->release(&error);
 //  assert(expression);
 
-//  auto records = create_input_records();
+//  records = create_input_records();
 
-//  grnxx::Array<grnxx::Bool> results;
+//  results.clear();
 //  assert(expression->evaluate(&error, records, &results));
 //  assert(results.size() == test.table->num_rows());
 //  for (grnxx::Int i = 0; i < results.size(); ++i) {
 //    grnxx::Int row_id = records.get_row_id(i);
 //    assert(results[i] ==
-//           (test.bool_values[row_id] != test.bool2_values[row_id]));
+//           (test.text_values[row_id] != test.text2_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] != test.bool2_values[i]) {
+//  count = 0;
+//  for (grnxx::Int i = 1; i < test.text_values.size(); ++i) {
+//    if (test.text_values[i] != test.text2_values[i]) {
 //      assert(records.get_row_id(count) == i);
 //      ++count;
 //    }
 //  }
 //  assert(records.size() == count);
 
-//  // Test an expression (Int != Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
+//  // Test an expression (BoolVector != BoolVector2).
+//  assert(builder->push_column(&error, "BoolVector"));
+//  assert(builder->push_column(&error, "BoolVector2"));
 //  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
 //  expression = builder->release(&error);
 //  assert(expression);
@@ -1413,23 +1511,23 @@ void test_logical_or() {
 //  assert(results.size() == test.table->num_rows());
 //  for (grnxx::Int i = 0; i < results.size(); ++i) {
 //    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] != test.int2_values[row_id]));
+//    assert(results[i] == (test.bool_vector_values[row_id] !=
+//                          test.bool_vector2_values[row_id]));
 //  }
 
 //  assert(expression->filter(&error, &records));
 //  count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] != test.int2_values[i]) {
+//  for (grnxx::Int i = 1; i < test.bool_vector_values.size(); ++i) {
+//    if (test.bool_vector_values[i] != test.bool_vector2_values[i]) {
 //      assert(records.get_row_id(count) == i);
 //      ++count;
 //    }
 //  }
 //  assert(records.size() == count);
 
-//  // Test an expression (Float != Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
+//  // Test an expression (IntVector != IntVector2).
+//  assert(builder->push_column(&error, "IntVector"));
+//  assert(builder->push_column(&error, "IntVector2"));
 //  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
 //  expression = builder->release(&error);
 //  assert(expression);
@@ -1441,135 +1539,23 @@ void test_logical_or() {
 //  assert(results.size() == test.table->num_rows());
 //  for (grnxx::Int i = 0; i < results.size(); ++i) {
 //    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] != test.float2_values[row_id]));
+//    assert(results[i] == (test.int_vector_values[row_id] !=
+//                          test.int_vector2_values[row_id]));
 //  }
 
 //  assert(expression->filter(&error, &records));
 //  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] != test.float2_values[i]) {
+//  for (grnxx::Int i = 1; i < test.int_vector_values.size(); ++i) {
+//    if (test.int_vector_values[i] != test.int_vector2_values[i]) {
 //      assert(records.get_row_id(count) == i);
 //      ++count;
 //    }
 //  }
 //  assert(records.size() == count);
 
-//  // Test an expression (GeoPoint != GeoPoint2).
-//  assert(builder->push_column(&error, "GeoPoint"));
-//  assert(builder->push_column(&error, "GeoPoint2"));
-//  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
-
-//  records = create_input_records();
-
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] == (test.geo_point_values[row_id] !=
-//                          test.geo_point2_values[row_id]));
-//  }
-
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.geo_point_values.size(); ++i) {
-//    if (test.geo_point_values[i] != test.geo_point2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
-
-//  // Test an expression (Text != Text2).
-//  assert(builder->push_column(&error, "Text"));
-//  assert(builder->push_column(&error, "Text2"));
-//  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
-
-//  records = create_input_records();
-
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.text_values[row_id] != test.text2_values[row_id]));
-//  }
-
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.text_values.size(); ++i) {
-//    if (test.text_values[i] != test.text2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
-
-//  // Test an expression (BoolVector != BoolVector2).
-//  assert(builder->push_column(&error, "BoolVector"));
-//  assert(builder->push_column(&error, "BoolVector2"));
-//  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
-
-//  records = create_input_records();
-
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] == (test.bool_vector_values[row_id] !=
-//                          test.bool_vector2_values[row_id]));
-//  }
-
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.bool_vector_values.size(); ++i) {
-//    if (test.bool_vector_values[i] != test.bool_vector2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
-
-//  // Test an expression (IntVector != IntVector2).
-//  assert(builder->push_column(&error, "IntVector"));
-//  assert(builder->push_column(&error, "IntVector2"));
-//  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
-
-//  records = create_input_records();
-
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] == (test.int_vector_values[row_id] !=
-//                          test.int_vector2_values[row_id]));
-//  }
-
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.int_vector_values.size(); ++i) {
-//    if (test.int_vector_values[i] != test.int_vector2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
-
-//  // Test an expression (FloatVector != FloatVector2).
-//  assert(builder->push_column(&error, "FloatVector"));
-//  assert(builder->push_column(&error, "FloatVector2"));
+//  // Test an expression (FloatVector != FloatVector2).
+//  assert(builder->push_column(&error, "FloatVector"));
+//  assert(builder->push_column(&error, "FloatVector2"));
 //  assert(builder->push_operator(&error, grnxx::NOT_EQUAL_OPERATOR));
 //  expression = builder->release(&error);
 //  assert(expression);
@@ -1650,70 +1636,65 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
-
-//void test_less() {
-//  grnxx::Error error;
+}
 
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
+void test_less() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Int < Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::LESS_OPERATOR));
-//  auto expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int < Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::LESS_OPERATOR);
+  auto expression = builder->release();
 
-//  auto records = create_input_records();
+  auto records = create_input_records();
 
-//  grnxx::Array<grnxx::Bool> results;
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] < test.int2_values[row_id]));
-//  }
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] < test.int2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  grnxx::Int count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] < test.int2_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 = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] < test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Float < Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
-//  assert(builder->push_operator(&error, grnxx::LESS_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float < Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::LESS_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] < test.float2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] < test.float2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] < test.float2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] < test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
 //  // Test an expression (Text < Text2).
 //  assert(builder->push_column(&error, "Text"));
@@ -1742,98 +1723,65 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
-
-//void test_less_equal() {
-//  grnxx::Error error;
-
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
-
-//  // Test an expression (Int <= Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::LESS_EQUAL_OPERATOR));
-//  auto expression = builder->release(&error);
-//  assert(expression);
-
-//  auto records = create_input_records();
-
-//  grnxx::Array<grnxx::Bool> results;
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] <= test.int2_values[row_id]));
-//  }
+}
 
-//  assert(expression->filter(&error, &records));
-//  grnxx::Int count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] <= test.int2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+void test_less_equal() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Int <= Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::LESS_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int <= Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::LESS_EQUAL_OPERATOR);
+  auto expression = builder->release();
 
-//  records = create_input_records();
+  auto records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] <= test.int2_values[row_id]));
-//  }
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] <= test.int2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] <= test.int2_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 = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] <= test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Float <= Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
-//  assert(builder->push_operator(&error, grnxx::LESS_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float <= Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::LESS_EQUAL_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] <= test.float2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] <= test.float2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] <= test.float2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] <= test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
 //  // Test an expression (Text <= Text2).
 //  assert(builder->push_column(&error, "Text"));
@@ -1862,70 +1810,65 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
-
-//void test_greater() {
-//  grnxx::Error error;
+}
 
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
+void test_greater() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Int > Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::GREATER_OPERATOR));
-//  auto expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int > Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::GREATER_OPERATOR);
+  auto expression = builder->release();
 
-//  auto records = create_input_records();
+  auto records = create_input_records();
 
-//  grnxx::Array<grnxx::Bool> results;
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] > test.int2_values[row_id]));
-//  }
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] > test.int2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  grnxx::Int count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] > test.int2_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 = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] > test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Float > Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
-//  assert(builder->push_operator(&error, grnxx::GREATER_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float > Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::GREATER_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] > test.float2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] > test.float2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] > test.float2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] > test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
 //  // Test an expression (Text > Text2).
 //  assert(builder->push_column(&error, "Text"));
@@ -1954,98 +1897,65 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
-
-//void test_greater_equal() {
-//  grnxx::Error error;
-
-//  // Create an object for building expressions.
-//  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
-//  assert(builder);
-
-//  // Test an expression (Int >= Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::GREATER_EQUAL_OPERATOR));
-//  auto expression = builder->release(&error);
-//  assert(expression);
-
-//  auto records = create_input_records();
-
-//  grnxx::Array<grnxx::Bool> results;
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] >= test.int2_values[row_id]));
-//  }
+}
 
-//  assert(expression->filter(&error, &records));
-//  grnxx::Int count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] >= test.int2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+void test_greater_equal() {
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(test.table);
 
-//  // Test an expression (Int >= Int2).
-//  assert(builder->push_column(&error, "Int"));
-//  assert(builder->push_column(&error, "Int2"));
-//  assert(builder->push_operator(&error, grnxx::GREATER_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Int >= Int2).
+  builder->push_column("Int");
+  builder->push_column("Int2");
+  builder->push_operator(grnxx::GREATER_EQUAL_OPERATOR);
+  auto expression = builder->release();
 
-//  records = create_input_records();
+  auto records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.int_values[row_id] >= test.int2_values[row_id]));
-//  }
+  grnxx::Array<grnxx::Bool> results;
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.int_values[row_id] >= test.int2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.int_values.size(); ++i) {
-//    if (test.int_values[i] >= test.int2_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 = 0; i < test.int_values.size(); ++i) {
+    if ((test.int_values[i] >= test.int2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
-//  // Test an expression (Float >= Float2).
-//  assert(builder->push_column(&error, "Float"));
-//  assert(builder->push_column(&error, "Float2"));
-//  assert(builder->push_operator(&error, grnxx::GREATER_EQUAL_OPERATOR));
-//  expression = builder->release(&error);
-//  assert(expression);
+  // Test an expression (Float >= Float2).
+  builder->push_column("Float");
+  builder->push_column("Float2");
+  builder->push_operator(grnxx::GREATER_EQUAL_OPERATOR);
+  expression = builder->release();
 
-//  records = create_input_records();
+  records = create_input_records();
 
-//  results.clear();
-//  assert(expression->evaluate(&error, records, &results));
-//  assert(results.size() == test.table->num_rows());
-//  for (grnxx::Int i = 0; i < results.size(); ++i) {
-//    grnxx::Int row_id = records.get_row_id(i);
-//    assert(results[i] ==
-//           (test.float_values[row_id] >= test.float2_values[row_id]));
-//  }
+  results.clear();
+  expression->evaluate(records, &results);
+  assert(results.size() == test.table->num_rows());
+  for (size_t i = 0; i < results.size(); ++i) {
+    size_t row_id = records[i].row_id.value();
+    assert(results[i].value() ==
+           (test.float_values[row_id] >= test.float2_values[row_id]).value());
+  }
 
-//  assert(expression->filter(&error, &records));
-//  count = 0;
-//  for (grnxx::Int i = 1; i < test.float_values.size(); ++i) {
-//    if (test.float_values[i] >= test.float2_values[i]) {
-//      assert(records.get_row_id(count) == i);
-//      ++count;
-//    }
-//  }
-//  assert(records.size() == count);
+  expression->filter(&records);
+  count = 0;
+  for (size_t i = 0; i < test.float_values.size(); ++i) {
+    if ((test.float_values[i] >= test.float2_values[i]).is_true()) {
+      assert(records[count].row_id.value() == grnxx::Int(i).value());
+      ++count;
+    }
+  }
+  assert(records.size() == count);
 
 //  // Test an expression (Text >= Text2).
 //  assert(builder->push_column(&error, "Text"));
@@ -2074,7 +1984,7 @@ void test_logical_or() {
 //    }
 //  }
 //  assert(records.size() == count);
-//}
+}
 
 //void test_bitwise_and() {
 //  grnxx::Error error;
@@ -3001,12 +2911,12 @@ int main() {
   // Binary operators.
   test_logical_and();
   test_logical_or();
-//  test_equal();
-//  test_not_equal();
-//  test_less();
-//  test_less_equal();
-//  test_greater();
-//  test_greater_equal();
+  test_equal();
+  test_not_equal();
+  test_less();
+  test_less_equal();
+  test_greater();
+  test_greater_equal();
 //  test_bitwise_and();
 //  test_bitwise_or();
 //  test_bitwise_xor();
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index