edponce commented on a change in pull request #10567:
URL: https://github.com/apache/arrow/pull/10567#discussion_r655907205



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
##########
@@ -1511,5 +1517,55 @@ TEST(TestBinaryArithmeticDecimal, Divide) {
   }
 }
 
+TYPED_TEST(TestUnaryArithmeticFloating, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1, 2.7182818284590452354]"),
+                        ArrayFromJSON(ty, "[0, 1]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"), ArrayFromJSON(ty, 
"[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"), ArrayFromJSON(ty, 
"[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Ln, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[-1]", "domain error");
+}
+
+TYPED_TEST(TestUnaryArithmeticSigned, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1]"), ArrayFromJSON(float64(), 
"[0]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Ln, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[-1]", "domain error");
+}
+
+TYPED_TEST(TestUnaryArithmeticUnsigned, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1]"), ArrayFromJSON(float64(), 
"[0]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+}
+

Review comment:
       In valid test cases, no need to use `ty` (aka `this->type_singleton()`) 
with `ArrayFromJSON` because that is the default type.
   
   Moreover, PR #10395 extends the unary scalar arithmetic test class to 
support combinations of JSON/Array inputs which will allow you to further 
simplify the test statements as follows:
   * For integer inputs: `AssertUnaryOp(Ln, "[1]", ArrayFromJSON(float64(), 
"[0]"));`
   * For floating point inputs: `AssertUnaryOp(Log10, "[1, 10]", "[0, 1]");`




-- 
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:
[email protected]


Reply via email to