END_TEST START_TEST (test_SpeciesReference_setStoichiometryMath5) { SpeciesReference_t *sr1 = SpeciesReference_create(1, 2); StoichiometryMath_t * sm = StoichiometryMath_create(2, 4); 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); StoichiometryMath_setMath(sm, math); int i = SpeciesReference_setStoichiometryMath(sr1, sm); fail_unless( i == LIBSBML_UNEXPECTED_ATTRIBUTE); fail_unless( !SpeciesReference_isSetStoichiometryMath(sr1) ); StoichiometryMath_free(sm); SpeciesReference_free(sr1); }
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_SpeciesReference_setStoichiometryMath1) { StoichiometryMath_t * sm = StoichiometryMath_create(2, 4); 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); StoichiometryMath_setMath(sm, math); int i = SpeciesReference_setStoichiometryMath(sr, sm); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( SpeciesReference_isSetStoichiometryMath(sr) ); fail_unless( SpeciesReference_getStoichiometry(sr) == 1 ); i = SpeciesReference_unsetStoichiometryMath(sr); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( !SpeciesReference_isSetStoichiometryMath(sr) ); StoichiometryMath_free(sm); }
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); }
END_TEST START_TEST (test_StoichiometryMath_setMath1) { ASTNode_t *math = SBML_parseFormula("2 * k"); int i = StoichiometryMath_setMath(D, math); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( StoichiometryMath_getMath(D) != math ); fail_unless( StoichiometryMath_isSetMath(D) ); i = StoichiometryMath_setMath(D, NULL); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( StoichiometryMath_getMath(D) == NULL ); fail_unless( !StoichiometryMath_isSetMath(D) ); ASTNode_free(math); }
END_TEST START_TEST (test_StoichiometryMath_setMath2) { ASTNode_t *math = ASTNode_createWithType(AST_DIVIDE); int i = StoichiometryMath_setMath(D, math); fail_unless( i == LIBSBML_INVALID_OBJECT); fail_unless( !StoichiometryMath_isSetMath(D) ); ASTNode_free(math); }
END_TEST START_TEST (test_SBMLConvert_convertToL3_stoichiometryMath) { SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(2, 1); Model_t *m = SBMLDocument_createModel(d); Compartment_t *c = Model_createCompartment(m); Compartment_setId ( c, "c" ); Species_t *s = Model_createSpecies(m); Species_setId(s, "s"); Species_setCompartment(s, "c"); Reaction_t * r = Model_createReaction(m); SpeciesReference_t *sr = Reaction_createReactant(r); SpeciesReference_setSpecies(sr, "s"); StoichiometryMath_t *sm = SpeciesReference_createStoichiometryMath(sr); ASTNode_t * ast = SBML_parseFormula("c*2"); StoichiometryMath_setMath(sm, ast); fail_unless(Model_getNumRules(m) == 0); fail_unless(SpeciesReference_isSetId(sr) == 0); fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 3, 1) == 1); m = SBMLDocument_getModel(d); r = Model_getReaction(m, 0); sr = Reaction_getReactant(r, 0); fail_unless(Model_getNumRules(m) == 1); fail_unless(SpeciesReference_isSetId(sr) == 1); Rule_t *rule = Model_getRule(m, 0); fail_unless( strcmp(SpeciesReference_getId(sr), Rule_getVariable(rule)) == 0 ); SBMLDocument_free(d); }
END_TEST START_TEST (test_SpeciesReference_setStoichiometryMath4) { StoichiometryMath_t * sm = StoichiometryMath_create(2, 4); ASTNode_t *math = NULL; StoichiometryMath_setMath(sm, math); int i = SpeciesReference_setStoichiometryMath(sr, sm); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( SpeciesReference_isSetStoichiometryMath(sr) ); fail_unless( SpeciesReference_getStoichiometry(sr) == 1 ); i = SpeciesReference_unsetStoichiometryMath(sr); fail_unless( i == LIBSBML_OPERATION_SUCCESS); fail_unless( !SpeciesReference_isSetStoichiometryMath(sr) ); StoichiometryMath_free(sm); }
END_TEST START_TEST (test_SpeciesReference_setStoichiometryMath2) { StoichiometryMath_t * sm = StoichiometryMath_create(2, 4); ASTNode_t *math = ASTNode_createWithType(AST_TIMES); ASTNode_t *a = ASTNode_create(); ASTNode_setName(a, "a"); ASTNode_addChild(math, a); StoichiometryMath_setMath(sm, math); int i = SpeciesReference_setStoichiometryMath(sr, sm); /* once the StoichiometryMath_setMath function does not set * an invalid ASTNode this changes to i == LIBSBML_OPERATION_SUCCESS fail_unless( i == LIBSBML_INVALID_OBJECT); */ fail_unless ( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( SpeciesReference_isSetStoichiometryMath(sr) ); StoichiometryMath_free(sm); }