Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-08-27 00:32:04 +0300
committerHans Goudey <h.goudey@me.com>2021-08-27 00:32:04 +0300
commit80429002d7218aaa73ab56a409b94c04becc69b1 (patch)
tree598353b423d134aef07b46e293a3887182631f0d
parent0910b76be3c966d614ddabd3ed37a186dfe4eeb7 (diff)
Add an index input function test
This one fails because `tot_initialized_` is 0 in the procedure evaluator. I'm not quite sure what that means yet.
-rw-r--r--source/blender/functions/tests/FN_field_test.cc51
1 files changed, 48 insertions, 3 deletions
diff --git a/source/blender/functions/tests/FN_field_test.cc b/source/blender/functions/tests/FN_field_test.cc
index 5178b7f5973..3addc054d34 100644
--- a/source/blender/functions/tests/FN_field_test.cc
+++ b/source/blender/functions/tests/FN_field_test.cc
@@ -8,10 +8,9 @@
namespace blender::fn::tests {
-TEST(field, ConstantFieldTest)
+TEST(field, ConstantInput)
{
- std::unique_ptr<CustomMF_Constant<int>> const_fn = std::make_unique<CustomMF_Constant<int>>(10);
- Function function = Function(std::move(const_fn), {});
+ Function function = Function(std::make_unique<CustomMF_Constant<int>>(10), {});
Field constant_field = Field(CPPType::get<int>(), function, 0);
Array<int> result(4);
@@ -24,4 +23,50 @@ TEST(field, ConstantFieldTest)
ASSERT_EQ(result[3], 10);
}
+class IndexFunction : public MultiFunction {
+ public:
+ IndexFunction()
+ {
+ static MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static MFSignature create_signature()
+ {
+ MFSignatureBuilder signature("Index");
+ signature.single_output<int>("Index");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
+ {
+ MutableSpan<int> result = params.uninitialized_single_output<int>(0, "Index");
+ for (int64_t i : mask) {
+ result[i] = i;
+ }
+ }
+};
+
+TEST(field, IndexInput)
+{
+ Function function = Function(std::make_unique<IndexFunction>(), {});
+ Field index_field = Field(CPPType::get<int>(), function, 0);
+
+ Array<int> result_1(4);
+ GMutableSpan result_generic_1(result_1.as_mutable_span());
+ evaluate_fields({&index_field, 1}, IndexMask(IndexRange(4)), {&result_generic_1, 1});
+ ASSERT_EQ(result_1[0], 0);
+ ASSERT_EQ(result_1[1], 1);
+ ASSERT_EQ(result_1[2], 2);
+ ASSERT_EQ(result_1[3], 3);
+
+ Array<int> result_2(4);
+ GMutableSpan result_generic_2(result_2.as_mutable_span());
+ evaluate_fields({&index_field, 1}, {20, 30, 40, 50}, {&result_generic_2, 1});
+ ASSERT_EQ(result_2[0], 20);
+ ASSERT_EQ(result_2[1], 30);
+ ASSERT_EQ(result_2[2], 40);
+ ASSERT_EQ(result_2[3], 50);
+}
+
} // namespace blender::fn::tests