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_SBMLDocument_setLevelAndVersion_UnitsError) { SBMLDocument_t *d = SBMLDocument_create(); SBMLDocument_setLevelAndVersionNonStrict(d, 2, 4); Model_t *m1 = SBMLDocument_createModel(d); Compartment_t *c = Model_createCompartment(m1); Compartment_setId(c, "c"); Parameter_t *p = Model_createParameter(m1); Parameter_setId(p, "p"); Parameter_setUnits(p, "mole"); Rule_t * r = Model_createAssignmentRule(m1); Rule_setVariable(r, "c"); Rule_setFormula(r, "p*p"); fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,2,2) == 1); fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,2,3) == 1); fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,1,2) == 1); fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,1,1) == 0); SBMLDocument_free(d); }
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_AlgebraicRule_createWithFormula) { const ASTNode_t *math; char *formula; Rule_t *ar = Rule_createAlgebraic(2, 4); Rule_setFormula(ar, "1 + 1"); fail_unless( SBase_getTypeCode ((SBase_t *) ar) == SBML_ALGEBRAIC_RULE ); fail_unless( SBase_getMetaId ((SBase_t *) ar) == NULL ); 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_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) ); }