diff options
author | Jacques Lucke <jacques@blender.org> | 2020-06-22 16:50:08 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-06-22 16:50:31 +0300 |
commit | c94a1f53499106c095156a23279e9b2083477eec (patch) | |
tree | 99b95146111168fc09e0ce0be40be274eaa6215e /tests/gtests/functions/FN_multi_function_test.cc | |
parent | 6223385043ddc93beaa8f092dfd31a2208b8e961 (diff) |
Functions: add utilities that allow creating some multi-functions with less typing
Diffstat (limited to 'tests/gtests/functions/FN_multi_function_test.cc')
-rw-r--r-- | tests/gtests/functions/FN_multi_function_test.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/gtests/functions/FN_multi_function_test.cc b/tests/gtests/functions/FN_multi_function_test.cc index 8cd9767abcf..12fa17b0d07 100644 --- a/tests/gtests/functions/FN_multi_function_test.cc +++ b/tests/gtests/functions/FN_multi_function_test.cc @@ -18,6 +18,7 @@ #include "FN_cpp_types.hh" #include "FN_multi_function.hh" +#include "FN_multi_function_builder.hh" namespace blender { namespace fn { @@ -218,5 +219,70 @@ TEST(multi_function, GenericAppendFunction) EXPECT_EQ(vectors_ref[3][0], 1); } +TEST(multi_function, CustomFunction_SI_SO) +{ + CustomFunction_SI_SO<std::string, uint> fn("strlen", + [](const std::string &str) { return str.size(); }); + + Array<std::string> strings = {"hello", "world", "test", "another test"}; + Array<uint> sizes(strings.size(), 0); + + MFParamsBuilder params(fn, strings.size()); + params.add_readonly_single_input(strings.as_span()); + params.add_uninitialized_single_output(sizes.as_mutable_span()); + + MFContextBuilder context; + + fn.call(IndexRange(strings.size()), params, context); + + EXPECT_EQ(sizes[0], 5); + EXPECT_EQ(sizes[1], 5); + EXPECT_EQ(sizes[2], 4); + EXPECT_EQ(sizes[3], 12); +} + +TEST(multi_function, CustomFunction_SI_SI_SO) +{ + CustomFunction_SI_SI_SO<int, int, int> fn("mul", [](int a, int b) { return a * b; }); + + Array<int> values_a = {4, 6, 8, 9}; + int value_b = 10; + Array<int> outputs(values_a.size(), -1); + + MFParamsBuilder params(fn, values_a.size()); + params.add_readonly_single_input(values_a.as_span()); + params.add_readonly_single_input(&value_b); + params.add_uninitialized_single_output(outputs.as_mutable_span()); + + MFContextBuilder context; + + fn.call({0, 1, 3}, params, context); + + EXPECT_EQ(outputs[0], 40); + EXPECT_EQ(outputs[1], 60); + EXPECT_EQ(outputs[2], -1); + EXPECT_EQ(outputs[3], 90); +} + +TEST(multi_function, CustomFunction_SM) +{ + CustomFunction_SM<std::string> fn("AddSuffix", [](std::string &value) { value += " test"; }); + + Array<std::string> values = {"a", "b", "c", "d", "e"}; + + MFParamsBuilder params(fn, values.size()); + params.add_single_mutable(values.as_mutable_span()); + + MFContextBuilder context; + + fn.call({1, 2, 3}, params, context); + + EXPECT_EQ(values[0], "a"); + EXPECT_EQ(values[1], "b test"); + EXPECT_EQ(values[2], "c test"); + EXPECT_EQ(values[3], "d test"); + EXPECT_EQ(values[4], "e"); +} + } // namespace fn } // namespace blender |