Skip to content

Commit 65dbd39

Browse files
authored
Skip comments in functional equivalence tests (#2110)
Skip `comment` blocks when checking for functional equivalency as they should not affect the comparison.
1 parent 20383ae commit 65dbd39

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

source/MaterialXCore/Element.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,25 @@ bool Element::isEquivalent(ConstElementPtr rhs, const ElementEquivalenceOptions&
426426
}
427427
}
428428

429-
// Compare children.
430-
const vector<ElementPtr>& children = getChildren();
431-
const vector<ElementPtr>& rhsChildren = rhs->getChildren();
429+
// Compare all child elements that affect functional equivalence.
430+
vector<ElementPtr> children;
431+
for (ElementPtr child : getChildren())
432+
{
433+
if (child->getCategory() == CommentElement::CATEGORY)
434+
{
435+
continue;
436+
}
437+
children.push_back(child);
438+
}
439+
vector <ElementPtr> rhsChildren;
440+
for (ElementPtr child : rhs->getChildren())
441+
{
442+
if (child->getCategory() == CommentElement::CATEGORY)
443+
{
444+
continue;
445+
}
446+
rhsChildren.push_back(child);
447+
}
432448
if (children.size() != rhsChildren.size())
433449
{
434450
if (results)

source/MaterialXTest/MaterialXCore/Document.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ TEST_CASE("Document equivalence", "[document]")
150150
unsigned int index = 0;
151151
mx::ElementPtr child = doc->addNodeGraph("mygraph");
152152
mx::NodeGraphPtr graph = child->asA<mx::NodeGraph>();
153+
// Add comment block at the start of the first doc to check skipping
154+
mx::ElementPtr comment = doc->addChildOfCategory(mx::CommentElement::CATEGORY);
155+
comment->setDocString("Comment 1");
153156
for (auto it = inputMap.begin(); it != inputMap.end(); ++it)
154157
{
155158
const std::string inputType = (*it).first;
@@ -205,6 +208,11 @@ TEST_CASE("Document equivalence", "[document]")
205208
input->setName("input_" + inputType);
206209
}
207210
}
211+
// Add comment blocks at end of second doc to check value and count checks
212+
comment = doc2->addChildOfCategory(mx::CommentElement::CATEGORY);
213+
comment->setDocString("Comment 2");
214+
comment = doc2->addChildOfCategory(mx::CommentElement::CATEGORY);
215+
comment->setDocString("Comment 3");
208216

209217
mx::ElementEquivalenceOptions options;
210218
mx::ElementEquivalenceResultVec results;

0 commit comments

Comments
 (0)