Skip to content

Commit

Permalink
Add test case for replaceFD issue sbmlteam#299
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeegan committed Mar 3, 2023
1 parent cbca453 commit fcd9e28
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/sbml/test/TestSBMLTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ START_TEST (test_SBMLTransforms_replaceFD)

m = d->getModel();

fail_unless( m->getNumFunctionDefinitions() == 2 );
fail_unless( m->getNumFunctionDefinitions() == 3 );

/* one function definition */
ast = *m->getReaction(2)->getKineticLaw()->getMath();
Expand All @@ -97,6 +97,24 @@ START_TEST (test_SBMLTransforms_replaceFD)
fail_unless (!strcmp(math, "S1 * p * compartmentOne / t"), NULL);
safe_free(math);

/* https://github.com/sbmlteam/libsbml/issues/299 */
/* fd: f_relabelled(p, S1) = p * S1 */
/* ast: f_relabelled(S1, p) * compartmentOne / t */
/* ast after replaceFD: p * p * compartmentOne / t */
ast = *m->getReaction(3)->getKineticLaw()->getMath();

math = SBML_formulaToString(&ast);
fail_unless (!strcmp(math, "f_relabelled(S1, p) * compartmentOne / t"), NULL);
safe_free(math);

fd = m->getFunctionDefinition(2);
SBMLTransforms::replaceFD(&ast, fd);

math = SBML_formulaToString(&ast);
std::cout << "TestSBMLTransforms.cpp:111 " << math << " =?= " << "S1 * p * compartmentOne / t" << std::endl;
fail_unless (!strcmp(math, "S1 * p * compartmentOne / t"), NULL);
safe_free(math);

/* one function definition - nested */
ast = *m->getReaction(1)->getKineticLaw()->getMath();

Expand Down
42 changes: 42 additions & 0 deletions src/sbml/test/test-data/multiple-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
</lambda>
</math>
</functionDefinition>
<functionDefinition id="f_relabelled">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<lambda>
<bvar>
<ci> p </ci>
</bvar>
<bvar>
<ci> S1 </ci>
</bvar>
<apply>
<times/>
<ci> p </ci>
<ci> S1 </ci>
</apply>
</lambda>
</math>
</functionDefinition>
</listOfFunctionDefinitions>
<listOfCompartments>
<compartment id="compartmentOne" size="1"/>
Expand Down Expand Up @@ -124,6 +141,31 @@
</math>
</kineticLaw>
</reaction>
<reaction id="reaction_3_using_f_relabelled" reversible="false" fast="false">
<listOfReactants>
<speciesReference species="S1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="S2"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<divide/>
<apply>
<times/>
<apply>
<ci> f_relabelled </ci>
<ci> S1 </ci>
<ci> p </ci>
</apply>
<ci> compartmentOne </ci>
</apply>
<ci> t </ci>
</apply>
</math>
</kineticLaw>
</reaction>
</listOfReactions>
</model>
</sbml>

0 comments on commit fcd9e28

Please sign in to comment.