void test000068::test_bug1068() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING1)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::Mol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::l); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); const CCompartment* pCompartment = pModel->getCompartments()[0]; CPPUNIT_ASSERT(pCompartment != NULL); CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 6); // check metabolites const CMetab* pMetab = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "A"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::REACTIONS); pMetab = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "B"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::REACTIONS); pMetab = pModel->getMetabolites()[2]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "C"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ASSIGNMENT); // check assignment const CEvaluationTree* pTree = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); const CEvaluationNode* pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_5"); pMetab = pModel->getMetabolites()[3]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "D"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ODE); // check ode pTree = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_2"); pMetab = pModel->getMetabolites()[4]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "E"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ODE); // check ode pTree = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_4"); pMetab = pModel->getMetabolites()[5]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "F"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ODE); // check ode pTree = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_6"); // check model values CPPUNIT_ASSERT(pModel->getModelValues().size() == 3); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getObjectName() == "K1"); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::ASSIGNMENT); // check assignment pTree = pModelValue->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_1"); pModelValue = pModel->getModelValues()[1]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getObjectName() == "K2"); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED); pModelValue = pModel->getModelValues()[2]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getObjectName() == "K3"); // check assignment pTree = pModelValue->getExpressionPtr(); CPPUNIT_ASSERT(pTree != NULL); pRoot = pTree->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot) != NULL); CPPUNIT_ASSERT(dynamic_cast<const CEvaluationNodeCall*>(pRoot)->getData() == "function_3"); CPPUNIT_ASSERT(pModel->getReactions().size() == 6); // check reactions const CReaction* pReaction = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 1); const CFunction* pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction1"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); pReaction = pModel->getReactions()[1]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 2); pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction2"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); pReaction = pModel->getReactions()[2]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 1); pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction3"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); pReaction = pModel->getReactions()[3]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 0); pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction4"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); pReaction = pModel->getReactions()[4]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 2); pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction5"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); pReaction = pModel->getReactions()[5]; CPPUNIT_ASSERT(pReaction != NULL); CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == true); // check the kinetic law CPPUNIT_ASSERT(pReaction->getParameters().size() == 3); pFunction = pReaction->getFunction(); CPPUNIT_ASSERT(pFunction != NULL); CPPUNIT_ASSERT(pFunction->getType() == CEvaluationTree::UserDefined); CPPUNIT_ASSERT(pFunction->getObjectName() == "Function for reaction6"); pRoot = pFunction->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); // export to SBML std::string s = pDataModel->exportSBMLToString(NULL, 1, 2); CPPUNIT_ASSERT(s.empty() == false); // due to the bugfix for Bug 1086 and some issues with libsbml and the current exporter, // we now no longer have a L1 document in the datamodel if there was an SBMLDocument prior // to exporting to L1 already. // To test now, we have to call newModel on the datamodel to delete the old sbml document, // and reimport the exported model // This will also lead to a Level 2 Version 1 model since we convert all Level 1 model to // Level 2 Version 1 on import, but we can at least test if the export worked. pCOPASIDATAMODEL->newModel(NULL, true); CPPUNIT_ASSERT(pCOPASIDATAMODEL->importSBMLFromString(s)); // check the sbml model const SBMLDocument* pDocument = pCOPASIDATAMODEL->getCurrentSBMLDocument(); CPPUNIT_ASSERT(pDocument != NULL); CPPUNIT_ASSERT(pDocument->getLevel() == 2); CPPUNIT_ASSERT(pDocument->getVersion() == 1); const Model* pSBMLModel = pDocument->getModel(); CPPUNIT_ASSERT(pSBMLModel != NULL); CPPUNIT_ASSERT(pSBMLModel->getListOfFunctionDefinitions()->size() == 0); CPPUNIT_ASSERT(pSBMLModel->getListOfCompartments()->size() == 1); CPPUNIT_ASSERT(pSBMLModel->getListOfSpecies()->size() == 6); CPPUNIT_ASSERT(pSBMLModel->getListOfParameters()->size() == 3); CPPUNIT_ASSERT(pSBMLModel->getListOfRules()->size() == 6); CPPUNIT_ASSERT(pSBMLModel->getListOfReactions()->size() == 6); std::map<std::string, const Rule*> ruleMap; unsigned int i, iMax = pSBMLModel->getListOfRules()->size(); const Rule* pRule = NULL; for (i = 0; i < iMax; ++i) { pRule = pSBMLModel->getRule(i); ruleMap.insert(std::pair<std::string, const Rule*>(pRule->getVariable(), pRule)); } // check the rules std::map<std::string, const Rule*>::const_iterator pos = ruleMap.find("parameter_1"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "parameter_1"); const ASTNode* pMath = pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix std::string formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "3 * 4.5"); pos = ruleMap.find("parameter_3"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "parameter_3"); pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "parameter_1 - 2 * 1.3"); pos = ruleMap.find("species_3"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "species_3"); pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "parameter_1 - 3.5 * 1.3 + (3 * 2.4 - 5.23)"); pos = ruleMap.find("species_4"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "species_4"); pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "3.4 + parameter_1"); pos = ruleMap.find("species_5"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "species_5"); pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "(parameter_2 + 1.4) / 2"); pos = ruleMap.find("species_6"); CPPUNIT_ASSERT(pos != ruleMap.end()); pRule = pos->second; CPPUNIT_ASSERT(pRule != NULL); CPPUNIT_ASSERT(pRule->getVariable() == "species_6"); pRule->getMath(); CPPUNIT_ASSERT(pMath != NULL); // only check the infix formula = pRule->getFormula(); CPPUNIT_ASSERT(formula == "parameter_3 - 3.4 * 1.3 + (3 * parameter_1 - 5.23)"); // check the reactions const Reaction* pSBMLReaction = pSBMLModel->getReaction(0); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * 3 * parameter_1"); pSBMLReaction = pSBMLModel->getReaction(1); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * (parameter_2 + parameter_1)"); pSBMLReaction = pSBMLModel->getReaction(2); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * (species_2 - parameter_1 * 1.3)"); pSBMLReaction = pSBMLModel->getReaction(3); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * ((species_2 + species_1) / 2)"); pSBMLReaction = pSBMLModel->getReaction(4); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * (parameter_1 - species_2 * 1.3 + (3 * parameter_3 - 5.23))"); pSBMLReaction = pSBMLModel->getReaction(5); CPPUNIT_ASSERT(pSBMLReaction != NULL); CPPUNIT_ASSERT(pSBMLReaction->getListOfReactants()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfProducts()->size() == 1); CPPUNIT_ASSERT(pSBMLReaction->getListOfModifiers()->size() == 0); CPPUNIT_ASSERT(pSBMLReaction->getReversible() == true); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw() != NULL); CPPUNIT_ASSERT(pSBMLReaction->getKineticLaw()->getListOfParameters()->size() == 0); pMath = pSBMLReaction->getKineticLaw()->getMath(); CPPUNIT_ASSERT(pMath != NULL); formula = pSBMLReaction->getKineticLaw()->getFormula(); CPPUNIT_ASSERT(formula == "compartment_1 * (parameter_1 - parameter_3 * 1.3 + (3 * parameter_2 - 5.23))"); }
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()); }
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); }