END_TEST START_TEST (test_Rule_setFormula) { const char *formula = "k1*X0"; Rule_setFormula(R, formula); fail_unless( !strcmp(Rule_getFormula(R), formula) ); fail_unless( Rule_isSetFormula(R) == 1 ); if (Rule_getFormula(R) == formula) { fail("Rule_setFormula(...) did not make a copy of string."); } /* Reflexive case (pathological) */ Rule_setFormula(R, Rule_getFormula(R)); fail_unless( !strcmp(Rule_getFormula(R), formula) ); Rule_setFormula(R, ""); fail_unless( Rule_isSetFormula(R) == 0 ); if (Rule_getFormula(R) != NULL) { fail("Rule_setFormula(R, NULL) did not clear string."); } }
END_TEST START_TEST (test_Rule_setFormula2) { int i = Rule_setFormula(R, NULL); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( !Rule_isSetFormula(R) ); }
END_TEST START_TEST (test_Rule_setFormula3) { const char *formula = "k1 X0"; int i = Rule_setFormula(R, formula); fail_unless( i == LIBSBML_INVALID_OBJECT); fail_unless( !Rule_isSetFormula(R) ); }
void printReactions(Model_t *m, FILE *f) { int i,j,k; Reaction_t *r; SpeciesReference_t *sref; KineticLaw_t *kl; Rule_t *rl; AssignmentRule_t *asr; AlgebraicRule_t *alr; RateRule_t *rr; Event_t *e; EventAssignment_t *ea; Parameter_t *p; FunctionDefinition_t *fd; SBMLTypeCode_t type; const ASTNode_t *math; math = NULL; fprintf(f, "\n"); for(i=0;i<Model_getNumParameters(m);i++){ if(i==0) fprintf(f, "# Global parameters:\n"); p = Model_getParameter(m,i); if(Parameter_isSetId(p)) fprintf(f, "%s ", Parameter_getId(p)); if(Parameter_isSetName(p)) fprintf(f, "(%s) ", Parameter_getName(p)); if(Parameter_isSetValue(p)) fprintf(f, "= %g; ", Parameter_getValue(p)); if(Parameter_isSetUnits(p)) fprintf(f, "[%s]; ", Parameter_getUnits(p)); if(!Parameter_getConstant(p)) fprintf(f, "(variable);"); fprintf(f, "\n"); if ( i==Model_getNumParameters(m)-1 ) fprintf(f, "\n"); } fprintf(f, "# Reactions:\n"); for ( i=0; i<Model_getNumReactions(m); i++ ) { r = Model_getReaction(m,i); fprintf(f, "%s: %s", Reaction_isSetName(r) ? Reaction_getName(r) : Reaction_getId(r), Reaction_getFast(r) ? "(fast)" : ""); for ( k=0; k<Reaction_getNumReactants(r); k++ ) { sref = Reaction_getReactant(r,k); if ( SpeciesReference_isSetStoichiometryMath(sref) ) fprintf(f, "%s ", SBML_formulaToString(\ SpeciesReference_getStoichiometryMath(sref))); else if ( SpeciesReference_getStoichiometry(sref) != 1. ) fprintf(f, "%g ", SpeciesReference_getStoichiometry(sref)); fprintf(f, "%s", SpeciesReference_getSpecies(sref)); if(k+1<Reaction_getNumReactants(r)) fprintf(f, "%s", " + "); } fprintf(f, "%s", Reaction_getReversible(r) ? " <-> " : " -> "); for ( k=0; k<Reaction_getNumProducts(r); k++ ) { sref = Reaction_getProduct(r,k); if ( SpeciesReference_isSetStoichiometryMath(sref) ) fprintf(f, "%s ", SBML_formulaToString(\ SpeciesReference_getStoichiometryMath(sref))); else if ( SpeciesReference_getStoichiometry(sref) != 1. ) fprintf(f, "%g ", SpeciesReference_getStoichiometry(sref)); fprintf(f, "%s", SpeciesReference_getSpecies(sref)); if(k+1<Reaction_getNumProducts(r)) fprintf(f, "%s", " + "); } fprintf(f, "; "); if(Reaction_isSetKineticLaw(r)){ kl = Reaction_getKineticLaw(r); math = KineticLaw_getMath(kl); fprintf(f, "%s;", SBML_formulaToString(math)); for(k=0;k<KineticLaw_getNumParameters(kl);k++){ p = KineticLaw_getParameter(kl,k); fprintf(f, " %s", Parameter_getId(p)); if(Parameter_isSetName(p)) fprintf(f, " (%s)", Parameter_getName(p)); if(Parameter_isSetValue(p)) fprintf(f, " = %g", Parameter_getValue(p)); if(Parameter_isSetUnits(p)) fprintf(f, " [%s]", Parameter_getUnits(p)); if ( !Parameter_getConstant(p) ) fprintf(f, " (variable)"); fprintf(f, ";"); } /* fprintf(f, "\n"); */ }else fprintf(f, "# no rate law is set for this reaction."); fprintf(f, "\n"); } for(i=0;i<Model_getNumRules(m);i++){ rl = Model_getRule(m,i); if ( i == 0 ) { fprintf(f, "# Rules:\n"); } type = SBase_getTypeCode((SBase_t *)rl); if ( type == SBML_RATE_RULE ) { rr = (RateRule_t *) rl; fprintf(f, " rateRule: d%s/dt = ", RateRule_getVariable(rr)); } if ( type == SBML_ALGEBRAIC_RULE ) { alr = (AlgebraicRule_t *) rl; fprintf(f, " algebraicRule: 0 = "); } if ( type == SBML_ASSIGNMENT_RULE ) { asr = (AssignmentRule_t *) rl; fprintf(f, " assignmentRule (%s): %s = ", RuleType_toString(AssignmentRule_getType(asr)), AssignmentRule_getVariable(asr)); } if(!Rule_isSetMath(rl)){ if(Rule_isSetFormula(rl)){ Rule_setMathFromFormula(rl); } } if(Rule_isSetMath(rl)) fprintf(f, "%s\n", SBML_formulaToString(Rule_getMath(rl))); } fprintf(f, "\n"); for(i=0;i<Model_getNumEvents(m);i++){ if(i==0) fprintf(f, "# Events:\n"); e = Model_getEvent(m,i); if(Event_isSetId(e)) fprintf(f, "%s: ", Event_getId(e)); if(Event_isSetName(e)) fprintf(f, "(%s) ", Event_getName(e)); if(Event_isSetTrigger(e)) { math = Event_getTrigger(e); fprintf(f, "trigger: %s\n", SBML_formulaToString(math)); } if(Event_isSetDelay(e)) fprintf(f, "delay: %s;\n", SBML_formulaToString(Event_getDelay(e))); if(Event_isSetTimeUnits(e)) fprintf(f, "time Units: %s;\n", Event_getTimeUnits(e)); for(k=0;k<Event_getNumEventAssignments(e);k++){ ea = Event_getEventAssignment(e,k); if(EventAssignment_isSetVariable(ea)) fprintf(f, " event: %s = %s;\n", EventAssignment_getVariable(ea), EventAssignment_isSetMath(ea) ? SBML_formulaToString(EventAssignment_getMath(ea)) : "# no math set;\n"); } if(i==Model_getNumEvents(m)-1) fprintf(f, "\n"); } for ( i=0; i<Model_getNumFunctionDefinitions(m); i++ ) { if ( i==0 ) fprintf(f, "# Functions:\n"); fd = Model_getFunctionDefinition(m,i); if ( FunctionDefinition_isSetName(fd) ) fprintf(f, "%s: ", FunctionDefinition_getName(fd)); if(FunctionDefinition_isSetId(fd) && FunctionDefinition_isSetMath(fd)){ fprintf(f, "%s( ", FunctionDefinition_getId(fd)); math = FunctionDefinition_getMath(fd); for(j=0;j<ASTNode_getNumChildren(math)-1;j++){ fprintf(f, "%s", SBML_formulaToString(ASTNode_getChild(math, j))); if(j<ASTNode_getNumChildren(math)-2) fprintf(f, ", "); if(j==ASTNode_getNumChildren(math)-2) fprintf(f, ") = "); } fprintf(f, "%s;", SBML_formulaToString(ASTNode_getRightChild(math))); } fprintf(f, "\n"); } }