END_TEST START_TEST (test_L3_Species_initDefaults) { Species_t *s = Species_create(3,1); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( Species_getSubstanceUnits (s) == NULL ); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( !Species_isSetSubstanceUnits (s) ); fail_unless( !Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( !Species_isSetBoundaryCondition(s) ); fail_unless( !Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_initDefaults(s); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( !strcmp(Species_getSubstanceUnits (s),"mole" )); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( Species_isSetSubstanceUnits (s) ); fail_unless( Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( Species_isSetBoundaryCondition(s) ); fail_unless( Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_free(s); }
END_TEST START_TEST (test_L3_Species_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); Species_t *s = Species_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) s) == SBML_SPECIES ); fail_unless( SBase_getMetaId ((SBase_t *) s) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) s) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) s) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) s) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) s) == 1 ); fail_unless( Species_getNamespaces (s) != NULL ); fail_unless( XMLNamespaces_getLength(Species_getNamespaces(s)) == 2 ); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( Species_getSubstanceUnits (s) == NULL ); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( !Species_isSetSubstanceUnits (s) ); fail_unless( !Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( !Species_isSetBoundaryCondition(s) ); fail_unless( !Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_free(s); XMLNamespaces_free(xmlns); SBMLNamespaces_free(sbmlns); }
END_TEST START_TEST (test_L3_Compartment_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); Compartment_t *c = Compartment_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) c) == SBML_COMPARTMENT ); fail_unless( SBase_getMetaId ((SBase_t *) c) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) c) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) c) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) c) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) c) == 1 ); fail_unless( Compartment_getNamespaces (c) != NULL ); fail_unless( XMLNamespaces_getLength(Compartment_getNamespaces(c)) == 2 ); fail_unless( Compartment_getId (c) == NULL ); fail_unless( Compartment_getName (c) == NULL ); fail_unless( Compartment_getUnits (c) == NULL ); fail_unless( Compartment_getOutside(c) == NULL ); fail_unless( util_isNaN(Compartment_getSpatialDimensionsAsDouble(c)) ); fail_unless( util_isNaN(Compartment_getVolume(c))); fail_unless( Compartment_getConstant(c) == 1 ); fail_unless( !Compartment_isSetId (c) ); fail_unless( !Compartment_isSetSpatialDimensions (c) ); fail_unless( !Compartment_isSetName (c) ); fail_unless( !Compartment_isSetSize (c) ); fail_unless( !Compartment_isSetVolume (c) ); fail_unless( !Compartment_isSetUnits (c) ); fail_unless( !Compartment_isSetOutside(c) ); fail_unless( !Compartment_isSetConstant(c) ); Compartment_free(c); XMLNamespaces_free(xmlns); SBMLNamespaces_free(sbmlns); }
END_TEST START_TEST(test_SBMLTransforms_evaluateCustomAST) { std::map<std::string, double> values; const char* formula = "a + b + c"; ASTNode* node = SBML_parseFormula(formula); fail_unless(node != NULL); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node, values))); values["a"] = 1; values["b"] = 1; fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node, values))); values["c"] = 1; fail_unless(SBMLTransforms::evaluateASTNode(node, values) == 3); }
END_TEST START_TEST (test_L3_Compartment_spatialDimensions) { fail_unless( !Compartment_isSetSpatialDimensions(C)); fail_unless( util_isNaN(Compartment_getSpatialDimensionsAsDouble(C))); Compartment_setSpatialDimensionsAsDouble(C, 1.5); fail_unless( Compartment_isSetSpatialDimensions(C)); fail_unless( Compartment_getSpatialDimensionsAsDouble(C) == 1.5); Compartment_unsetSpatialDimensions(C); fail_unless( !Compartment_isSetSpatialDimensions(C)); fail_unless( util_isNaN(Compartment_getSpatialDimensionsAsDouble(C))); }
END_TEST START_TEST (test_L3_LocalParameter_value) { fail_unless( !LocalParameter_isSetValue(P)); fail_unless( util_isNaN(LocalParameter_getValue(P))); LocalParameter_setValue(P, 1.5); fail_unless( LocalParameter_isSetValue(P)); fail_unless( LocalParameter_getValue(P) == 1.5); LocalParameter_unsetValue(P); fail_unless( !LocalParameter_isSetValue(P)); fail_unless( util_isNaN(LocalParameter_getValue(P))); }
END_TEST START_TEST (test_L3_Compartment_size) { double size = 0.2; fail_unless( !Compartment_isSetSize(C)); fail_unless( util_isNaN(Compartment_getSize(C))); Compartment_setSize(C, size); fail_unless( Compartment_getSize(C) == size ); fail_unless( Compartment_isSetSize(C) ); Compartment_unsetSize(C); fail_unless( !Compartment_isSetSize(C) ); fail_unless( util_isNaN(Compartment_getSize(C))); }
END_TEST START_TEST (test_L3_SpeciesReference_stoichiometry) { double stoichiometry = 0.2; fail_unless( !SpeciesReference_isSetStoichiometry(SR)); fail_unless( util_isNaN(SpeciesReference_getStoichiometry(SR))); SpeciesReference_setStoichiometry(SR, stoichiometry); fail_unless( SpeciesReference_getStoichiometry(SR) == stoichiometry ); fail_unless( SpeciesReference_isSetStoichiometry(SR) ); SpeciesReference_unsetStoichiometry(SR); fail_unless( !SpeciesReference_isSetStoichiometry(SR) ); fail_unless( util_isNaN(SpeciesReference_getStoichiometry(SR))); }
std::string CODEExporterC::exportNumber(double number) { if (util_isNaN(number)) return "NaN"; if (util_isInf(number)) return "INFINITY"; std::stringstream str; str << number; return str.str(); }
END_TEST START_TEST (test_L3_Species_initialConcentration) { double initialConcentration = 0.2; fail_unless( !Species_isSetInitialConcentration(S)); fail_unless( util_isNaN(Species_getInitialConcentration(S))); Species_setInitialConcentration(S, initialConcentration); fail_unless( Species_getInitialConcentration(S) == initialConcentration ); fail_unless( Species_isSetInitialConcentration(S) ); Species_unsetInitialConcentration(S); fail_unless( !Species_isSetInitialConcentration(S) ); fail_unless( util_isNaN(Species_getInitialConcentration(S))); }
END_TEST START_TEST (test_L3_Species_initialAmount) { double initialAmount = 0.2; fail_unless( !Species_isSetInitialAmount(S)); fail_unless( util_isNaN(Species_getInitialAmount(S))); Species_setInitialAmount(S, initialAmount); fail_unless( Species_getInitialAmount(S) == initialAmount ); fail_unless( Species_isSetInitialAmount(S) ); Species_unsetInitialAmount(S); fail_unless( !Species_isSetInitialAmount(S) ); fail_unless( util_isNaN(Species_getInitialAmount(S))); }
LIBSBML_EXTERN int util_isInf (double d) { if ( !(util_isFinite(d) || util_isNaN(d)) ) { return (d < 0) ? -1 : 1; } return 0; }
END_TEST START_TEST (test_util_PosInf) { double d = util_PosInf(); if ( util_isFinite(d) || util_isNaN(d) || d <= 0) { fail("util_PosInf() did not return +Inf."); } }
/** * Formats the given ASTNode as a real number and appends the result to * the given StringBuffer. */ void L3FormulaFormatter_formatReal (StringBuffer_t *sb, const ASTNode_t *node, const L3ParserSettings_t *settings) { double value = ASTNode_getReal(node); int sign; char * units; if (ASTNode_isInteger(node)) { value = ASTNode_getInteger(node); } if (util_isNaN(value)) { StringBuffer_append(sb, "NaN"); } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { StringBuffer_appendChar(sb, '-'); } StringBuffer_append(sb, "INF"); } else if (util_isNegZero(value)) { StringBuffer_append(sb, "-0"); } else { if (ASTNode_getType(node) == AST_REAL_E) { StringBuffer_appendExp(sb, value); } else { StringBuffer_appendReal(sb, value); } } if (L3ParserSettings_getParseUnits(settings)) { if (ASTNode_hasUnits(node)) { StringBuffer_appendChar( sb, ' '); units = ASTNode_getUnits(node); StringBuffer_append( sb, units); safe_free(units); } } }
END_TEST START_TEST (test_L3_SpeciesReference_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); SpeciesReference_t *sr = SpeciesReference_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) sr) == SBML_SPECIES_REFERENCE ); fail_unless( SBase_getMetaId ((SBase_t *) sr) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) sr) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) sr) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) sr) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) sr) == 1 ); fail_unless( SpeciesReference_getNamespaces (sr) != NULL ); fail_unless( XMLNamespaces_getLength(SpeciesReference_getNamespaces(sr)) == 2 ); fail_unless( SpeciesReference_getId (sr) == NULL ); fail_unless( SpeciesReference_getName (sr) == NULL ); fail_unless( SpeciesReference_getSpecies (sr) == NULL ); fail_unless( util_isNaN(SpeciesReference_getStoichiometry (sr)) ); fail_unless( SpeciesReference_getConstant(sr) == 0 ); fail_unless( !SpeciesReference_isSetId (sr) ); fail_unless( !SpeciesReference_isSetName (sr) ); fail_unless( !SpeciesReference_isSetSpecies (sr) ); fail_unless( !SpeciesReference_isSetStoichiometry (sr) ); fail_unless( !SpeciesReference_isSetConstant(sr) ); SpeciesReference_free(sr); XMLNamespaces_free(xmlns); SBMLNamespaces_free(sbmlns); }
END_TEST START_TEST (test_L3_LocalParameter_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); LocalParameter_t *p = LocalParameter_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) p) == SBML_LOCAL_PARAMETER ); fail_unless( SBase_getMetaId ((SBase_t *) p) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) p) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) p) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) p) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) p) == 1 ); fail_unless( LocalParameter_getNamespaces (p) != NULL ); fail_unless( XMLNamespaces_getLength(LocalParameter_getNamespaces(p)) == 2 ); fail_unless( LocalParameter_getId (p) == NULL ); fail_unless( LocalParameter_getName (p) == NULL ); fail_unless( LocalParameter_getUnits (p) == NULL ); fail_unless( util_isNaN(LocalParameter_getValue(p))); fail_unless( !LocalParameter_isSetId (p) ); fail_unless( !LocalParameter_isSetName (p) ); fail_unless( !LocalParameter_isSetValue (p) ); fail_unless( !LocalParameter_isSetUnits (p) ); LocalParameter_free(p); XMLNamespaces_free(xmlns); SBMLNamespaces_free(sbmlns); }
/** * Formats the given ASTNode as a real number and returns the result as * a string. */ char * FormulaGraphvizFormatter_formatReal (const ASTNode_t *node) { StringBuffer_t *p = StringBuffer_create(128); double value = ASTNode_getReal(node); int sign; char *s; if (util_isNaN(value)) { s = "NaN"; } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { s = "-INF"; } else { s = "INF"; } } else if (util_isNegZero(value)) { s = "-0"; } else { StringBuffer_appendReal(p, value); s = StringBuffer_toString(p); } free(p); return s; }
/** * Formats the given ASTNode as a real number and appends the result to * the given StringBuffer. */ void FormulaFormatter_formatReal (StringBuffer_t *sb, const ASTNode_t *node) { double value = ASTNode_getReal(node); int sign; if (util_isNaN(value)) { StringBuffer_append(sb, "NaN"); } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { StringBuffer_appendChar(sb, '-'); } StringBuffer_append(sb, "INF"); } else if (util_isNegZero(value)) { StringBuffer_append(sb, "-0"); } else { if (ASTNode_getType(node) == AST_REAL_E) { StringBuffer_appendExp(sb, value); } else { StringBuffer_appendReal(sb, value); } } }
END_TEST START_TEST(test_SBMLTransforms_evaluateAST) { double temp; const char * mathml; ASTNode * node = new ASTNode(); node->setValue((int)(2)); fail_unless(SBMLTransforms::evaluateASTNode(node) == 2); node->setValue((double) (3.2)); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 3.2)); node->setValue((long)(1), (long)(4)); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.25)); node->setValue((double) (4.234), (int) (2)); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 423.4)); node->setType(AST_NAME_AVOGADRO); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 6.02214179e23)); node->setType(AST_NAME_TIME); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node->setType(AST_NAME); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node))); node->setType(AST_CONSTANT_E); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), exp(1.0))); node->setType(AST_CONSTANT_FALSE); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node->setType(AST_CONSTANT_PI); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 4.0*atan(1.0))); node->setType(AST_CONSTANT_TRUE); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("2.5 + 6.1"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 8.6)); node = SBML_parseFormula("-4.3"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), -4.3)); node = SBML_parseFormula("9.2-4.3"); temp = 9.2-4.3; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("2*3"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 6)); node = SBML_parseFormula("1/5"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.2)); node = SBML_parseFormula("pow(2, 3)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 8)); node = SBML_parseFormula("3^3"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 27)); node = SBML_parseFormula("abs(-9.456)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 9.456)); node = SBML_parseFormula("ceil(9.456)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 10)); node = SBML_parseFormula("exp(2.0)"); temp = exp(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("floor(2.04567)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 2)); node = SBML_parseFormula("ln(2.0)"); temp = log(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("log10(100.0)"); temp = log10(100.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("sin(2.0)"); temp = sin(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("cos(4.1)"); temp = cos(4.1); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("tan(0.345)"); temp = tan(0.345); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arcsin(0.456)"); temp = asin(0.456); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccos(0.41)"); temp = acos(0.41); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arctan(0.345)"); temp = atan(0.345); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("sinh(2.0)"); temp = sinh(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("cosh(4.1)"); temp = cosh(4.1); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("tanh(0.345)"); temp = tanh(0.345); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("and(1, 0)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("or(1, 0)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("not(1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("xor(1, 0)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("xor(1, 1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("eq(1, 2)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("eq(1, 1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("geq(2,1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("geq(2,4)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("geq(2,2)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("gt(2,1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("gt(2,4)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("leq(2,1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("leq(2,4)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("leq(2,2)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("lt(2,1)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("lt(2,4)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("neq(2,2)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0)); node = SBML_parseFormula("neq(3,2)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0)); node = SBML_parseFormula("cot(2.0)"); temp = 1.0/tan(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("csc(4.1)"); temp = 1.0/sin(4.1); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("sec(0.345)"); temp = 1.0/cos(0.345); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("coth(2.0)"); temp = cosh(2.0)/sinh(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("sech(2.0)"); temp = 1.0/cosh(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("csch(2.0)"); temp = 1.0/sinh(2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccot(2.0)"); temp = atan(1/2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccsc(2.0)"); temp = asin(1/2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arcsec(2.0)"); temp = acos(1/2.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccosh(2.0)"); temp = log(2.0 + pow(3.0, 0.5)); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccoth(2.0)"); temp = 0.5 * log(3.0); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arcsech(0.2)"); temp = log(2*pow(6, 0.5)+5); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arccsch(0.2)"); /* temp = log(5 +pow(26, 0.5)); * only matches to 15 dp and therefore fails !! */ temp = 2.312438341272753; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arcsinh(3.0)"); temp = log(3.0 +pow(10.0, 0.5)); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("arctanh(0.2)"); temp = 0.5 * log(1.5); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node->setType(AST_FUNCTION_DELAY); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node))); node = SBML_parseFormula("factorial(3)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 6)); node= SBML_parseFormula("piecewise()"); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node))); node= SBML_parseFormula("piecewise(1,false)"); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node))); node= SBML_parseFormula("piecewise(1,true)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1)); node = SBML_parseFormula("piecewise(1.0, true, 0.0)"); temp = 1.0; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("piecewise(1.0, false, 0.0)"); temp = 0.0; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("piecewise(4.5)"); temp = 4.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("piecewise(4.5, false, 5.5, true)"); temp = 5.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("piecewise(4.5, true, 5.5, false)"); temp = 4.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("piecewise(4.5, false, 5.5, false, 6.5)"); temp = 6.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node= SBML_parseFormula("piecewise(4.5, true, 5.5, true)"); fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node))); node = SBML_parseFormula("piecewise(4.5, true, 4.5, true)"); temp = 4.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); node = SBML_parseFormula("root(2, 4)"); fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 2)); mathml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" "<apply><plus/></apply></math>"; node = readMathMLFromString(mathml); temp = 0; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); mathml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" "<apply><plus/><cn>2.3</cn></apply></math>"; node = readMathMLFromString(mathml); temp = 2.3; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); mathml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" "<apply><times/></apply></math>"; node = readMathMLFromString(mathml); temp = 1.0; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); mathml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" "<apply><times/><cn>6.5</cn></apply></math>"; node = readMathMLFromString(mathml); temp = 6.5; fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp)); }
LIBSBML_EXTERN int util_isFinite (double d) { return !util_isNaN(d) && !util_isNaN(d-d); }