MCPcopy Create free account
hub / github.com/apache/arrow / TestRandomWithOptions

Function TestRandomWithOptions

cpp/src/arrow/compute/kernels/scalar_random_test.cc:33–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31namespace {
32
33void TestRandomWithOptions(int64_t length, const RandomOptions& random_options) {
34 ExecBatch input({}, length);
35 ASSERT_OK_AND_ASSIGN(Datum result, CallFunction("random", input, &random_options));
36 const auto result_array = result.make_array();
37 ValidateOutput(*result_array);
38 ASSERT_EQ(result_array->length(), length);
39 ASSERT_EQ(result_array->null_count(), 0);
40 AssertTypeEqual(result_array->type(), float64());
41
42 if (length > 0) {
43 // verify E(X), E(X^2) is near theory
44 double sum = 0, square_sum = 0;
45 const double* values = result_array->data()->GetValues<double>(1);
46 for (int64_t i = 0; i < length; ++i) {
47 const double value = values[i];
48 ASSERT_GE(value, 0);
49 ASSERT_LT(value, 1);
50 sum += value;
51 square_sum += value * value;
52 }
53 const double E_X = 0.5;
54 const double E_X2 = 1.0 / 12 + E_X * E_X;
55 ASSERT_NEAR(sum / length, E_X, E_X * 0.02);
56 ASSERT_NEAR(square_sum / length, E_X2, E_X2 * 0.02);
57 }
58}
59
60} // namespace
61

Callers 1

TESTFunction · 0.85

Calls 6

ValidateOutputFunction · 0.85
make_arrayMethod · 0.80
lengthMethod · 0.45
null_countMethod · 0.45
typeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected