END_TEST START_TEST (test_FormulaFormatter_multiAnd) { char *s; ASTNode_t *n = ASTNode_create(); ASTNode_t *c = ASTNode_create(); ASTNode_setType(n, AST_LOGICAL_AND); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "and()"), NULL ); safe_free(s); ASTNode_setName(c, "x"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "and(x)"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "y"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "and(x, y)"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "z"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "and(x, y, z)"), NULL ); safe_free(s); ASTNode_free(n); }
void printEventMath (unsigned int n, Event_t *e) { char *formula; unsigned int i; if ( Event_isSetDelay(e) ) { const Delay_t *delay = Event_getDelay(e); formula = SBML_formulaToString( Delay_getMath(delay) ); printf("Event %d delay: %s\n", n, formula); free(formula); } if ( Event_isSetTrigger(e) ) { const Trigger_t *trigger = Event_getTrigger(e); formula = SBML_formulaToString( Trigger_getMath(trigger) ); printf("Event %d trigger: %s\n", n, formula); free(formula); } for (i = 0; i < Event_getNumEventAssignments(e); ++i) { printEventAssignmentMath(i + 1, Event_getEventAssignment(e, i)); } printf("\n"); }
END_TEST START_TEST (test_FormulaFormatter_multiPlusTimes) { StringBuffer_t *sb = StringBuffer_create(42); char *s = StringBuffer_getBuffer(sb); ASTNode_t *n = ASTNode_create(); ASTNode_t *c = ASTNode_create(); ASTNode_setType(n, AST_PLUS); ASTNode_setName(c, "x"); ASTNode_addChild(n, c); c = ASTNode_create(); ASTNode_setName(c, "y"); ASTNode_addChild(n, c); c = ASTNode_create(); ASTNode_setName(c, "z"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x + y + z"), NULL ); ASTNode_setType(n, AST_TIMES); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x * y * z"), NULL ); safe_free(s); ASTNode_free(n); }
END_TEST START_TEST (test_FormulaFormatter_multiDivide) { StringBuffer_t *sb = StringBuffer_create(42); char *s = StringBuffer_getBuffer(sb); ASTNode_t *n = ASTNode_create(); ASTNode_t *c = ASTNode_create(); ASTNode_setType(n, AST_DIVIDE); s = SBML_formulaToString(n); fail_unless( !strcmp(s, " / "), NULL ); ASTNode_setName(c, "x"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, " / (x)"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "y"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x / y"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "z"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x / y / z"), NULL ); safe_free(s); ASTNode_free(n); }
END_TEST START_TEST (test_FormulaFormatter_multiPlus) { char *s; ASTNode_t *n = ASTNode_create(); ASTNode_t *c = ASTNode_create(); ASTNode_setType(n, AST_PLUS); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "0"), NULL ); safe_free(s); ASTNode_setName(c, "x"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "y"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x + y"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "z"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "x + y + z"), NULL ); safe_free(s); ASTNode_free(n); }
END_TEST START_TEST (test_FormulaFormatter_multiOr) { StringBuffer_t *sb = StringBuffer_create(42); char *s = StringBuffer_getBuffer(sb); ASTNode_t *n = ASTNode_create(); ASTNode_t *c = ASTNode_create(); ASTNode_setType(n, AST_LOGICAL_OR); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "or()"), NULL ); ASTNode_setName(c, "x"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "or(x)"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "y"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "or(x, y)"), NULL ); safe_free(s); c = ASTNode_create(); ASTNode_setName(c, "z"); ASTNode_addChild(n, c); s = SBML_formulaToString(n); fail_unless( !strcmp(s, "or(x, y, z)"), NULL ); safe_free(s); ASTNode_free(n); }
int main(void) { int i; char *formula; variableIndex_t *vi = NULL; odeModel_t *model = ODEModel_createFromFile("basic-model1-forward-l2.xml"); /* Get some information from constructed odeModel */ printf("\n\n"); printf("ODE Model Statistics:\n"); printf("Number of ODEs: %d\n", ODEModel_getNeq(model)); printf("Number of Assignments: %d\n", ODEModel_getNumAssignments(model)); printf("Number of Constants: %d\n", ODEModel_getNumConstants(model)); printf(" ____\n"); printf("Total number of values: %d\n", ODEModel_getNumValues(model)); printf("\n"); printf("ODEs:\n"); for ( i=0; i<ODEModel_getNeq(model); i++ ){ vi = ODEModel_getOdeVariableIndex(model, i); formula = SBML_formulaToString(ODEModel_getOde(model, vi)); printf("d[%s]/dt = %s \n", ODEModel_getVariableName(model, vi), formula); free(formula); VariableIndex_free(vi); } printf("Assigned Variables:\n"); for ( i=0; i<ODEModel_getNumAssignments(model); i++ ){ vi = ODEModel_getAssignedVariableIndex(model, i); formula = SBML_formulaToString(ODEModel_getOde(model, vi)); printf("%s = %s \n", ODEModel_getVariableName(model, vi), formula); free(formula); VariableIndex_free(vi); } printf("Constants:\n"); for ( i=0; i<ODEModel_getNumConstants(model); i++ ){ vi = ODEModel_getConstantIndex(model, i); printf("%s\n", ODEModel_getVariableName(model, vi)); VariableIndex_free(vi); } printf("\n\n"); ODEModel_free(model); return 1; }
void printJacobian(odeModel_t *om, FILE *f) { int i, j; if ( om == NULL ) { fprintf(stderr, "No odeModel available.\n"); return; } if ( om->jacob == NULL ) { fprintf(stderr, "Jacobian Matrix has not been constructed.\n"); return; } fprintf(f, "\n"); fprintf(f, "# Jacobian Matrix:\n"); for ( i=0; i<om->neq; i++ ) { fprintf(f, "# %s: \n", om->names[i]); for ( j=0; j<om->neq; j++ ) { fprintf(f, " (d[%s]/dt)/d[%s] = %s;\n", om->names[i], om->names[j], SBML_formulaToString(om->jacob[i][j])); } } fprintf(f, "\n"); fprintf(stderr, "Use option -j to avoid printing the" " jacobian matrix expressions.\n"); return; }
END_TEST /** * setMathFromFormula() is no longer necessary. LibSBML now keeps formula * strings and math ASTs synchronized automatically. This (now modified) * test is kept around to demonstrate the behavioral change. */ START_TEST (test_KineticLaw_setMathFromFormula) { const char *initial_formula = "k3 / k2"; char* formula; fail_unless( !KineticLaw_isSetMath (kl) ); fail_unless( !KineticLaw_isSetFormula(kl) ); KineticLaw_setFormula(kl, initial_formula); fail_unless( KineticLaw_isSetMath (kl) ); fail_unless( KineticLaw_isSetFormula(kl) ); formula = SBML_formulaToString( KineticLaw_getMath(kl) ); fail_unless( !strcmp(formula, initial_formula) ); safe_free(formula); }
END_TEST START_TEST (test_AssignmentRule_createWithFormula) { const ASTNode_t *math; char *formula; Rule_t *ar = Rule_createAssignment(2, 4); Rule_setVariable(ar, "s"); Rule_setFormula(ar, "1 + 1"); fail_unless( SBase_getTypeCode ((SBase_t *) ar) == SBML_ASSIGNMENT_RULE ); fail_unless( SBase_getMetaId ((SBase_t *) ar) == NULL ); fail_unless( !strcmp(Rule_getVariable(ar), "s") ); math = Rule_getMath((Rule_t *) ar); fail_unless(math != NULL); formula = SBML_formulaToString(math); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "1 + 1") ); fail_unless( !strcmp(Rule_getFormula((Rule_t *) ar), formula) ); Rule_free(ar); safe_free(formula); }
END_TEST START_TEST (test_Rule_setMath1) { ASTNode_t *math = ASTNode_createWithType(AST_TIMES); ASTNode_t *a = ASTNode_create(); ASTNode_t *b = ASTNode_create(); ASTNode_setName(a, "a"); ASTNode_setName(b, "b"); ASTNode_addChild(math, a); ASTNode_addChild(math, b); char *formula; const ASTNode_t *math1; int i = Rule_setMath(R, math); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( Rule_isSetMath(R) ); math1 = Rule_getMath(R); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "a * b") ); ASTNode_free(math); }
END_TEST START_TEST (test_SpeciesReference_setStoichiometryMath) { const ASTNode_t *math = SBML_parseFormula("k3 / k2"); StoichiometryMath_t *stoich = StoichiometryMath_create(2, 4); StoichiometryMath_setMath(stoich, math); const StoichiometryMath_t * math1; char * formula; SpeciesReference_setStoichiometryMath(SR, stoich); math1 = SpeciesReference_getStoichiometryMath(SR); fail_unless( math1 != NULL ); formula = SBML_formulaToString(StoichiometryMath_getMath(math1)); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "k3 / k2") ); fail_unless( SpeciesReference_isSetStoichiometryMath(SR) ); safe_free(formula); }
END_TEST START_TEST (test_AlgebraicRule_createWithFormula) { const ASTNode_t *math; char *formula; AlgebraicRule_t *ar = AlgebraicRule_create(2, 4); AlgebraicRule_setFormula(ar, "1 + 1"); fail_unless( SBase_getTypeCode ((SBase_t *) ar) == SBML_ALGEBRAIC_RULE ); fail_unless( SBase_getMetaId ((SBase_t *) ar) == NULL ); math = AlgebraicRule_getMath(ar); fail_unless(math != NULL); formula = SBML_formulaToString(math); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "1 + 1") ); fail_unless( !strcmp(AlgebraicRule_getFormula(ar), formula) ); AlgebraicRule_free(ar); safe_free(formula); }
int main (int argc, char *argv[]){ int i, j; char *model; double time; double printstep; /* libSBML types */ SBMLDocument_t *d; SBMLReader_t *sr; Model_t *m; Reaction_t *r; KineticLaw_t *kl; ASTNode_t *nary; ASTNode_t *diff; /* SOSlib types */ SBMLResults_t *results; timeCourse_t *tc; cvodeSettings_t *set; /* parsing command-line arguments */ if (argc < 4 ) { fprintf(stderr, "usage %s sbml-model-file simulation-time time-steps\n", argv[0]); exit(EXIT_FAILURE); } model = argv[1]; time = atof(argv[2]); printstep = atoi(argv[3]); /* parsing the SBML model with libSBML */ sr = SBMLReader_create(); d = SBMLReader_readSBML(sr, model); SBMLReader_free(sr); m = SBMLDocument_getModel(d); r = Model_getReaction(m,0); kl = Reaction_getKineticLaw(r); nary = KineticLaw_getMath(kl); printf("N-ary formula: %s\n", SBML_formulaToString(nary)); diff = differentiateAST(nary, "Product"); printf("N-ary diff: %s\n", SBML_formulaToString(diff)); ASTNode_free(diff); return (EXIT_SUCCESS); }
void printOdes_fromFile(char* filename) { if (filename == NULL) return; int i; char *formula; variableIndex_t *vi = NULL; odeModel_t *model = ODEModel_createFromFile(filename); if (model == NULL) { printf("create odemodel fails:\n"); return; } /* Get some information from constructed odeModel */ printf("\n\n"); printf("ODE Model Statistics:\n"); printf("Number of ODEs: %d\n", ODEModel_getNeq(model)); printf("Number of Assignments: %d\n", ODEModel_getNumAssignments(model)); printf("Number of Constants: %d\n", ODEModel_getNumConstants(model)); printf(" ____\n"); printf("Total number of values: %d\n", ODEModel_getNumValues(model)); printf("\n"); printf("ODEs:\n"); for ( i=0; i<ODEModel_getNeq(model); i++ ){ vi = ODEModel_getOdeVariableIndex(model, i); formula = SBML_formulaToString(ODEModel_getOde(model, vi)); printf("d[%s]/dt = %s \n", ODEModel_getVariableName(model, vi), formula); free(formula); VariableIndex_free(vi); } // printf("Assigned Variables:\n"); // for ( i=0; i<ODEModel_getNumAssignments(model); i++ ){ // vi = ODEModel_getAssignedVariableIndex(model, i); // formula = SBML_formulaToString(ODEModel_getOde(model, vi)); // printf("%s = %s \n", ODEModel_getVariableName(model, vi), formula); // free(formula); // VariableIndex_free(vi); // } printf("Constants:\n"); for ( i=0; i<ODEModel_getNumConstants(model); i++ ){ vi = ODEModel_getConstantIndex(model, i); printf("%s\n", ODEModel_getVariableName(model, vi)); VariableIndex_free(vi); } printf("\n\n"); ODEModel_free(model); }
END_TEST START_TEST (test_FunctionDefinition_setMath) { ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)"); const ASTNode_t * math1; char * formula; FunctionDefinition_setMath(FD, math); math1 = FunctionDefinition_getMath(FD); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( FunctionDefinition_getMath(FD) != math ); fail_unless( FunctionDefinition_isSetMath(FD) ); fail_unless( FunctionDefinition_isSetBody(FD) ); /* Reflexive case (pathological) */ FunctionDefinition_setMath(FD, (ASTNode_t *) FunctionDefinition_getMath(FD)); math1 = FunctionDefinition_getMath(FD); fail_unless( math1 != NULL ); safe_free(formula); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( FunctionDefinition_getMath(FD) != math ); FunctionDefinition_setMath(FD, NULL); fail_unless( !FunctionDefinition_isSetMath(FD) ); fail_unless( !FunctionDefinition_isSetBody(FD) ); if (FunctionDefinition_getMath(FD) != NULL) { fail("FunctionDefinition_setMath(FD, NULL) did not clear ASTNode."); } ASTNode_free(math); safe_free(formula); }
END_TEST START_TEST (test_EventAssignment_setMath) { ASTNode_t *math = SBML_parseFormula("2 * k"); char *formula; const ASTNode_t *math1; EventAssignment_setMath(EA, math); math1 = EventAssignment_getMath(EA); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "2 * k") ); safe_free(formula); fail_unless( EventAssignment_getMath(EA) != math); fail_unless( EventAssignment_isSetMath(EA) ); /* Reflexive case (pathological) */ EventAssignment_setMath(EA, (ASTNode_t *) EventAssignment_getMath(EA)); math1 = EventAssignment_getMath(EA); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "2 * k") ); fail_unless( EventAssignment_getMath(EA) != math ); safe_free(formula); EventAssignment_setMath(EA, NULL); fail_unless( !EventAssignment_isSetMath(EA) ); if (EventAssignment_getMath(EA) != NULL) { fail("EventAssignment_setMath(EA, NULL) did not clear ASTNode."); } ASTNode_free(math); }
END_TEST START_TEST (test_KineticLaw_setMath) { ASTNode_t *math = SBML_parseFormula("k3 / k2"); char *formula; const ASTNode_t *math1; KineticLaw_setMath(kl, math); math1 = KineticLaw_getMath(kl); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "k3 / k2") ); fail_unless( KineticLaw_getMath(kl) != math ); fail_unless( KineticLaw_isSetMath(kl) ); safe_free(formula); /* Reflexive case (pathological) */ KineticLaw_setMath(kl, (ASTNode_t *) KineticLaw_getMath(kl)); math1 = KineticLaw_getMath(kl); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "k3 / k2") ); fail_unless( KineticLaw_getMath(kl) != math ); safe_free(formula); KineticLaw_setMath(kl, NULL); fail_unless( !KineticLaw_isSetMath(kl) ); if (KineticLaw_getMath(kl) != NULL) { fail( "KineticLaw_setMath(kl, NULL) did not clear ASTNode." ); } ASTNode_free(math); }
END_TEST START_TEST (test_SBML_formulaToString) { const char *formulae[] = { "1", "2.1", #if defined(WIN32) && !defined(CYGWIN) #if _MSC_VER < 1900 "2.100000e-010", #else "2.100000e-10", #endif #else "2.100000e-10", #endif "foo", "1 + foo", "1 + 2", "1 + 2 * 3", "(1 - 2) * 3", "1 + -2 / 3", "1 + -2.000000e-100 / 3", "1 - -foo / 3", "2 * foo^bar + 3.1", "foo()", "foo(1)", "foo(1, bar)", "foo(1, bar, 2^-3)", "a / b * c", "a / (b * c)", "1 + 2 + 3", "pow(x, y)", "" }; ASTNode_t *n; char *s; int i; for (i = 0; i < *formulae[i]; i++) { n = SBML_parseFormula( formulae[i] ); s = SBML_formulaToString(n); fail_unless( !strcmp(s, formulae[i]), NULL ); ASTNode_free(n); safe_free(s); } }
END_TEST START_TEST (test_Priority_setMath) { ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)"); const ASTNode_t * math1; char * formula; Priority_setMath(P, math); math1 = Priority_getMath(P); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( Priority_getMath(P) != math ); fail_unless( Priority_isSetMath(P) ); safe_free(formula); /* Reflexive case (pathological) */ Priority_setMath(P, (ASTNode_t *) Priority_getMath(P)); math1 = Priority_getMath(P); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); safe_free(formula); Priority_setMath(P, NULL); fail_unless( !Priority_isSetMath(P) ); if (Priority_getMath(P) != NULL) { fail("Priority_setMath(P, NULL) did not clear ASTNode."); } ASTNode_free(math); }
END_TEST START_TEST (test_StoichiometryMath_setMath) { ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)"); const ASTNode_t * math1; char * formula; StoichiometryMath_setMath(D, math); math1 = StoichiometryMath_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( StoichiometryMath_getMath(D) != math ); fail_unless( StoichiometryMath_isSetMath(D) ); safe_free(formula); /* Reflexive case (pathological) */ StoichiometryMath_setMath(D, (ASTNode_t *) StoichiometryMath_getMath(D)); math1 = StoichiometryMath_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); safe_free(formula); StoichiometryMath_setMath(D, NULL); fail_unless( !StoichiometryMath_isSetMath(D) ); if (StoichiometryMath_getMath(D) != NULL) { fail("StoichiometryMath_setMath(D, NULL) did not clear ASTNode."); } ASTNode_free(math); }
/** * Translates the given MathML into an infix formula. The MathML must * contain no leading whitespace, but an XML header is optional. * * @return the infix formula as a string. The caller owns the memory and * is responsible for freeing it. */ char * translateMathML (const char* xml) { char* result; ASTNode_t* math; math = readMathMLFromString(xml); result = SBML_formulaToString(math); ASTNode_free(math); return result; }
SBML_ODESOLVER_API int IntegratorInstance_checkTrigger(integratorInstance_t *engine) { int i, j, fired; ASTNode_t *trigger, *assignment; Event_t *e; EventAssignment_t *ea; variableIndex_t *vi; cvodeSettings_t *opt = engine->opt; cvodeData_t *data = engine->data; odeModel_t *om = engine->om; fired = 0; for ( i=0; i<Model_getNumEvents(om->simple); i++ ) { e = Model_getEvent(om->simple, i); trigger = (ASTNode_t *) Event_getTrigger(e); if ( data->trigger[i] == 0 && evaluateAST(trigger, data) ) { if (opt->HaltOnEvent) SolverError_error(ERROR_ERROR_TYPE, SOLVER_ERROR_EVENT_TRIGGER_FIRED, "Event Trigger %d (%s) fired at time %g. " "Aborting simulation.", i, SBML_formulaToString(trigger), data->currenttime); /* removed AMF 08/11/05 else SolverError_error(WARNING_ERROR_TYPE, SOLVER_ERROR_EVENT_TRIGGER_FIRED, "Event Trigger %d (%s) fired at time %g. ", i, SBML_formulaToString(trigger), data->currenttime); */ fired++; data->trigger[i] = 1; for ( j=0; j<Event_getNumEventAssignments(e); j++ ) { ea = Event_getEventAssignment(e, j); assignment = (ASTNode_t *) EventAssignment_getMath(ea); vi = ODEModel_getVariableIndex(om, EventAssignment_getVariable(ea)); IntegratorInstance_setVariableValue(engine, vi, evaluateAST(assignment, data)); VariableIndex_free(vi); } } else { data->trigger[i] = 0; } } return fired; }
void printRuleMath (unsigned int n, const Rule_t *r) { char *formula; if ( Rule_isSetMath(r) ) { formula = SBML_formulaToString( Rule_getMath(r) ); printf("Rule %d, formula: %s\n", n, formula); free(formula); } }
END_TEST START_TEST (test_Trigger_setMath) { ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)"); const ASTNode_t * math1; char * formula; Trigger_setMath(D, math); math1 = Trigger_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); fail_unless( Trigger_getMath(D) != math ); fail_unless( Trigger_isSetMath(D) ); /* Reflexive case (pathological) */ Trigger_setMath(D, (ASTNode_t *) Trigger_getMath(D)); math1 = Trigger_getMath(D); fail_unless( math1 != NULL ); formula = SBML_formulaToString(math1); fail_unless( formula != NULL ); fail_unless( !strcmp(formula, "lambda(x, x^3)") ); Trigger_setMath(D, NULL); fail_unless( !Trigger_isSetMath(D) ); if (Trigger_getMath(D) != NULL) { fail("Trigger_setMath(D, NULL) did not clear ASTNode."); } }
void printODEs(odeModel_t *model, FILE *f) { int i, nvalues; char *formel; nvalues = model->neq+model->nass + model->nconst; fprintf(f, "\n"); fprintf(f, "# Derived system of Ordinary Differential Equations (ODEs):\n"); fprintf(f, "# Parameters:\n"); for ( i=model->neq+model->nass; i<nvalues; i++ ) fprintf(f, "%s, ", model->names[i]); printf("\n"); fprintf(f, "# Assigned Parameters:\n"); for ( i=0; i<model->nass; i++ ) { formel = SBML_formulaToString(model->assignment[i]); fprintf(f, "%d: %s = %s;\n", i+1, model->names[model->neq+i], formel); free(formel); } for ( i=0; i<model->neq; i++ ) { if ( i == 0 ) { fprintf(f, "# ODEs:\n"); } formel = SBML_formulaToString(model->ode[i]); fprintf(f, "%d: d%s/dt = %s;\n", i+1, model->names[i], formel); free(formel); } fprintf(f, "\n"); /* change in behaviour AMF 27th June 05 if ( data->errors>0 ) { fprintf(f, "# %d ODEs could not be constructed." " Try to add or correct kinetic laws!\n", data->errors); }*/ return; }
END_TEST START_TEST (test_parse_function_selector_0args) { ASTNode_t *r = new ASTNode(AST_LINEAR_ALGEBRA_SELECTOR); char* roundtrip = SBML_formulaToL3String(r); fail_unless( !strcmp(roundtrip, "selector()") ); char* oldroundtrip = SBML_formulaToString(r); fail_unless( !strcmp(oldroundtrip, "selector()") ); delete r; delete roundtrip; delete oldroundtrip; }
END_TEST START_TEST (test_parse_function_matrix_emptyrows) { ASTNode_t *r = SBML_parseL3Formula("matrix(matrixrow(), matrixrow())"); char* roundtrip = SBML_formulaToL3String(r); fail_unless( !strcmp(roundtrip, "matrix(matrixrow(), matrixrow())") ); char* oldroundtrip = SBML_formulaToString(r); fail_unless( !strcmp(oldroundtrip, "matrix(matrixrow(), matrixrow())") ); delete r; delete roundtrip; delete oldroundtrip; }
END_TEST START_TEST (test_parse_brackets_2args) { ASTNode_t *r = SBML_parseL3Formula("a[x, y]"); char* roundtrip = SBML_formulaToL3String(r); fail_unless( !strcmp(roundtrip, "a[x, y]") ); char* oldroundtrip = SBML_formulaToString(r); fail_unless( !strcmp(oldroundtrip, "selector(a, x, y)") ); delete r; delete roundtrip; delete oldroundtrip; }
END_TEST START_TEST (test_parse_function_vector_2args) { ASTNode_t *r = SBML_parseL3Formula("vector(a+b, x^y)"); char* roundtrip = SBML_formulaToL3String(r); fail_unless( !strcmp(roundtrip, "{a + b, x^y}") ); char* oldroundtrip = SBML_formulaToString(r); fail_unless( !strcmp(oldroundtrip, "vector(a + b, x^y)") ); delete r; delete roundtrip; delete oldroundtrip; }