END_TEST START_TEST (test_AssignmentRule_setVariable) { const char *variable = "x"; Rule_setVariable(AR, variable); fail_unless( !strcmp(Rule_getVariable(AR), variable) ); fail_unless( Rule_isSetVariable(AR) ); if (Rule_getVariable(AR) == variable) { fail("Rule_setVariable(...) did not make a copy of string."); } /* Reflexive case (pathological) */ Rule_setVariable(AR, Rule_getVariable(AR)); fail_unless( !strcmp(Rule_getVariable(AR), variable) ); Rule_setVariable(AR, NULL); fail_unless( !Rule_isSetVariable(AR) ); if (Rule_getVariable(AR) != NULL) { fail("Rule_setVariable(AR, NULL) did not clear string."); } }
END_TEST START_TEST (test_ParameterRule_setName) { const char *name = "cell"; const char *c; Rule_setVariable(PR, name); fail_unless( !strcmp(Rule_getVariable(PR), name)); fail_unless( Rule_isSetVariable(PR) ); if (Rule_getVariable(PR) == name) { fail( "ParameterRule_setName(...) did not make a copy of string." ); } /* Reflexive case (pathological) */ c = Rule_getVariable(PR); Rule_setVariable(PR, c); fail_unless( !strcmp(Rule_getVariable(PR), name), NULL ); Rule_setVariable(PR, NULL); fail_unless( !Rule_isSetVariable(PR) ); if (Rule_getVariable(PR) != NULL) { fail( "Rule_setVariable(PR, NULL)" " did not clear string." ); } }
END_TEST START_TEST (test_Rule_setVariable2) { int i = Rule_setVariable(R, "mole"); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( Rule_isSetVariable(R) ); i = Rule_setVariable(R, ""); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( !Rule_isSetVariable(R) ); }
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_Rule_setVariable1) { int i = Rule_setVariable(R, "1mole"); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE); fail_unless( !Rule_isSetVariable(R) ); }
END_TEST START_TEST (test_Rule_setVariable3) { Rule_t *R1 = Rule_createAlgebraic(1, 2); int i = Rule_setVariable(R1, "r"); fail_unless( i == LIBSBML_UNEXPECTED_ATTRIBUTE); fail_unless( !Rule_isSetVariable(R1) ); Rule_free(R1); }
END_TEST START_TEST (test_SpeciesConcentrationRule_setSpecies) { const char *species = "s2"; const char *s; Rule_setVariable(SCR, species); fail_unless( !strcmp(Rule_getVariable(SCR), species), NULL ); fail_unless( Rule_isSetVariable(SCR) ); if (Rule_getVariable(SCR) == species) { fail( "SpeciesConcentrationRule_setSpecies(...)" " did not make a copy of string." ); } /* Reflexive case (pathological) */ s = Rule_getVariable(SCR); Rule_setVariable(SCR, s); fail_unless( !strcmp(Rule_getVariable(SCR), species), NULL ); Rule_setVariable(SCR, NULL); fail_unless( !Rule_isSetVariable(SCR) ); if (Rule_getVariable(SCR) != NULL) { fail( "SpeciesConcentrationRule_setSpecies(SCR, NULL)" " did not clear string." ); } }
END_TEST START_TEST (test_CompartmentVolumeRule_setCompartment) { const char *c; const char *compartment = "cell"; Rule_setVariable(CVR, compartment); fail_unless( !strcmp(Rule_getVariable(CVR), compartment), NULL ); fail_unless( Rule_isSetVariable(CVR) ); if (Rule_getVariable(CVR) == compartment) { fail( "Rule_setVariable(...)" " did not make a copy of string." ); } /* Reflexive case (pathological) */ c = Rule_getVariable(CVR); Rule_setVariable(CVR, c); fail_unless( !strcmp(Rule_getVariable(CVR), compartment), NULL ); Rule_setVariable(CVR, NULL); fail_unless( !Rule_isSetVariable(CVR) ); if (Rule_getVariable(CVR) != NULL) { fail( "Rule_setVariable(CVR, NULL)" " did not clear string." ); } }
END_TEST START_TEST (test_AssignmentRule_createWithMath) { ASTNode_t *math = SBML_parseFormula("1 + 1"); Rule_t *ar = Rule_createAssignment(2, 4); Rule_setVariable(ar, "s"); Rule_setMath(ar, math); 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") ); fail_unless( !strcmp(Rule_getFormula((Rule_t *) ar), "1 + 1") ); fail_unless( Rule_getMath((Rule_t *) ar) != math ); Rule_free(ar); }
END_TEST START_TEST (test_SBMLConvertStrict_convertL1ParamRule) { SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(1, 2); Model_t * m = SBMLDocument_createModel(d); /* create a compartment */ Compartment_t * c = Model_createCompartment(m); Compartment_setId(c, "c"); /* create a parameter */ Parameter_t * p = Model_createParameter(m); Parameter_setId(p, "p"); Parameter_t * p1 = Model_createParameter(m); Parameter_setId(p1, "p1"); /* create a math element */ ASTNode_t *math = SBML_parseFormula("p"); /* create an assignment rule */ Rule_t *ar = Model_createAssignmentRule(m); Rule_setVariable(ar, "p1"); Rule_setMath(ar, math); Rule_setUnits(ar, "mole"); fail_unless( SBMLDocument_setLevelAndVersionStrict(d, 2, 1) == 1 ); fail_unless( SBMLDocument_getLevel (d) == 2, NULL ); fail_unless( SBMLDocument_getVersion(d) == 1, NULL ); Rule_t * r1 = Model_getRule(SBMLDocument_getModel(d), 0); fail_unless (Rule_getUnits(r1) == NULL ); SBMLDocument_free(d); }