[Groonga-commit] groonga/grnxx at 1d573a8 [master] Add tests for operators TO_INT and TO_FLOAT. (#37)

Back to archive index

susumu.yata null+****@clear*****
Mon Aug 18 16:21:58 JST 2014


susumu.yata	2014-08-18 16:21:58 +0900 (Mon, 18 Aug 2014)

  New Revision: 1d573a8adec039ede4415d1b1621aaf62370fbd1
  https://github.com/groonga/grnxx/commit/1d573a8adec039ede4415d1b1621aaf62370fbd1

  Message:
    Add tests for operators TO_INT and TO_FLOAT. (#37)

  Modified files:
    test/test_expression.cpp

  Modified: test/test_expression.cpp (+67 -0)
===================================================================
--- test/test_expression.cpp    2014-08-18 16:17:39 +0900 (07af42d)
+++ test/test_expression.cpp    2014-08-18 16:21:58 +0900 (c1cbd8d)
@@ -494,6 +494,63 @@ void test_negative() {
   }
 }
 
+void test_to_int() {
+  grnxx::Error error;
+
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
+  assert(builder);
+
+  // Test an expression (Int(Float)).
+  assert(builder->push_column(&error, "Float"));
+  assert(builder->push_operator(&error, grnxx::TO_INT_OPERATOR));
+  auto expression = builder->release(&error);
+  assert(expression);
+
+  grnxx::Array<grnxx::Record> records;
+  auto cursor = test.table->create_cursor(&error);
+  assert(cursor);
+  assert(cursor->read_all(&error, &records) == test.table->num_rows());
+
+  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] ==
+           static_cast<grnxx::Int>(test.float_values[row_id]));
+  }
+}
+
+void test_to_float() {
+  grnxx::Error error;
+
+  // Create an object for building expressions.
+  auto builder = grnxx::ExpressionBuilder::create(&error, test.table);
+  assert(builder);
+
+  // Test an expression (Float(Int)).
+  assert(builder->push_column(&error, "Int"));
+  assert(builder->push_operator(&error, grnxx::TO_FLOAT_OPERATOR));
+  auto expression = builder->release(&error);
+  assert(expression);
+
+  grnxx::Array<grnxx::Record> records;
+  auto cursor = test.table->create_cursor(&error);
+  assert(cursor);
+  assert(cursor->read_all(&error, &records) == test.table->num_rows());
+
+  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] ==
+           static_cast<grnxx::Float>(test.int_values[row_id]));
+  }
+}
+
+// TODO: To be removed.
 void test_expression() {
   grnxx::Error error;
 
@@ -925,12 +982,22 @@ void test_expression() {
 
 int main() {
   init_test();
+
+  // Data.
   test_constant();
   test_column();
+
+  // Unary operators.
   test_logical_not();
   test_bitwise_not();
   test_positive();
   test_negative();
+  test_to_int();
+  test_to_float();
+
+  // TODO: Binary operators.
+
+  // TODO: To be removed.
   test_expression();
   return 0;
 }
-------------- next part --------------
HTML����������������������������...
Download 



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