pitrou commented on a change in pull request #10395:
URL: https://github.com/apache/arrow/pull/10395#discussion_r646772641



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
##########
@@ -1161,5 +1180,93 @@ TYPED_TEST(TestUnaryArithmeticFloating, AbsoluteValue) {
   }
 }
 
+TYPED_TEST(TestUnaryArithmeticSigned, Sign) {
+  using CType = typename TestFixture::CType;
+  auto min = std::numeric_limits<CType>::min();
+  auto max = std::numeric_limits<CType>::max();
+
+  for (auto allow_signed_zero : {false, true}) {
+    this->SetSignedZero(allow_signed_zero);
+    // Empty array
+    this->AssertUnaryOp(Sign, "[]", ArrayFromJSON(int8(), "[]"));
+    // Scalar/arrays with nulls
+    this->AssertUnaryOp(Sign, "[null]", ArrayFromJSON(int8(), "[null]"));
+    this->AssertUnaryOp(Sign, "[1, null, -10]", ArrayFromJSON(int8(), "[1, 
null, -1]"));
+    // Scalar/arrays with zeros
+    this->AssertUnaryOp(Sign, "[0]", ArrayFromJSON(int8(), "[0]"));
+    // Ordinary scalar/arrays (positive inputs)
+    this->AssertUnaryOp(Sign, "[1, 10, 127]", ArrayFromJSON(int8(), "[1, 1, 
1]"));
+    // Ordinary scalar/arrays (negative inputs)
+    this->AssertUnaryOp(Sign, "[-1, -10, -127]", ArrayFromJSON(int8(), "[-1, 
-1, -1]"));
+    // Min/max
+    this->AssertUnaryOp(Sign, ArrayFromJSON(this->type_singleton(), 
MakeArray(min, max)),
+                        ArrayFromJSON(int8(), "[-1, 1]"));
+
+    auto arg = ArrayFromJSON(this->type_singleton(), MakeArray(-1, min, max, 
1));
+    arg = TweakValidityBit(arg, 1, false);
+    arg = TweakValidityBit(arg, 2, false);
+    this->AssertUnaryOp(Sign, arg, ArrayFromJSON(int8(), "[-1, null, null, 
1]"));
+  }
+}
+
+TYPED_TEST(TestUnaryArithmeticUnsigned, Sign) {
+  using CType = typename TestFixture::CType;
+  auto min = std::numeric_limits<CType>::min();
+  auto max = std::numeric_limits<CType>::max();
+
+  for (auto allow_signed_zero : {false, true}) {
+    this->SetSignedZero(allow_signed_zero);
+    // Empty arrays
+    this->AssertUnaryOp(Sign, "[]", ArrayFromJSON(int8(), "[]"));
+    // Array with nulls
+    this->AssertUnaryOp(Sign, "[null]", ArrayFromJSON(int8(), "[null]"));
+    // Ordinary arrays
+    this->AssertUnaryOp(Sign, "[0, 1, 10, 127]", ArrayFromJSON(int8(), "[0, 1, 
1, 1]"));
+    // Min/max
+    this->AssertUnaryOp(Sign, ArrayFromJSON(this->type_singleton(), 
MakeArray(min, max)),
+                        ArrayFromJSON(int8(), "[0, 1]"));
+
+    auto arg = ArrayFromJSON(this->type_singleton(), MakeArray(0, min, max, 
1));
+    arg = TweakValidityBit(arg, 1, false);
+    arg = TweakValidityBit(arg, 2, false);
+    this->AssertUnaryOp(Sign, arg, ArrayFromJSON(int8(), "[0, null, null, 
1]"));
+  }
+}
+
+TYPED_TEST(TestUnaryArithmeticFloating, Sign) {
+  using CType = typename TestFixture::CType;
+  auto min = std::numeric_limits<CType>::lowest();
+  auto max = std::numeric_limits<CType>::max();
+
+  // Empty array
+  this->AssertUnaryOp(Sign, "[]", ArrayFromJSON(int8(), "[]"));
+  // Scalar/arrays with nulls
+  this->AssertUnaryOp(Sign, "[null]", ArrayFromJSON(int8(), "[null]"));
+  this->AssertUnaryOp(Sign, "[1.3, null, -10.80]",
+                      ArrayFromJSON(int8(), "[1, null, -1]"));
+  // Scalars/arrays with zeros
+  this->AssertUnaryOp(Sign, "[0.0, -0.0]", ArrayFromJSON(int8(), "[0, 0]"));
+  this->SetSignedZero(true);
+  this->AssertUnaryOp(Sign, "[0.0, -0.0]", ArrayFromJSON(int8(), "[1, -1]"));
+  this->SetSignedZero(false);
+  // Ordinary scalars/arrays (positive inputs)
+  this->AssertUnaryOp(Sign, "[1.3, 10.80, 12748.001]",
+                      ArrayFromJSON(int8(), "[1, 1, 1]"));
+  // Ordinary scalars/arrays (negative inputs)
+  this->AssertUnaryOp(Sign, "[-1.3, -10.80, -12748.001]",
+                      ArrayFromJSON(int8(), "[-1, -1, -1]"));
+  // Arrays with infinites
+  this->AssertUnaryOp(Sign, "[Inf, -Inf]", ArrayFromJSON(int8(), "[1, -1]"));
+  // Arrays with NaNs
+  this->AssertUnaryOp(Sign, "[NaN]", ArrayFromJSON(int8(), "[1]"));
+  // Min/max
+  // this->AssertUnaryOp(Sign, ArrayFromJSON(this->type_singleton(), 
MakeArray(min, max)),
+  //                     ArrayFromJSON(int8(), "[-1, 1]"));
+
+  // auto arg = ArrayFromJSON(this->type_singleton(), MakeArray(-1, min, max, 
1));
+  // arg = TweakValidityBit(arg, 1, false);
+  // arg = TweakValidityBit(arg, 2, false);
+  // this->AssertUnaryOp(Sign, arg, ArrayFromJSON(int8(), "[-1, null, null, 
1]"));

Review comment:
       Please remove commented out code.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to