[Bf-blender-cvs] [80429002d72] temp-geometry-nodes-fields--fields: Add an index input function test
Hans Goudey
noreply at git.blender.org
Thu Aug 26 23:32:15 CEST 2021
Commit: 80429002d7218aaa73ab56a409b94c04becc69b1
Author: Hans Goudey
Date: Thu Aug 26 16:32:04 2021 -0500
Branches: temp-geometry-nodes-fields--fields
https://developer.blender.org/rB80429002d7218aaa73ab56a409b94c04becc69b1
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.
===================================================================
M source/blender/functions/tests/FN_field_test.cc
===================================================================
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
More information about the Bf-blender-cvs
mailing list