// test whether exporting an SBML Level 3 file after an SBML Level 2 file // succeeds void test000100::test_bug1692_1() { CPPUNIT_ASSERT(pDataModel != NULL); std::istringstream iss(test000100::CPS_STRING); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); std::string s; try { s = pDataModel->exportSBMLToString(NULL, 2, 1); } catch (...) { CPPUNIT_ASSERT_MESSAGE("The first export to Level 2 Version 1 failed.", false); } try { s = pDataModel->exportSBMLToString(NULL, 3, 1); } catch (...) { CPPUNIT_ASSERT_MESSAGE("The second export to Level 3 Version 1 failed.", false); } }
void test000081::test_bug1205() { CDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000081::MODEL_STRING1); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CPPUNIT_ASSERT(pDataModel->getModel() != NULL); const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument == NULL); std::string sbmlString; try { sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1); } catch (...) { // fail if an uncaught exception occurs during export CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(!sbmlString.empty()); // check if the exported SBML model has three compartments pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); const Model* pModel = pDocument->getModel(); CPPUNIT_ASSERT(pModel != NULL); unsigned int iMax = pModel->getListOfCompartments()->size(); CPPUNIT_ASSERT(iMax == 3); // check that the compartment named compartment_2 has the id compartment_1 const Compartment* pCompartment = pModel->getCompartment("compartment_1"); CPPUNIT_ASSERT(pCompartment != NULL); CPPUNIT_ASSERT(pCompartment->getName() == "compartment_2"); // check if the exported SBML model has three species iMax = pModel->getListOfSpecies()->size(); CPPUNIT_ASSERT(iMax == 3); // check that the species named species_2 has the id species_1 const Species* pSpecies = pModel->getSpecies("species_1"); CPPUNIT_ASSERT(pSpecies != NULL); CPPUNIT_ASSERT(pSpecies->getName() == "species_2"); // check if the exported SBML model has three parameters iMax = pModel->getListOfParameters()->size(); CPPUNIT_ASSERT(iMax == 3); // check that the parameter named quantity_2 has the id parameter_1 const Parameter* pParameter = pModel->getParameter("parameter_1"); CPPUNIT_ASSERT(pParameter != NULL); CPPUNIT_ASSERT(pParameter->getName() == "quantity_2"); // check if the exported SBML model has three reactions iMax = pModel->getListOfReactions()->size(); CPPUNIT_ASSERT(iMax == 3); // check that the reaction named reaction_2 has the id reaction_1 const Reaction* pReaction = pModel->getReaction("reaction_1"); CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getName() == "reaction_2"); }
void test000087::test_export_reaction_flux_reference_1() { try { std::istringstream iss(test000087::MODEL_STRING4); bool result = load_cps_model_from_stream(iss, *pCOPASIDATAMODEL); CPPUNIT_ASSERT(result == true); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel() != NULL); } catch (...) { // there should be no exception CPPUNIT_ASSERT(false); } try { CPPUNIT_ASSERT(pCOPASIDATAMODEL->exportSBMLToString(NULL, 2, 3).empty() == false); } catch (...) { // there should be no exception CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(CCopasiMessage::size() == 0); const SBMLDocument* pDocument = pCOPASIDATAMODEL->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); CPPUNIT_ASSERT(pDocument->getLevel() == 2); CPPUNIT_ASSERT(pDocument->getVersion() == 3); const Model* pModel = pDocument->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getListOfFunctionDefinitions()->size() == 0); CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1); CPPUNIT_ASSERT(pModel->getListOfSpecies()->size() == 3); CPPUNIT_ASSERT(pModel->getListOfReactions()->size() == 1); CPPUNIT_ASSERT(pModel->getListOfRules()->size() == 1); const Reaction* pReaction = pModel->getReaction(0); CPPUNIT_ASSERT(pReaction != NULL); std::string reactionId = pReaction->getId(); CPPUNIT_ASSERT(reactionId.empty() == false); const Rule* pRule = pModel->getRule(0); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); const AssignmentRule* pAssignmentRule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pAssignmentRule != NULL); const Species* pSpecies = pModel->getSpecies(pAssignmentRule->getVariable()); CPPUNIT_ASSERT(pSpecies != NULL); CPPUNIT_ASSERT(pSpecies->getName() == "C"); const ASTNode* pMath = pAssignmentRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getName() == reactionId); }
void test000087::test_export_reaction_flux_reference_2() { try { std::istringstream iss(test000087::MODEL_STRING4); bool result = load_cps_model_from_stream(iss, *pCOPASIDATAMODEL); CPPUNIT_ASSERT(result == true); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel() != NULL); } catch (...) { // there should be no exception CPPUNIT_ASSERT(false); } try { std::string result = pCOPASIDATAMODEL->exportSBMLToString(NULL, 2, 1); CPPUNIT_ASSERT(result.empty()); } catch (...) { // there should be an exception // check if the correct error message has been created CPPUNIT_ASSERT(pCOPASIDATAMODEL->getCurrentSBMLDocument() == NULL); // last message should be an exception CCopasiMessage message = CCopasiMessage::getLastMessage(); CPPUNIT_ASSERT(message.getType() == CCopasiMessage::EXCEPTION); // see if the incompatibility message is there bool found = false; while (CCopasiMessage::size() > 0) { message = CCopasiMessage::getLastMessage(); if (message.getType() == CCopasiMessage::RAW) { std::string s = message.getText(); if (s.find(std::string("SBML Incompatibility (10)")) != std::string::npos) { found = true; break; } } } CPPUNIT_ASSERT_MESSAGE("Error message not found.", found == true); return; } CPPUNIT_ASSERT(false); }
void test000061::test_bug_1044() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000061::MODEL_STRING1); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); // check if the model has been loaded correctly CPPUNIT_ASSERT(pModel->getModelValues().size() == 1); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getObjectName() == "A"); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::ASSIGNMENT); CPPUNIT_ASSERT(pModelValue->getExpressionPtr() != NULL); const CEvaluationNode* pRoot = pModelValue->getExpressionPtr()->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(CEvaluationNode::type(pRoot->getType()) == CEvaluationNode::INVALID); const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument == NULL); // export the model to SBML bool exception = false; try { CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 1).empty() == true); } catch (...) { exception = true; } CPPUNIT_ASSERT(exception == true); CPPUNIT_ASSERT(pDataModel->getCurrentSBMLDocument() == NULL); // check if the correct error message has been created. const CCopasiMessage& message = CCopasiMessage::getLastMessage(); CPPUNIT_ASSERT(message.getNumber() == MCSBML + 70); CPPUNIT_ASSERT(message.getType() == CCopasiMessage::EXCEPTION); CPPUNIT_ASSERT(CCopasiMessage::size() == 0); }
void test_compare_utilities::test_copasi_function_expansion() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;; std::istringstream iss(test_compare_utilities::MODEL_STRING1); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CFunctionDB* pFunctionDB = CCopasiRootContainer::getFunctionList(); // function_5 CEvaluationTree* pTree = pFunctionDB->findFunction("function_4"); CPPUNIT_ASSERT(pTree != NULL); // generate a call node CFunction* pFunction = dynamic_cast<CFunction*>(pTree); CPPUNIT_ASSERT(pFunction != NULL); CEvaluationNodeCall* pCallNode = new CEvaluationNodeCall(CEvaluationNode::S_FUNCTION, pFunction->getObjectName()); CPPUNIT_ASSERT(pCallNode != NULL); CFunctionParameters* pFunctionParameters = &pFunction->getVariables(); unsigned int i = 0, iMax = pFunctionParameters->size(); while (i < iMax) { CFunctionParameter* pParameter = (*pFunctionParameters)[i]; CPPUNIT_ASSERT(pParameter != NULL); CEvaluationNodeVariable* pVariableNode = new CEvaluationNodeVariable(CEvaluationNode::S_DEFAULT, pParameter->getObjectName()); pCallNode->addChild(pVariableNode); ++i; } CEvaluationNode* pExpanded = expand_function_calls(pCallNode, pFunctionDB); delete pCallNode; CPPUNIT_ASSERT(pExpanded != NULL); CPPUNIT_ASSERT(pExpanded->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pExpanded->subType() == CEvaluationNode::S_DIVIDE); CEvaluationNode* pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_PLUS); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("y")); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("x")); CPPUNIT_ASSERT(pChild->getSibling() == NULL); pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 2.0) / 2.0) < 1e-6); CPPUNIT_ASSERT(pChild->getSibling() == NULL); delete pExpanded; // function_5 pTree = pFunctionDB->findFunction("function_5"); CPPUNIT_ASSERT(pTree != NULL); // generate a call node pFunction = dynamic_cast<CFunction*>(pTree); CPPUNIT_ASSERT(pFunction != NULL); pCallNode = new CEvaluationNodeCall(CEvaluationNode::S_FUNCTION, pFunction->getObjectName()); CPPUNIT_ASSERT(pCallNode != NULL); pFunctionParameters = &pFunction->getVariables(); i = 0, iMax = pFunctionParameters->size(); while (i < iMax) { CFunctionParameter* pParameter = (*pFunctionParameters)[i]; CPPUNIT_ASSERT(pParameter != NULL); CEvaluationNodeVariable* pVariableNode = new CEvaluationNodeVariable(CEvaluationNode::S_DEFAULT, pParameter->getObjectName()); pCallNode->addChild(pVariableNode); ++i; } pExpanded = expand_function_calls(pCallNode, pFunctionDB); delete pCallNode; CPPUNIT_ASSERT(pExpanded != NULL); CPPUNIT_ASSERT(pExpanded->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pExpanded->subType() == CEvaluationNode::S_PLUS); pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MINUS); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("a")); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MULTIPLY); CPPUNIT_ASSERT(pChild->getSibling() == NULL); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("c")); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 1.3) / 1.3) < 1e-6); CPPUNIT_ASSERT(pChild->getSibling() == NULL); // (3*b)-5.23 pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MINUS); // 3*b pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MULTIPLY); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 3.0) / 3.0) < 1e-6); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("b")); CPPUNIT_ASSERT(pChild->getSibling() == NULL); // 5.23 pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()->getChild()->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 5.23) / 5.23) < 1e-6); CPPUNIT_ASSERT(pChild->getSibling() == NULL); delete pExpanded; // function_6 pTree = pFunctionDB->findFunction("function_6"); CPPUNIT_ASSERT(pTree != NULL); // generate a call node pFunction = dynamic_cast<CFunction*>(pTree); CPPUNIT_ASSERT(pFunction != NULL); pCallNode = new CEvaluationNodeCall(CEvaluationNode::S_FUNCTION, pFunction->getObjectName()); CPPUNIT_ASSERT(pCallNode != NULL); pFunctionParameters = &pFunction->getVariables(); i = 0, iMax = pFunctionParameters->size(); while (i < iMax) { CFunctionParameter* pParameter = (*pFunctionParameters)[i]; CPPUNIT_ASSERT(pParameter != NULL); CEvaluationNodeVariable* pVariableNode = new CEvaluationNodeVariable(CEvaluationNode::S_DEFAULT, pParameter->getObjectName()); pCallNode->addChild(pVariableNode); ++i; } pExpanded = expand_function_calls(pCallNode, pFunctionDB); delete pCallNode; CPPUNIT_ASSERT(pExpanded != NULL); // (k1-k3*1.3)+((3*k2)-5.23) CPPUNIT_ASSERT(pExpanded->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pExpanded->subType() == CEvaluationNode::S_PLUS); pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MINUS); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("k1")); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MULTIPLY); CPPUNIT_ASSERT(pChild->getSibling() == NULL); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("k3")); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 1.3) / 1.3) < 1e-6); CPPUNIT_ASSERT(pChild->getSibling() == NULL); // (3*b)-5.23 pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MINUS); // 3*b pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_OPERATOR); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_MULTIPLY); pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 3.0) / 3.0) < 1e-6); pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling()); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_VARIABLE); CPPUNIT_ASSERT(pChild->getData() == std::string("k2")); CPPUNIT_ASSERT(pChild->getSibling() == NULL); // 5.23 pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()->getChild()->getSibling()); CPPUNIT_ASSERT(pChild != NULL); CPPUNIT_ASSERT(pChild->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT(pChild->subType() == CEvaluationNode::S_DOUBLE); CPPUNIT_ASSERT((fabs(pChild->getValue() - 5.23) / 5.23) < 1e-6); CPPUNIT_ASSERT(pChild->getSibling() == NULL); delete pExpanded; }
void test000009::test_references_to_species() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000009::MODEL_STRING); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CPPUNIT_ASSERT(pDataModel->getModel() != NULL); CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false); SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); Model* pModel = pDocument->getModel(); CPPUNIT_ASSERT(pModel != NULL); // assert that there is only one compartment and // assert the compartment is constant CPPUNIT_ASSERT(pModel->getNumCompartments() == 1); Compartment* pCompartment = pModel->getCompartment(0); CPPUNIT_ASSERT(pCompartment->getConstant() == false); CPPUNIT_ASSERT(pModel->getNumSpecies() == 2); Species* pSpecies = pModel->getSpecies(1); CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true); pSpecies = pModel->getSpecies(0); std::string idSpeciesA = pSpecies->getId(); CPPUNIT_ASSERT(pSpecies->getHasOnlySubstanceUnits() == true); CPPUNIT_ASSERT(pModel->getNumRules() == 2); // there are two rules, one is the rule for the compartment AssignmentRule* pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(0)); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pModel->getNumParameters() == 1); Parameter* pParameter = pModel->getParameter(0); CPPUNIT_ASSERT(pParameter != NULL); if (pRule->getVariable() != pParameter->getId()) { pRule = dynamic_cast<AssignmentRule*>(pModel->getRule(1)); } CPPUNIT_ASSERT(pRule->getVariable() == pParameter->getId()); const ASTNode* pMath = pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // the expression should be the species divided by the volume CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE); CPPUNIT_ASSERT(pMath->getChild(0) != NULL); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pSpecies->getId()); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId()); CPPUNIT_ASSERT(pModel->getNumReactions() == 2); Reaction* pReaction = pModel->getReaction(0); // make sure this is reaction A -> CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getNumReactants() == 1); CPPUNIT_ASSERT(pReaction->getNumProducts() == 0); // check if all references in the kinetic law are unmodified // math element must be a multiplication of the mass action term by // the compartment volume // the mass action term is a multiplication of the parameter node by // the species node // the code that multiplies the reaction by the compartments volume // recognizes the division of the species by the compartment and cancels // those two CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true); KineticLaw* pLaw = pReaction->getKineticLaw(); CPPUNIT_ASSERT(pLaw != NULL); CPPUNIT_ASSERT(pLaw->isSetMath() == true); pMath = pLaw->getMath(); CPPUNIT_ASSERT(pMath->getType() == AST_TIMES); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == std::string("k1")); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == idSpeciesA); pReaction = pModel->getReaction(1); // make sure this is reaction A -> S CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getNumReactants() == 1); CPPUNIT_ASSERT(pReaction->getNumProducts() == 1); // check if all references in the kinetic law are unmodified // math element must be a multiplication of the compartments volume with // a function call with three arguments // the first argument is the reference to the species CPPUNIT_ASSERT(pReaction->isSetKineticLaw() == true); pLaw = pReaction->getKineticLaw(); CPPUNIT_ASSERT(pLaw != NULL); CPPUNIT_ASSERT(pLaw->isSetMath() == true); pMath = pLaw->getMath(); CPPUNIT_ASSERT(pMath->getType() == AST_TIMES); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == pCompartment->getId()); pMath = pMath->getChild(1); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION); CPPUNIT_ASSERT(pMath->getNumChildren() == 3); pMath = pMath->getChild(0); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); CPPUNIT_ASSERT(pMath->getChild(0) != NULL); CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(0)->getName() == idSpeciesA); CPPUNIT_ASSERT(pMath->getChild(1) != NULL); CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getChild(1)->getName() == pCompartment->getId()); }
// tests whether we are importing global render information void test000098::test_export_notes() { CPPUNIT_ASSERT(pDataModel != NULL); std::istringstream iss(test000098::CPS_MODEL_1); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); std::string s; try { s = pDataModel->exportSBMLToString(NULL, 2, 1); } catch (...) { CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(!s.empty()); SBMLReader reader; SBMLDocument* pSBMLDocument = NULL; try { pSBMLDocument = reader.readSBMLFromString(s); } catch (...) { CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(pSBMLDocument != NULL); Model* pModel = pSBMLDocument->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->isSetNotes() == true); std::string notes = pModel->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on model") != std::string::npos); CPPUNIT_ASSERT(pModel->getNumCompartments() == 1); CPPUNIT_ASSERT(pModel->getNumSpecies() == 1); CPPUNIT_ASSERT(pModel->getNumParameters() == 1); CPPUNIT_ASSERT(pModel->getNumReactions() == 1); CPPUNIT_ASSERT(pModel->getNumEvents() == 1); // compartment SBase* pObject = pModel->getCompartment(0); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isSetNotes() == true); notes = pObject->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on compartment") != std::string::npos); // species pObject = pModel->getSpecies(0); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isSetNotes() == true); notes = pObject->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on species") != std::string::npos); // parameter pObject = pModel->getParameter(0); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isSetNotes() == true); notes = pObject->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on parameter") != std::string::npos); // reaction pObject = pModel->getReaction(0); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isSetNotes() == true); notes = pObject->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on reaction") != std::string::npos); // event pObject = pModel->getEvent(0); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isSetNotes() == true); notes = pObject->getNotesString(); CPPUNIT_ASSERT(!notes.empty()); CPPUNIT_ASSERT(notes.find("Simple note on event") != std::string::npos); }
void test000054::test_bug1002() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; std::istringstream iss(test000054::MODEL_STRING); CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true); CPPUNIT_ASSERT(pDataModel->getModel() != NULL); CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false); SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); Model* pSBMLModel = pDocument->getModel(); CPPUNIT_ASSERT(pSBMLModel != NULL); CPPUNIT_ASSERT(pSBMLModel->getNumCompartments() == 0); CPPUNIT_ASSERT(pSBMLModel->getNumSpecies() == 0); CPPUNIT_ASSERT(pSBMLModel->getNumReactions() == 0); CPPUNIT_ASSERT(pSBMLModel->getNumInitialAssignments() == 0); CPPUNIT_ASSERT(pSBMLModel->getNumParameters() == 5); const Parameter* pParameter1 = pSBMLModel->getParameter(0); CPPUNIT_ASSERT(pParameter1 != NULL); CPPUNIT_ASSERT(pParameter1->getConstant() == false); const Parameter* pParameter2 = pSBMLModel->getParameter(1); CPPUNIT_ASSERT(pParameter2 != NULL); CPPUNIT_ASSERT(pParameter2->getConstant() == false); const Parameter* pParameter3 = pSBMLModel->getParameter(2); CPPUNIT_ASSERT(pParameter3 != NULL); CPPUNIT_ASSERT(pParameter3->getConstant() == false); const Parameter* pParameter4 = pSBMLModel->getParameter(3); CPPUNIT_ASSERT(pParameter4 != NULL); CPPUNIT_ASSERT(pParameter4->getConstant() == false); const Parameter* pParameter5 = pSBMLModel->getParameter(4); CPPUNIT_ASSERT(pParameter5 != NULL); CPPUNIT_ASSERT(pParameter5->getConstant() == false); CPPUNIT_ASSERT(pSBMLModel->getNumRules() == 5); const Rule* pRule = pSBMLModel->getRule(0); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); const AssignmentRule* pARule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pARule != NULL); CPPUNIT_ASSERT(pARule->getVariable() == pParameter4->getId()); CPPUNIT_ASSERT(pARule->isSetMath() == true); const ASTNode* pMath = pARule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_PLUS); CPPUNIT_ASSERT(pMath->getNumChildren() == 2); const ASTNode* pChild1 = pMath->getChild(0); CPPUNIT_ASSERT(pChild1 != NULL); CPPUNIT_ASSERT(pChild1->getType() == AST_REAL); CPPUNIT_ASSERT(fabs((pChild1->getReal() - 2.0) / 2.0) < 1e-15); const ASTNode* pChild2 = pMath->getChild(1); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->getType() == AST_REAL); CPPUNIT_ASSERT(fabs((pChild2->getReal() - 4.0) / 4.0) < 1e-15); pRule = pSBMLModel->getRule(1); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); pARule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pARule != NULL); CPPUNIT_ASSERT(pARule->getVariable() == pParameter1->getId()); CPPUNIT_ASSERT(pARule->isSetMath() == true); pMath = pARule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getName() == pParameter4->getId()); CPPUNIT_ASSERT(pMath->getNumChildren() == 0); pRule = pSBMLModel->getRule(2); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); pARule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pARule != NULL); CPPUNIT_ASSERT(pARule->getVariable() == pParameter3->getId()); CPPUNIT_ASSERT(pARule->isSetMath() == true); pMath = pARule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId()); CPPUNIT_ASSERT(pMath->getNumChildren() == 0); pRule = pSBMLModel->getRule(3); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); pARule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pARule != NULL); CPPUNIT_ASSERT(pARule->getVariable() == pParameter5->getId()); CPPUNIT_ASSERT(pARule->isSetMath() == true); pMath = pARule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getName() == pParameter3->getId()); CPPUNIT_ASSERT(pMath->getNumChildren() == 0); pRule = pSBMLModel->getRule(4); CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE); pARule = dynamic_cast<const AssignmentRule*>(pRule); CPPUNIT_ASSERT(pARule != NULL); CPPUNIT_ASSERT(pARule->getVariable() == pParameter2->getId()); CPPUNIT_ASSERT(pARule->isSetMath() == true); pMath = pARule->getMath(); CPPUNIT_ASSERT(pMath != NULL); CPPUNIT_ASSERT(pMath->getType() == AST_NAME); CPPUNIT_ASSERT(pMath->getName() == pParameter5->getId()); CPPUNIT_ASSERT(pMath->getNumChildren() == 0); }