mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/parametered_expression] Fix variables detection
The method getVariables would not correctly remove the parameter from the list of variables. e.g. In the expression "box+y×int(z,x,0,1)", when trying to remove x from the list of variables, the letter x would be removed from the name "box" instead.
This commit is contained in:
committed by
EmilieNumworks
parent
fff514d410
commit
48d93584e7
@@ -22,13 +22,16 @@ int ParameteredExpressionNode::getVariables(Context * context, isVariableTest is
|
||||
/* Remove the parameter symbol from the list of variable if it was added at
|
||||
* the previous line */
|
||||
const char * parameterName = ParameteredExpression(this).parameter().name();
|
||||
for (int i = nextVariableIndex; i < numberOfVariables; i++) {
|
||||
if (strcmp(parameterName, &variables[i]) == 0) {
|
||||
variables[i] = 0;
|
||||
for (int index = nextVariableIndex * maxSizeVariable; index < numberOfVariables * maxSizeVariable; index += maxSizeVariable) {
|
||||
if (strcmp(parameterName, &variables[index]) == 0) {
|
||||
memmove(&variables[index], &variables[index + maxSizeVariable], (numberOfVariables - nextVariableIndex) * maxSizeVariable);
|
||||
numberOfVariables--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (numberOfVariables < Expression::k_maxNumberOfVariables) {
|
||||
variables[numberOfVariables * maxSizeVariable] = '\0';
|
||||
}
|
||||
nextVariableIndex = numberOfVariables;
|
||||
static_assert(ParameteredExpression::ParameteredChildIndex() == 0 && ParameteredExpression::ParameterChildIndex() == 1,
|
||||
"ParameteredExpression::getVariables might not be valid");
|
||||
|
||||
@@ -346,6 +346,11 @@ QUIZ_CASE(poincare_properties_get_variables) {
|
||||
assert_expression_has_variables("diff(3x,x,0)y-2", variableBuffer8, 1);
|
||||
const char * variableBuffer9[] = {"a", "b", "c", "d", "e", "f"};
|
||||
assert_expression_has_variables("a+b+c+d+e+f", variableBuffer9, 6);
|
||||
|
||||
const char * variableBuffer10[] = {"c", "z", "a", "b", ""};
|
||||
assert_expression_has_variables("int(c×x×z, x, a, b)", variableBuffer10, 4);
|
||||
const char * variableBuffer11[] = {"box", "y", "z", "a", ""};
|
||||
assert_expression_has_variables("box+y×int(z,x,a,0)", variableBuffer11, 4);
|
||||
}
|
||||
|
||||
void assert_reduced_expression_has_polynomial_coefficient(const char * expression, const char * symbolName, const char ** coefficients, Preferences::ComplexFormat complexFormat = Cartesian, Preferences::AngleUnit angleUnit = Radian, Preferences::UnitFormat unitFormat = Metric, ExpressionNode::SymbolicComputation symbolicComputation = ReplaceAllDefinedSymbolsWithDefinition) {
|
||||
|
||||
Reference in New Issue
Block a user