Skip to content

Commit

Permalink
Expressions: Fixed issue #3432; aggregate functions sometimes ignore …
Browse files Browse the repository at this point in the history
…some of their arguments.

Also updated regression tests in Spreadsheet module.
  • Loading branch information
eivindkv authored and wwmayer committed Apr 22, 2018
1 parent e17b340 commit f522116
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/App/Expression.cpp
Expand Up @@ -897,16 +897,13 @@ Expression * FunctionExpression::evalAggregate() const
throw Exception("Invalid property type for aggregate");
} while (range.next());
}
else if (args[i]->isDerivedFrom(App::VariableExpression::getClassTypeId())) {
else {
std::unique_ptr<Expression> e(args[i]->eval());
NumberExpression * n(freecad_dynamic_cast<NumberExpression>(e.get()));

if (n)
c->collect(n->getQuantity());
}
else if (args[i]->isDerivedFrom(App::NumberExpression::getClassTypeId())) {
c->collect(static_cast<NumberExpression*>(args[i])->getQuantity());
}
}

return new NumberExpression(owner, c->getQuantity());
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Spreadsheet/TestSpreadsheet.py
Expand Up @@ -851,6 +851,16 @@ def testIssue3363(self):
self.assertEqual(sheet.getContents('B1'), '=A1 == 1 ? 11 : (A1 == 2 ? 12 : 13)')
self.assertEqual(sheet.getContents('C1'), '=A1 == 1 ? (A1 == 2 ? 12 : 13) : 11')

def testIssue3432(self):
""" Regression test for issue 3432; numbers with units are ignored from aggregates"""
sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet')
sheet.set('A1', '1mm')
sheet.set('B1', '2mm')
sheet.set('C1', '=max(A1:B1;3mm)')
self.doc.recompute()
self.assertEqual(sheet.get('C1'), Units.Quantity('3 mm'))


def tearDown(self):
#closing doc
FreeCAD.closeDocument(self.doc.Name)

0 comments on commit f522116

Please sign in to comment.