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

Function TEST_P

cpp/src/arrow/compute/registry_test.cc:50–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50TEST_P(TestRegistry, Basics) {
51 auto registry_factory = std::get<0>(GetParam());
52 auto registry_ = registry_factory();
53 auto get_num_funcs = std::get<1>(GetParam());
54 int n_funcs = get_num_funcs();
55 auto get_func_names = std::get<2>(GetParam());
56 std::vector<std::string> func_names = get_func_names();
57 ASSERT_EQ(n_funcs, registry_->num_functions());
58
59 std::shared_ptr<Function> func = std::make_shared<ScalarFunction>(
60 "f1", Arity::Unary(), /*doc=*/FunctionDoc::Empty());
61 ASSERT_OK(registry_->AddFunction(func));
62 ASSERT_EQ(n_funcs + 1, registry_->num_functions());
63
64 func = std::make_shared<VectorFunction>("f0", Arity::Binary(),
65 /*doc=*/FunctionDoc::Empty());
66 ASSERT_OK(registry_->AddFunction(func));
67 ASSERT_EQ(n_funcs + 2, registry_->num_functions());
68
69 ASSERT_OK_AND_ASSIGN(std::shared_ptr<const Function> f1, registry_->GetFunction("f1"));
70 ASSERT_EQ("f1", f1->name());
71
72 // Nonexistent function
73 ASSERT_RAISES(KeyError, registry_->GetFunction("f2"));
74
75 // Try adding a function with name collision
76 func = std::make_shared<ScalarAggregateFunction>("f1", Arity::Unary(),
77 /*doc=*/FunctionDoc::Empty());
78 ASSERT_RAISES(KeyError, registry_->AddFunction(func));
79
80 // Allow overwriting by flag
81 ASSERT_OK(registry_->AddFunction(func, /*allow_overwrite=*/true));
82 ASSERT_OK_AND_ASSIGN(f1, registry_->GetFunction("f1"));
83 ASSERT_EQ(Function::SCALAR_AGGREGATE, f1->kind());
84
85 std::vector<std::string> expected_names(func_names);
86 for (auto name : {"f0", "f1"}) {
87 expected_names.push_back(name);
88 }
89 std::sort(expected_names.begin(), expected_names.end());
90 ASSERT_EQ(expected_names, registry_->GetFunctionNames());
91
92 // Aliases
93 ASSERT_RAISES(KeyError, registry_->AddAlias("f33", "f3"));
94 ASSERT_OK(registry_->AddAlias("f11", "f1"));
95 ASSERT_OK_AND_ASSIGN(std::shared_ptr<const Function> f2, registry_->GetFunction("f11"));
96 ASSERT_EQ(func, f2);
97}
98
99// Define a custom print since the default Googletest print trips Valgrind
100void PrintTo(const TestRegistryParams& param, std::ostream* os) {
101 (*os) << "TestRegistryParams{"
102 << "get_num_funcs()=" << std::get<1>(param)() << ", get_func_names()=";
103 for (std::string func_name : std::get<2>(param)()) {
104 (*os) << func_name;
105 }
106 (*os) << ", name=" << std::get<3>(param) << "}";
107}

Callers

nothing calls this directly

Calls 13

UnaryFunction · 0.85
push_backMethod · 0.80
BinaryFunction · 0.70
ASSERT_OK_AND_ASSIGNFunction · 0.70
EmptyClass · 0.50
num_functionsMethod · 0.45
AddFunctionMethod · 0.45
GetFunctionMethod · 0.45
kindMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetFunctionNamesMethod · 0.45

Tested by

no test coverage detected