Commit 5b7c08b9 authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Re #17176. Fixed division and single tie with brackets.

parent f99c4758
......@@ -495,6 +495,8 @@ std::string Expression::str() const {
brackets = true;
} else if (m_op == "-" && m_funct == "+") {
brackets = true;
} else if (m_op == "/" && m_funct == "*") {
brackets = true;
}
if (!m_terms.empty()) {
......
......@@ -113,9 +113,9 @@ IFunction_sptr FunctionFactoryImpl::createSimple(
fun->setAttribute(parName, att);
} else if (parName.size() >= 10 && parName.substr(0, 10) == "constraint") {
// or it can be a list of constraints
addConstraints(fun, (*term)[1]);
addConstraints(fun, (*term)[1].bracketsRemoved());
} else if (parName == "ties") {
addTies(fun, (*term)[1]);
addTies(fun, (*term)[1].bracketsRemoved());
} else if (!parName.empty() && parName[0] == '$') {
parName.erase(0, 1);
parentAttributes[parName] = parValue;
......@@ -213,10 +213,10 @@ CompositeFunction_sptr FunctionFactoryImpl::createComposite(
} else {
std::string parName = term[0].name();
if (parName.size() >= 10 && parName.substr(0, 10) == "constraint") {
addConstraints(cfun, term[1]);
addConstraints(cfun, term[1].bracketsRemoved());
continue;
} else if (parName == "ties") {
addTies(cfun, term[1]);
addTies(cfun, term[1].bracketsRemoved());
continue;
} else {
fun = createSimple(term, pAttributes);
......
......@@ -401,6 +401,13 @@ public:
TS_ASSERT_EQUALS(e[1].name(), ",");
}
void test_tie_expression_with_brackets_1() {
Expression e;
e.parse("ties=(a0 = 2, Height = Sigma/(0.5 * 0.5))");
TS_ASSERT_EQUALS(e.str(), "ties=(a0=2,Height=Sigma/(0.5*0.5))");
TS_ASSERT_EQUALS(e[1].name(), ",");
}
void test_bad_brackets() {
Expression e;
try {
......
......@@ -353,6 +353,16 @@ public:
TS_ASSERT_EQUALS(funa->getParameter("a1"), 16);
}
void testCreateWithTies4() {
std::string fnString =
"name=FunctionFactoryTest_FunctA,ties=(a0=2,a1=a0/(2*2))";
IFunction_sptr funa =
FunctionFactory::Instance().createInitialized(fnString);
TS_ASSERT(funa);
TS_ASSERT_EQUALS(funa->getParameter("a0"), 2);
TS_ASSERT_EQUALS(funa->getParameter("a1"), 0.5);
}
void testCreateCompositeWithTies() {
std::string fnString = "name=FunctionFactoryTest_FunctA,ties=(a0=a1=14);"
"name=FunctionFactoryTest_FunctB,b0=0.2,b1=1.2;ties="
......@@ -387,6 +397,20 @@ public:
TS_ASSERT_EQUALS(fun1->getParameter(3), 789);
}
void testCreateCompositeWithTies1() {
std::string fnString = "name=FunctionFactoryTest_FunctA,ties=(a0=a1=16);"
"name=FunctionFactoryTest_FunctB,b0=0.2,b1=1.2;ties="
"(f1.b1=f0.a1/(2*2))";
IFunction_sptr fun =
FunctionFactory::Instance().createInitialized(fnString);
TS_ASSERT(fun);
TS_ASSERT_EQUALS(fun->getParameter(0), 16.);
TS_ASSERT_EQUALS(fun->getParameter(1), 16.);
TS_ASSERT_EQUALS(fun->getParameter(2), 0.2);
TS_ASSERT_EQUALS(fun->getParameter(3), 4.);
}
void test_MultiDomainFunction_creation() {
const std::string fnString = "composite=MultiDomainFunction;"
"name=FunctionFactoryTest_FunctA;"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment