public void test_internal_consistency_check_20306() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); FunctionDefinition fd = m.createFunctionDefinition(); fd.setId("fd"); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20306 ); ASTNode ast = libsbml.parseFormula("lambda(x, 2*x)"); fd.setMath(ast); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_99904_model() { SBMLDocument d = new SBMLDocument(2,4); long errors; d.setLevelAndVersion(1,2,false); Model m = new Model(2,4); Compartment c = m.createCompartment(); c.setId("cc"); m.setMetaId("mmm"); d.setModel(m); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20201 ); d = null; }
public void test_internal_consistency_check_20419() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); UnitDefinition ud = m.createUnitDefinition(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20419 ); ud.setId("ud"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_99902() { SBMLDocument d = new SBMLDocument(2,4); long errors; Compartment c = new Compartment(2,4); d.setLevelAndVersion(1,2,false); Model m = d.createModel(); c.setCompartmentType("hh"); c.setId("c"); m.addCompartment(c); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 10103 ); d = null; }
public void test_internal_consistency_check_21231() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Event r = m.createEvent(); r.setUseValuesFromTriggerTime(true); ASTNode ast = libsbml.parseFormula("2*x"); Trigger t = r.createTrigger(); t.setMath(ast); t.setPersistent(true); t.setInitialValue(false); EventAssignment ea = r.createEventAssignment(); ea.setVariable("ea"); ea.setMath(ast); Priority prior = r.createPriority(); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21231 ); prior.setMath(ast); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_21172() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Reaction r = m.createReaction(); r.setId("r"); r.setReversible(true); r.setFast(false); SpeciesReference sr = r.createReactant(); sr.setSpecies("s"); sr.setConstant(true); KineticLaw kl = r.createKineticLaw(); ASTNode ast = libsbml.parseFormula("2*x"); kl.setMath(ast); LocalParameter lp = kl.createLocalParameter(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21172 ); lp.setId("pp"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_20517() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Compartment c = m.createCompartment(); errors = d.checkInternalConsistency(); assertTrue( errors == 2 ); assertTrue( d.getError(0).getErrorId() == 20517 ); assertTrue( d.getError(1).getErrorId() == 20517 ); c.setId("c"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20517 ); c.setConstant(true); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_WriteL3SBML_error() { SBMLDocument d = new SBMLDocument(); SBMLWriter w = new SBMLWriter(); assertEquals( false, w.writeSBML(d, "/tmp/impossible/path/should/fail") ); assertTrue( d.getNumErrors() == 1 ); assertTrue( d.getError(0).getErrorId() == libsbml.XMLFileUnwritable ); d = null; w = null; }
public void test_internal_consistency_check_21007() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Constraint r = m.createConstraint(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21007 ); ASTNode ast = libsbml.parseFormula("lambda(x, 2*x)"); r.setMath(ast); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_20908() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); AssignmentRule r = m.createAssignmentRule(); ASTNode ast = libsbml.parseFormula("lambda(x, 2*x)"); r.setMath(ast); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20908 ); r.setVariable("fd"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_20805() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); InitialAssignment ia = m.createInitialAssignment(); ASTNode ast = libsbml.parseFormula("lambda(x, 2*x)"); ia.setMath(ast); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20805 ); ia.setSymbol("fd"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_20706() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Parameter p = m.createParameter(); errors = d.checkInternalConsistency(); assertTrue( errors == 2 ); assertTrue( d.getError(0).getErrorId() == 20706 ); assertTrue( d.getError(1).getErrorId() == 20706 ); p.setId("c"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20706 ); p.setConstant(true); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_99921() { SBMLDocument d = new SBMLDocument(2,4); long errors; SpeciesReference sr = new SpeciesReference(2,4); d.setLevelAndVersion(2,1,false); Model m = d.createModel(); Compartment c = m.createCompartment(); c.setId("c"); Species s = m.createSpecies(); s.setId("s"); Reaction r = m.createReaction(); r.setId("r"); s.setCompartment("c"); sr.setSpecies("s"); sr.setName("mmm"); r.addReactant(sr); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21101 ); d = null; }
public void test_internal_consistency_check_20623() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Compartment c = m.createCompartment(); c.setId("c"); c.setConstant(true); Species s = m.createSpecies(); errors = d.checkInternalConsistency(); assertTrue( errors == 5 ); assertTrue( d.getError(0).getErrorId() == 20623 ); assertTrue( d.getError(1).getErrorId() == 20614 ); assertTrue( d.getError(2).getErrorId() == 20623 ); assertTrue( d.getError(3).getErrorId() == 20623 ); assertTrue( d.getError(4).getErrorId() == 20623 ); s.setId("s"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 4 ); assertTrue( d.getError(0).getErrorId() == 20614 ); assertTrue( d.getError(1).getErrorId() == 20623 ); assertTrue( d.getError(2).getErrorId() == 20623 ); assertTrue( d.getError(3).getErrorId() == 20623 ); s.setCompartment("c"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 3 ); assertTrue( d.getError(0).getErrorId() == 20623 ); assertTrue( d.getError(1).getErrorId() == 20623 ); assertTrue( d.getError(2).getErrorId() == 20623 ); s.setHasOnlySubstanceUnits(true); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 2 ); assertTrue( d.getError(0).getErrorId() == 20623 ); assertTrue( d.getError(1).getErrorId() == 20623 ); s.setBoundaryCondition(true); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20623 ); s.setConstant(true); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_internal_consistency_check_99911_model() { SBMLDocument d = new SBMLDocument(2,4); long errors; d.setLevelAndVersion(2,1,false); Model m = new Model(2,4); m.setSBOTerm(2); d.setModel(m); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20201 ); d = null; }
public void test_internal_consistency_check_20421() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); UnitDefinition ud = m.createUnitDefinition(); ud.setId("ud"); Unit u = ud.createUnit(); errors = d.checkInternalConsistency(); assertTrue( errors == 4 ); assertTrue( d.getError(0).getErrorId() == 20421 ); assertTrue( d.getError(1).getErrorId() == 20421 ); assertTrue( d.getError(2).getErrorId() == 20421 ); assertTrue( d.getError(3).getErrorId() == 20421 ); u.setKind(libsbml.UNIT_KIND_MOLE); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 3 ); assertTrue( d.getError(0).getErrorId() == 20421 ); assertTrue( d.getError(1).getErrorId() == 20421 ); assertTrue( d.getError(2).getErrorId() == 20421 ); u.setExponent(1.0); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 2 ); assertTrue( d.getError(0).getErrorId() == 20421 ); assertTrue( d.getError(1).getErrorId() == 20421 ); u.setScale(0); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 20421 ); u.setMultiplier(1.0); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
public void test_ReadSBML_FunctionDefinition_OnlyBVars() { FunctionDefinition fd; SBMLError error; int numErrors; ASTNode math; string formula; string s = wrapSBML_L2v1("<listOfFunctionDefinitions>" + " <functionDefinition id='invalid'>" + " <math xmlns='http://www.w3.org/1998/Math/MathML'>" + " <lambda>" + " <bvar><ci> x </ci></bvar>" + " <bvar><ci> y </ci></bvar>" + " <bvar><ci> z </ci></bvar>" + " </lambda>" + " </math>" + " </functionDefinition>" + "</listOfFunctionDefinitions>"); D = libsbml.readSBMLFromString(s); M = D.getModel(); D.checkInternalConsistency(); D.checkConsistency(); numErrors = (int)D.getNumErrors(); assertTrue( numErrors == 1 ); error = D.getError(0); int errorId = (int)error.getErrorId(); assertTrue( errorId == libsbml.NoBodyInFunctionDef ); assertTrue( M.getNumFunctionDefinitions() == 1 ); fd = M.getFunctionDefinition(0); assertTrue( fd != null ); assertEquals( true, fd.isSetId() ); assertEquals( false, fd.isSetName() ); assertTrue(( "invalid" == fd.getId() )); assertTrue( fd.getBody() == null ); assertEquals( true, fd.isSetMath() ); math = fd.getMath(); formula = libsbml.formulaToString(math); assertTrue( formula != null ); assertTrue(( "lambda(x, y, z)" == formula )); }
public void test_internal_consistency_check_21117() { SBMLDocument d = new SBMLDocument(3,1); long errors; Model m = d.createModel(); Reaction r = m.createReaction(); r.setId("r"); r.setReversible(true); r.setFast(false); SpeciesReference sr = r.createReactant(); sr.setSpecies("s"); sr.setConstant(true); ModifierSpeciesReference msr = r.createModifier(); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21117 ); msr.setSpecies("s"); d.getErrorLog().clearLog(); errors = d.checkInternalConsistency(); assertTrue( errors == 0 ); d = null; }
//=============================================================================== // // // Helper functions for writing/validating the given SBML documents. // // //=============================================================================== /** * * Validates the given SBMLDocument. * * This function is based on validateSBML.cpp implemented by * Sarah Keating, Ben Bornstein, and Michael Hucka. * */ private static bool validateExampleSBML(SBMLDocument sbmlDoc) { if (sbmlDoc == null) { Console.Error.WriteLine("validateExampleSBML: given a null SBML Document"); return false; } string consistencyMessages = ""; string validationMessages = ""; bool noProblems = true; int numCheckFailures = 0; int numConsistencyErrors = 0; int numConsistencyWarnings = 0; int numValidationErrors = 0; int numValidationWarnings = 0; // LibSBML 3.3 is lenient when generating models from scratch using the // API for creating objects. Once the whole model is done and before it // gets written out, it's important to check that the whole model is in // fact complete, consistent and valid. numCheckFailures = (int)sbmlDoc.checkInternalConsistency(); if (numCheckFailures > 0) { noProblems = false; for (int i = 0; i < numCheckFailures; i++) { SBMLError sbmlErr = sbmlDoc.getError(i); if (sbmlErr.isFatal() || sbmlErr.isError()) { ++numConsistencyErrors; } else { ++numConsistencyWarnings; } } consistencyMessages = sbmlDoc.getErrorLog().toString(); } // If the internal checks fail, it makes little sense to attempt // further validation, because the model may be too compromised to // be properly interpreted. if (numConsistencyErrors > 0) { consistencyMessages += "Further validation aborted."; } else { numCheckFailures = (int)sbmlDoc.checkConsistency(); if (numCheckFailures > 0) { noProblems = false; for (int i = 0; i < numCheckFailures; i++) { SBMLError sbmlErr = sbmlDoc.getError(i); if (sbmlErr.isFatal() || sbmlErr.isError()) { ++numValidationErrors; } else { ++numValidationWarnings; } } validationMessages = sbmlDoc.getErrorLog().toString(); } } if (noProblems) return true; else { if (numConsistencyErrors > 0) { Console.WriteLine("ERROR: encountered " + numConsistencyErrors + " consistency error" + (numConsistencyErrors == 1 ? "" : "s") + " in model '" + sbmlDoc.getModel().getId() + "'."); } if (numConsistencyWarnings > 0) { Console.WriteLine("Notice: encountered " + numConsistencyWarnings + " consistency warning" + (numConsistencyWarnings == 1 ? "" : "s") + " in model '" + sbmlDoc.getModel().getId() + "'."); } Console.WriteLine(); Console.WriteLine(consistencyMessages); if (numValidationErrors > 0) { Console.WriteLine("ERROR: encountered " + numValidationErrors + " validation error" + (numValidationErrors == 1 ? "" : "s") + " in model '" + sbmlDoc.getModel().getId() + "'."); } if (numValidationWarnings > 0) { Console.WriteLine("Notice: encountered " + numValidationWarnings + " validation warning" + (numValidationWarnings == 1 ? "" : "s") + " in model '" + sbmlDoc.getModel().getId() + "'."); } Console.WriteLine(); Console.WriteLine(validationMessages); return (numConsistencyErrors == 0 && numValidationErrors == 0); } }
public void test_internal_consistency_check_99911_ea() { SBMLDocument d = new SBMLDocument(2,4); d.setLevelAndVersion(2,1,false); long errors; Model m = d.createModel(); Compartment c = m.createCompartment(); c.setId("c"); c.setConstant(false); Event e = m.createEvent(); ASTNode ast = libsbml.parseFormula("2*x"); Trigger t = e.createTrigger(); t.setMath(ast); EventAssignment ea = new EventAssignment(2,4); ea.setVariable("c"); ea.setSBOTerm(2); ea.setMath(ast); e.addEventAssignment(ea); errors = d.checkInternalConsistency(); assertTrue( errors == 1 ); assertTrue( d.getError(0).getErrorId() == 21203 ); d = null; }