/// /// @file TestReadSBML.cs /// @brief Read SBML unit tests /// @author Frank Bergmann (Csharp conversion) /// @author Akiya Jouraku (Csharp conversion) /// @author Ben Bornstein /// /// $Id: TestReadSBML.cs 8704 2009-01-04 02:26:05Z mhucka $ /// $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/trunk/libsbml/src/bindings/csharp/test/sbml/TestReadSBML.cs $ /// /// This test file was converted from src/sbml/test/TestReadSBML.cpp /// with the help of conversion sciprt (ctest_converter.pl). /// /// */ namespace LibSBMLCSTest { using libsbml; using System.IO; public class TestReadSBML { public class AssertionError : System.Exception { public AssertionError() : base() { } } static void assertTrue(bool condition) { if (condition == true) { return; } throw new AssertionError(); } static void assertEquals(object a, object b) { if ( (a == null) && (b == null) ) { return; } else if (a.Equals(b)) { return; } throw new AssertionError(); } static void assertNotEquals(object a, object b) { if ( (a == null) && (b == null) ) { throw new AssertionError(); } else if (a.Equals(b)) { throw new AssertionError(); } } static void assertEquals(bool a, bool b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(bool a, bool b) { if ( a != b ) { return; } throw new AssertionError(); } static void assertEquals(int a, int b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(int a, int b) { if ( a != b ) { return; } throw new AssertionError(); } private SBMLDocument D; private Model M; public string SBML_FOOTER() { return " "; } public string SBML_HEADER_L1v1() { return " \n"; } public string SBML_HEADER_L1v2() { return " \n"; } public string SBML_HEADER_L2v1() { return " \n"; } public string SBML_HEADER_L2v2() { return " \n"; } public string SBML_HEADER_L2v3() { return " \n"; } public string XML_HEADER() { return "\n"; } public string wrapSBML_L1v1(string s) { string r = XML_HEADER(); r += SBML_HEADER_L1v1(); r += s; r += SBML_FOOTER(); return r; } public string wrapSBML_L1v2(string s) { string r = XML_HEADER(); r += SBML_HEADER_L1v2(); r += s; r += SBML_FOOTER(); return r; } public string wrapSBML_L2v1(string s) { string r = XML_HEADER(); r += SBML_HEADER_L2v1(); r += s; r += SBML_FOOTER(); return r; } public string wrapSBML_L2v2(string s) { string r = XML_HEADER(); r += SBML_HEADER_L2v2(); r += s; r += SBML_FOOTER(); return r; } public string wrapSBML_L2v3(string s) { string r = XML_HEADER(); r += SBML_HEADER_L2v3(); r += s; r += SBML_FOOTER(); return r; } public string wrapXML(string s) { string r = XML_HEADER(); r += s; return r; } private int USE_LIBXML = 0; private int USE_EXPAT = 0; private int USE_XERCES = 0; public void setUp() { D = null; } public void tearDown() { D = null; } public void test_ReadSBML_AlgebraicRule() { Rule ar; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); ar = M.getRule(0); assertTrue(( "x + 1" == ar.getFormula() )); } public void test_ReadSBML_AlgebraicRule_L2() { Rule ar; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + " " + " S1 " + " S2 " + " " + " T " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); ar = M.getRule(0); assertTrue( ar != null ); assertEquals( true, ar.isSetMath() ); math = ar.getMath(); formula = ar.getFormula(); assertTrue( formula != null ); assertTrue(( "S1 + S2 - T" == formula )); } public void test_ReadSBML_AssignmentRule() { Rule ar; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " k3 " + " k2 " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); ar = M.getRule(0); assertTrue( ar != null ); assertEquals( true, ar.isSetMath() ); math = ar.getMath(); formula = ar.getFormula(); assertTrue( formula != null ); assertTrue(( "k3 / k2" == formula )); } public void test_ReadSBML_Compartment() { Compartment c; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumCompartments() == 1 ); c = M.getCompartment(0); assertTrue(( "mitochondria" == c.getId() )); assertTrue(( "milliliters" == c.getUnits() )); assertTrue(( "cell" == c.getOutside() )); assertTrue( c.getVolume() == .0001 ); assertEquals( true, c.isSetVolume() ); assertEquals( true, c.isSetSize() ); } public void test_ReadSBML_CompartmentVolumeRule() { Rule cvr; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); cvr = M.getRule(0); assertEquals( true, cvr.isCompartmentVolume() ); assertTrue(( "A" == cvr.getVariable() )); assertTrue(( "0.10 * t" == cvr.getFormula() )); assertTrue( cvr.getType() == libsbml.RULE_TYPE_SCALAR ); } public void test_ReadSBML_Compartment_L2() { Compartment c; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumCompartments() == 1 ); c = M.getCompartment(0); assertEquals( true, c.isSetId() ); assertEquals( false, c.isSetName() ); assertEquals( true, c.isSetVolume() ); assertEquals( true, c.isSetSize() ); assertEquals( true, c.isSetUnits() ); assertEquals( true, c.isSetOutside() ); assertTrue(( "membrane" == c.getId() )); assertTrue(( "area" == c.getUnits() )); assertTrue(( "tissue" == c.getOutside() )); assertTrue( c.getSpatialDimensions() == 2 ); assertTrue( c.getSize() == .3 ); } public void test_ReadSBML_Compartment_defaults() { Compartment c; string s = wrapSBML_L1v2(" " ); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumCompartments() == 1 ); c = M.getCompartment(0); assertEquals( true, c.isSetId() ); assertEquals( true, c.isSetVolume() ); assertEquals( false, c.isSetSize() ); assertEquals( false, c.isSetUnits() ); assertEquals( false, c.isSetOutside() ); assertTrue(( "cell" == c.getId() )); assertTrue( c.getVolume() == 1.0 ); } public void test_ReadSBML_Compartment_defaults_L2() { Compartment c; string s = wrapSBML_L2v1(" " ); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumCompartments() == 1 ); c = M.getCompartment(0); assertEquals( true, c.isSetId() ); assertEquals( false, c.isSetName() ); assertEquals( false, c.isSetSize() ); assertEquals( false, c.isSetUnits() ); assertEquals( false, c.isSetOutside() ); assertTrue(( "cell" == c.getId() )); assertTrue( c.getSpatialDimensions() == 3 ); assertTrue( c.getConstant() == true ); } public void test_ReadSBML_Event() { Event e; string s = wrapSBML_L2v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumEvents() == 1 ); e = M.getEvent(0); assertTrue( e != null ); assertEquals( true, e.isSetId() ); assertEquals( true, e.isSetName() ); assertEquals( true, e.isSetTimeUnits() ); assertEquals( false, e.isSetTrigger() ); assertEquals( false, e.isSetDelay() ); assertTrue(( "e1" == e.getId() )); assertTrue(( "MyEvent" == e.getName() )); assertTrue(( "time" == e.getTimeUnits() )); } public void test_ReadSBML_EventAssignment() { Event e; EventAssignment ea; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " 0 " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumEvents() == 1 ); e = M.getEvent(0); assertTrue( e != null ); assertTrue( e.getNumEventAssignments() == 1 ); ea = e.getEventAssignment(0); assertTrue( ea != null ); assertEquals( true, ea.isSetVariable() ); assertTrue(( "k2" == ea.getVariable() )); assertEquals( true, ea.isSetMath() ); math = ea.getMath(); formula = libsbml.formulaToString(math); assertTrue( formula != null ); assertTrue(( "0" == formula )); } public void test_ReadSBML_Event_delay() { Event e; Delay delay; string formula; string s = wrapSBML_L2v1("" + " 5 " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumEvents() == 1 ); e = M.getEvent(0); assertTrue( e != null ); assertEquals( true, e.isSetDelay() ); assertEquals( false, e.isSetTrigger() ); delay = e.getDelay(); formula = libsbml.formulaToString(delay.getMath()); assertTrue( formula != null ); assertTrue(( "5" == formula )); } public void test_ReadSBML_Event_trigger() { Event e; Trigger trigger; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + " P1 " + " t " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumEvents() == 1 ); e = M.getEvent(0); assertTrue( e != null ); assertEquals( false, e.isSetDelay() ); assertEquals( true, e.isSetTrigger() ); trigger = e.getTrigger(); formula = libsbml.formulaToString(trigger.getMath()); assertTrue( formula != null ); assertTrue(( "leq(P1, t)" == formula )); } public void test_ReadSBML_FunctionDefinition() { FunctionDefinition fd; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " x " + " " + " " + " x " + " 3 " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumFunctionDefinitions() == 1 ); fd = M.getFunctionDefinition(0); assertTrue( fd != null ); assertEquals( true, fd.isSetId() ); assertEquals( true, fd.isSetName() ); assertTrue(( "pow3" == fd.getId() )); assertTrue(( "cubed" == fd.getName() )); assertEquals( true, fd.isSetMath() ); math = fd.getMath(); formula = libsbml.formulaToString(math); assertTrue( formula != null ); assertTrue(( "lambda(x, pow(x, 3))" == formula )); } public void test_ReadSBML_KineticLaw() { Reaction r; KineticLaw kl; string s = wrapSBML_L1v2("" + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); kl = r.getKineticLaw(); assertTrue(( "k1*X0" == kl.getFormula() )); } public void test_ReadSBML_KineticLaw_L2() { Reaction r; KineticLaw kl; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + " k " + " S2 " + " X0 " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue( r != null ); kl = r.getKineticLaw(); assertTrue( kl != null ); assertEquals( true, kl.isSetMath() ); math = kl.getMath(); formula = kl.getFormula(); assertTrue( formula != null ); assertTrue(( "k * S2 * X0" == formula )); } public void test_ReadSBML_KineticLaw_Parameter() { Reaction r; KineticLaw kl; Parameter p; string s = wrapSBML_L1v2("" + " " + " " + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); kl = r.getKineticLaw(); assertTrue(( "k1*X0" == kl.getFormula() )); assertTrue( kl.getNumParameters() == 1 ); p = kl.getParameter(0); assertTrue(( "k1" == p.getId() )); assertTrue( p.getValue() == 0 ); } public void test_ReadSBML_Model() { string s = wrapXML("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue(( "testModel" == M.getId() )); } public void test_ReadSBML_Model_L2() { string s = wrapXML("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertEquals( true, M.isSetId() ); assertEquals( false, M.isSetName() ); assertTrue(( "testModel" == M.getId() )); } public void test_ReadSBML_Parameter() { Parameter p; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumParameters() == 1 ); p = M.getParameter(0); assertTrue(( "Km1" == p.getId() )); assertTrue(( "second" == p.getUnits() )); assertTrue( p.getValue() == 2.3 ); assertTrue( p.isSetValue() == true ); } public void test_ReadSBML_ParameterRule() { Rule pr; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); pr = M.getRule(0); assertEquals( true, pr.isParameter() ); assertTrue(( "k" == pr.getVariable() )); assertTrue(( "k3/k2" == pr.getFormula() )); assertTrue( pr.getType() == libsbml.RULE_TYPE_SCALAR ); } public void test_ReadSBML_Parameter_L2() { Parameter p; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumParameters() == 1 ); p = M.getParameter(0); assertEquals( true, p.isSetId() ); assertEquals( false, p.isSetName() ); assertEquals( true, p.isSetValue() ); assertEquals( true, p.isSetUnits() ); assertTrue(( "T" == p.getId() )); assertTrue(( "Celsius" == p.getUnits() )); assertTrue( p.getValue() == 4.6 ); assertTrue( p.getConstant() == false ); } public void test_ReadSBML_Parameter_L2_defaults() { Parameter p; string s = wrapSBML_L2v1(" " ); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumParameters() == 1 ); p = M.getParameter(0); assertEquals( true, p.isSetId() ); assertEquals( false, p.isSetName() ); assertEquals( false, p.isSetValue() ); assertEquals( false, p.isSetUnits() ); assertTrue(( "x" == p.getId() )); assertTrue( p.getConstant() == true ); } public void test_ReadSBML_RateRule() { Rule rr; ASTNode math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + " " + " 1 " + " x " + " " + " " + " " + " x " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); rr = M.getRule(0); assertTrue( rr != null ); assertEquals( true, rr.isSetMath() ); math = rr.getMath(); formula = rr.getFormula(); assertTrue( formula != null ); assertTrue(( "(1 - x) * log(x)" == formula )); } public void test_ReadSBML_Reaction() { Reaction r; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getFast() == false ); } public void test_ReadSBML_Reaction_L2() { Reaction r; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertEquals( true, r.isSetId() ); assertEquals( false, r.isSetName() ); assertEquals( true, r.isSetFast() ); assertTrue(( "r1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getFast() == false ); } public void test_ReadSBML_Reaction_L2_defaults() { Reaction r; string s = wrapSBML_L2v1(" " ); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertEquals( true, r.isSetId() ); assertEquals( false, r.isSetName() ); assertEquals( false, r.isSetFast() ); assertTrue(( "r1" == r.getId() )); assertTrue( r.getReversible() == true ); } public void test_ReadSBML_Reaction_defaults() { Reaction r; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() != false ); assertTrue( r.getFast() == false ); } public void test_ReadSBML_SBML() { string s = wrapXML(" "); D = libsbml.readSBMLFromString(s); assertTrue( D.getLevel() == 1 ); assertTrue( D.getVersion() == 1 ); } public void test_ReadSBML_Specie() { Species sp; string s = wrapSBML_L1v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertTrue(( "Glucose" == sp.getId() )); assertTrue(( "cell" == sp.getCompartment() )); assertTrue(( "volume" == sp.getUnits() )); assertTrue( sp.getInitialAmount() == 4.1 ); assertTrue( sp.getBoundaryCondition() == false ); assertTrue( sp.getCharge() == 6 ); assertTrue( sp.isSetInitialAmount() == true ); assertTrue( sp.isSetCharge() == true ); } public void test_ReadSBML_SpecieConcentrationRule() { Rule scr; string s = wrapSBML_L1v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); scr = M.getRule(0); assertEquals( true, scr.isSpeciesConcentration() ); assertTrue(( "s2" == scr.getVariable() )); assertTrue(( "k * t/(1 + k)" == scr.getFormula() )); assertTrue( scr.getType() == libsbml.RULE_TYPE_SCALAR ); } public void test_ReadSBML_SpecieConcentrationRule_rate() { Rule scr; string s = wrapSBML_L1v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); scr = M.getRule(0); assertEquals( true, scr.isSpeciesConcentration() ); assertTrue(( "s2" == scr.getVariable() )); assertTrue(( "k * t/(1 + k)" == scr.getFormula() )); assertTrue( scr.getType() == libsbml.RULE_TYPE_RATE ); } public void test_ReadSBML_SpecieReference_Product() { Reaction r; SpeciesReference sr; string s = wrapSBML_L1v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getNumProducts() == 1 ); sr = r.getProduct(0); assertTrue(( "S1" == sr.getSpecies() )); assertTrue( sr.getStoichiometry() == 1 ); assertTrue( sr.getDenominator() == 1 ); } public void test_ReadSBML_SpecieReference_Reactant() { Reaction r; SpeciesReference sr; string s = wrapSBML_L1v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getNumReactants() == 1 ); sr = r.getReactant(0); assertTrue(( "X0" == sr.getSpecies() )); assertTrue( sr.getStoichiometry() == 1 ); assertTrue( sr.getDenominator() == 1 ); } public void test_ReadSBML_SpecieReference_defaults() { Reaction r; SpeciesReference sr; string s = wrapSBML_L1v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getNumReactants() == 1 ); sr = r.getReactant(0); assertTrue(( "X0" == sr.getSpecies() )); assertTrue( sr.getStoichiometry() == 1 ); assertTrue( sr.getDenominator() == 1 ); } public void test_ReadSBML_Specie_defaults() { Species sp; string s = wrapSBML_L1v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertTrue(( "Glucose" == sp.getId() )); assertTrue(( "cell" == sp.getCompartment() )); assertTrue( sp.getInitialAmount() == 1.0 ); assertTrue( sp.getBoundaryCondition() == false ); assertTrue( sp.isSetInitialAmount() == true ); assertTrue( sp.isSetCharge() == false ); } public void test_ReadSBML_Species() { Species sp; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertTrue(( "Glucose" == sp.getId() )); assertTrue(( "cell" == sp.getCompartment() )); assertTrue(( "volume" == sp.getUnits() )); assertTrue( sp.getInitialAmount() == 4.1 ); assertTrue( sp.getBoundaryCondition() == false ); assertTrue( sp.getCharge() == 6 ); assertTrue( sp.isSetInitialAmount() == true ); assertTrue( sp.isSetCharge() == true ); } public void test_ReadSBML_SpeciesConcentrationRule() { Rule scr; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumRules() == 1 ); scr = M.getRule(0); assertEquals( true, scr.isSpeciesConcentration() ); assertTrue(( "s2" == scr.getVariable() )); assertTrue(( "k * t/(1 + k)" == scr.getFormula() )); assertTrue( scr.getType() == libsbml.RULE_TYPE_SCALAR ); } public void test_ReadSBML_SpeciesReference_StoichiometryMath_1() { Reaction r; SpeciesReference sr; StoichiometryMath math; string formula; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " x " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue( r != null ); assertTrue( r.getNumReactants() == 1 ); sr = r.getReactant(0); assertTrue( sr != null ); assertEquals( true, sr.isSetStoichiometryMath() ); math = sr.getStoichiometryMath(); formula = libsbml.formulaToString(math.getMath()); assertTrue( formula != null ); assertTrue(( "x" == formula )); } public void test_ReadSBML_SpeciesReference_StoichiometryMath_2() { Reaction r; SpeciesReference sr; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " 3 2 " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue( r != null ); assertTrue( r.getNumReactants() == 1 ); sr = r.getReactant(0); assertTrue( sr != null ); assertEquals( false, sr.isSetStoichiometryMath() ); assertTrue( sr.getStoichiometry() == 3 ); assertTrue( sr.getDenominator() == 2 ); } public void test_ReadSBML_SpeciesReference_defaults() { Reaction r; SpeciesReference sr; string s = wrapSBML_L1v2("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumReactions() == 1 ); r = M.getReaction(0); assertTrue(( "reaction_1" == r.getId() )); assertTrue( r.getReversible() == false ); assertTrue( r.getNumReactants() == 1 ); sr = r.getReactant(0); assertTrue(( "X0" == sr.getSpecies() )); assertTrue( sr.getStoichiometry() == 1 ); assertTrue( sr.getDenominator() == 1 ); } public void test_ReadSBML_Species_L2_1() { Species sp; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertEquals( true, sp.isSetId() ); assertEquals( false, sp.isSetName() ); assertEquals( true, sp.isSetCompartment() ); assertEquals( false, sp.isSetInitialAmount() ); assertEquals( true, sp.isSetInitialConcentration() ); assertEquals( true, sp.isSetSubstanceUnits() ); assertEquals( true, sp.isSetSpatialSizeUnits() ); assertEquals( true, sp.isSetCharge() ); assertTrue(( "Glucose" == sp.getId() )); assertTrue(( "cell" == sp.getCompartment() )); assertTrue(( "item" == sp.getSubstanceUnits() )); assertTrue(( "volume" == sp.getSpatialSizeUnits() )); assertTrue( sp.getInitialConcentration() == 4.1 ); assertTrue( sp.getHasOnlySubstanceUnits() == false ); assertTrue( sp.getBoundaryCondition() == true ); assertTrue( sp.getCharge() == 6 ); assertTrue( sp.getConstant() == true ); } public void test_ReadSBML_Species_L2_2() { Species sp; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertEquals( true, sp.isSetId() ); assertEquals( false, sp.isSetName() ); assertEquals( true, sp.isSetCompartment() ); assertEquals( false, sp.isSetInitialAmount() ); assertEquals( false, sp.isSetInitialConcentration() ); assertEquals( false, sp.isSetSubstanceUnits() ); assertEquals( false, sp.isSetSpatialSizeUnits() ); assertEquals( false, sp.isSetCharge() ); assertTrue(( "s" == sp.getId() )); assertTrue(( "c" == sp.getCompartment() )); assertTrue( sp.getHasOnlySubstanceUnits() == true ); assertTrue( sp.getBoundaryCondition() == false ); assertTrue( sp.getConstant() == false ); } public void test_ReadSBML_Species_L2_defaults() { Species sp; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumSpecies() == 1 ); sp = M.getSpecies(0); assertEquals( true, sp.isSetId() ); assertEquals( false, sp.isSetName() ); assertEquals( true, sp.isSetCompartment() ); assertEquals( false, sp.isSetInitialAmount() ); assertEquals( false, sp.isSetInitialConcentration() ); assertEquals( false, sp.isSetSubstanceUnits() ); assertEquals( false, sp.isSetSpatialSizeUnits() ); assertEquals( false, sp.isSetCharge() ); assertTrue(( "Glucose_6_P" == sp.getId() )); assertTrue(( "cell" == sp.getCompartment() )); assertTrue( sp.getHasOnlySubstanceUnits() == false ); assertTrue( sp.getBoundaryCondition() == false ); assertTrue( sp.getConstant() == false ); } public void test_ReadSBML_Unit() { Unit u; UnitDefinition ud; string s = wrapSBML_L1v2("" + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumUnitDefinitions() == 1 ); ud = M.getUnitDefinition(0); assertTrue(( "substance" == ud.getId() )); assertTrue( ud.getNumUnits() == 1 ); u = ud.getUnit(0); assertTrue( u.getKind() == libsbml.UNIT_KIND_MOLE ); assertTrue( u.getExponent() == 1 ); assertTrue( u.getScale() == -3 ); } public void test_ReadSBML_UnitDefinition() { UnitDefinition ud; string s = wrapSBML_L1v2("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumUnitDefinitions() == 1 ); ud = M.getUnitDefinition(0); assertTrue(( "mmls" == ud.getId() )); } public void test_ReadSBML_UnitDefinition_L2() { UnitDefinition ud; string s = wrapSBML_L2v1("" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumUnitDefinitions() == 1 ); ud = M.getUnitDefinition(0); assertEquals( true, ud.isSetId() ); assertEquals( true, ud.isSetName() ); assertTrue(( "mmls" == ud.getId() )); assertTrue(( "mmol/ls" == ud.getName() )); } public void test_ReadSBML_Unit_L2() { Unit u; UnitDefinition ud; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumUnitDefinitions() == 1 ); ud = M.getUnitDefinition(0); assertEquals( true, ud.isSetId() ); assertTrue(( "Fahrenheit" == ud.getId() )); assertTrue( ud.getNumUnits() == 1 ); u = ud.getUnit(0); assertTrue( u.getKind() == libsbml.UNIT_KIND_CELSIUS ); assertTrue( u.getExponent() == 1 ); assertTrue( u.getScale() == 0 ); assertTrue( u.getMultiplier() == 1.8 ); assertTrue( u.getOffset() == 32 ); } public void test_ReadSBML_Unit_defaults_L1_L2() { Unit u; UnitDefinition ud; string s = wrapSBML_L1v2("" + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNumUnitDefinitions() == 1 ); ud = M.getUnitDefinition(0); assertTrue(( "bogomips" == ud.getId() )); assertTrue( ud.getNumUnits() == 1 ); u = ud.getUnit(0); assertTrue( u.getKind() == libsbml.UNIT_KIND_SECOND ); assertTrue( u.getExponent() == 1 ); assertTrue( u.getScale() == 0 ); assertTrue( u.getMultiplier() == 1.0 ); assertTrue( u.getOffset() == 0.0 ); } public void test_ReadSBML_annotation() { string s = wrapSBML_L2v3("" + " " + " " + " 2000-12-18 18:31 PST" + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getAnnotation() != null ); XMLNode ann = M.getAnnotation(); assertTrue( ann.getNumChildren() == 2 ); } public void test_ReadSBML_annotation_sbml() { string s = wrapXML("" + " " + " " + " " + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); assertTrue( D.getNumErrors() > 0 ); } public void test_ReadSBML_annotation_sbml_L2() { string s = wrapXML(" " + " " + " " + " " + " " + " " + " " + " "); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( D.getNumErrors() == 0 ); } public void test_ReadSBML_line_col_numbers() { //setXMLParser(); SBase sb; string s = "\n" + "\n" + " \n" + " \n" + " \n" + "\n"; D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); sb = M; sb = M.getListOfReactions(); sb = M.getReaction(0); } public void test_ReadSBML_metaid() { SBase sb; string s = wrapSBML_L2v1("" + " " + "" + "" + " " + "" + "" + " " + "" + "" + " " + "" + "" + " " + "" + "" + " " + "" + "" + " " + "" + "" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); sb = M.getFunctionDefinition(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "fd" == sb.getMetaId() )); sb = M.getUnitDefinition(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "ud" == sb.getMetaId() )); sb = M.getCompartment(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "c" == sb.getMetaId() )); sb = M.getSpecies(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "s" == sb.getMetaId() )); sb = M.getParameter(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "p" == sb.getMetaId() )); sb = M.getRule(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "rr" == sb.getMetaId() )); sb = M.getReaction(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "rx" == sb.getMetaId() )); sb = M.getEvent(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "e" == sb.getMetaId() )); } public void test_ReadSBML_metaid_Event() { SBase sb; Event e; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); e = M.getEvent(0); sb = e; assertEquals( true, sb.isSetMetaId() ); assertTrue(( "e" == sb.getMetaId() )); sb = e.getListOfEventAssignments(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "loea" == sb.getMetaId() )); sb = e.getEventAssignment(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "ea" == sb.getMetaId() )); } public void test_ReadSBML_metaid_ListOf() { SBase sb; string s = wrapSBML_L2v1("" + "" + "" + "" + "" + "" + "" + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); sb = M.getListOfFunctionDefinitions(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lofd" == sb.getMetaId() )); sb = M.getListOfUnitDefinitions(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "loud" == sb.getMetaId() )); sb = M.getListOfCompartments(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "loc" == sb.getMetaId() )); sb = M.getListOfSpecies(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "los" == sb.getMetaId() )); sb = M.getListOfParameters(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lop" == sb.getMetaId() )); sb = M.getListOfRules(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lor" == sb.getMetaId() )); sb = M.getListOfReactions(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lorx" == sb.getMetaId() )); sb = M.getListOfEvents(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "loe" == sb.getMetaId() )); } public void test_ReadSBML_metaid_Reaction() { SBase sb; Reaction r; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); r = M.getReaction(0); sb = r; assertEquals( true, sb.isSetMetaId() ); assertTrue(( "r" == sb.getMetaId() )); sb = r.getListOfReactants(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lor" == sb.getMetaId() )); sb = r.getReactant(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "sr1" == sb.getMetaId() )); sb = r.getListOfProducts(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lop" == sb.getMetaId() )); sb = r.getProduct(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "sr2" == sb.getMetaId() )); sb = r.getListOfModifiers(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lom" == sb.getMetaId() )); sb = r.getModifier(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "msr" == sb.getMetaId() )); sb = r.getKineticLaw(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "kl" == sb.getMetaId() )); } public void test_ReadSBML_metaid_Unit() { SBase sb; UnitDefinition ud; string s = wrapSBML_L2v1("" + " " + " " + " " + " " + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); ud = M.getUnitDefinition(0); sb = ud; assertEquals( true, sb.isSetMetaId() ); assertTrue(( "ud" == sb.getMetaId() )); sb = ud.getListOfUnits(); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "lou" == sb.getMetaId() )); sb = ud.getUnit(0); assertEquals( true, sb.isSetMetaId() ); assertTrue(( "u" == sb.getMetaId() )); } public void test_ReadSBML_notes() { Reaction r; KineticLaw kl; string s = wrapSBML_L2v3("" + "" + " " + " This is a test note." + " " + " " + " " + " " + "" + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); r = M.getReaction(0); kl = r.getKineticLaw(); assertTrue( kl.getNotes() != null ); string notes = kl.getNotes().getChild(0).getCharacters(); assertTrue( ( "This is a test note." != notes ) == false ); } public void test_ReadSBML_notes_ListOf() { SBase sb; string s = wrapSBML_L2v1("" + " My Functions" + " " + "" + "" + " My Units" + " " + "" + "" + " My Compartments" + " " + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M != null ); sb = M.getListOfFunctionDefinitions(); assertEquals( true, sb.isSetNotes() ); string notes = sb.getNotes().getChild(0).getCharacters(); assertTrue( ( "My Functions" != notes ) == false ); sb = M.getListOfUnitDefinitions(); assertEquals( true, sb.isSetNotes() ); notes = sb.getNotes().getChild(0).getCharacters(); assertTrue( ( "My Units" != notes ) == false ); sb = M.getListOfCompartments(); assertEquals( true, sb.isSetNotes() ); notes = sb.getNotes().getChild(0).getCharacters(); assertTrue( ( "My Compartments" != notes ) == false ); } public void test_ReadSBML_notes_sbml() { string s = wrapXML("" + " Notes are not allowed as part of the SBML element." + ""); D = libsbml.readSBMLFromString(s); assertTrue( D.getNotes() != null ); string notes = D.getNotes().getChild(0).getCharacters(); assertTrue( ( "Notes are not allowed as part of the SBML element." != notes ) == false ); assertTrue( D.getNumErrors() > 0 ); } public void test_ReadSBML_notes_sbml_L2() { string s = wrapXML(" " + " " + " " + " " + " " + " " + " " + " "); D = libsbml.readSBMLFromString(s); assertTrue( D.getNotes() != null ); assertTrue( D.getNumErrors() == 0 ); } public void test_ReadSBML_notes_xmlns() { string s = wrapSBML_L2v3("" + " Some text." + ""); D = libsbml.readSBMLFromString(s); M = D.getModel(); assertTrue( M.getNotes() != null ); XMLNamespaces ns = M.getNotes().getChild(0).getNamespaces(); assertTrue( ns.getLength() == 1 ); assertTrue(( "http://www.w3.org/1999/xhtml" == ns.getURI(0) )); string notes = M.getNotes().getChild(0).getChild(0).getCharacters(); assertTrue( ( "Some text." != notes ) == false ); } } }