[poincare/multiplication] Fix Multiplication::removeUnit

Scenario:
f(x) = 0->_A
evaluate 0f(0)
This commit is contained in:
Léa Saviot
2020-07-15 14:31:58 +02:00
committed by EmilieNumworks
parent 36bc70aaee
commit 3a046f5bcb
2 changed files with 20 additions and 2 deletions

View File

@@ -264,8 +264,15 @@ Expression Multiplication::removeUnit(Expression * unit) {
if (!currentUnit.isUninitialized()) {
unitMult.addChildAtIndexInPlace(currentUnit, resultChildrenCount, resultChildrenCount);
resultChildrenCount++;
assert(childAtIndex(i).isRationalOne());
removeChildAtIndexInPlace(i--);
if (childAtIndex(i).isRationalOne()) {
removeChildAtIndexInPlace(i--);
} else {
/* If the child was a unit convert, it replaced itself with an undefined
* during the removeUnit. */
assert(childAtIndex(i).isUndefined());
*unit = Expression();
return replaceWithUndefinedInPlace();
}
}
}
if (resultChildrenCount == 0) {

View File

@@ -1317,6 +1317,17 @@ QUIZ_CASE(poincare_simplification_user_function_with_convert) {
Symbol::Builder('x')));
assert_expression_reduce(e);
assert_parsed_expression_simplify_to("e^(f(0))", "undef");
e = Store::Builder(
UnitConvert::Builder(
Rational::Builder(0),
Unit::Second()),
Function::Builder(
"f", 1,
Symbol::Builder('x')));
assert_expression_reduce(e);
assert_parsed_expression_simplify_to("0f(0)", "undef");
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
}