void test000053::test4_bug1000() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000053::MODEL_STRING_4)); const CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); CPPUNIT_ASSERT(pModel->getModelValues().size() == 0); CPPUNIT_ASSERT(pModel->getReactions().size() == 0); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1); const CMetab* pMetab = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "A"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); const CEvaluationNode* pRoot = pExpr->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(pRoot->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pRoot->subType()) == CEvaluationNode::S_DOUBLE); const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pRoot); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 1.5) / 1.5) < 1e-6); }
void test000080::test_mass_action_recognition_bug() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; try { CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000080::MODEL_STRING1)); } catch (...) { // there should not be an exception CPPUNIT_ASSERT(false); } const CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getReactions().size() == 1); const CReaction* pReaction = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction != NULL); const CFunction* pFun = pReaction->getFunction(); CPPUNIT_ASSERT(pFun != NULL); CPPUNIT_ASSERT(pFun->getType() == CEvaluationTree::UserDefined); }
void test000047::test_delay() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); 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() == 2); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::FIXED); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pA->getExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeDelay* pDelayNode = dynamic_cast<const CEvaluationNodeDelay*>(pNode); CPPUNIT_ASSERT(pDelayNode != NULL); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pDelayNode->getChild()); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); std::vector<CCopasiContainer*> listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Concentration")); CPPUNIT_ASSERT(pObject->getObjectParent() == pB); const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.5) / 0.5) < 1e-3); CPPUNIT_ASSERT(pNumberNode->getSibling() == NULL); CPPUNIT_ASSERT(pModel->getModelValues().size() == 1); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModel->getReactions().size() == 0); //CPPUNIT_ASSERT(CCopasiMessage::size() == 2); CCopasiMessage message = CCopasiMessage::getLastMessage(); CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING); std::string s = message.getText(); CPPUNIT_ASSERT(!s.empty()); CPPUNIT_ASSERT(s.find(std::string("COPASI does not support time delays. Calculations on this model will most likely lead to unusable results.")) != std::string::npos); // right now, we don't care about the last message since it is a units // warning from libSBML }
void test000046::test_stoichiometricExpression() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::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() == 2); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS); CPPUNIT_ASSERT(pModel->getModelValues().size() == 1); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(fabs((pModelValue->getInitialValue() - 3.7) / 3.7) < 1e-3); CPPUNIT_ASSERT(pModel->getReactions().size() == 1); const CReaction* pReaction1 = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction1 != NULL); CPPUNIT_ASSERT(pReaction1->isReversible() == true); // check the kinetic law const CFunction* pKineticFunction = pReaction1->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction); CPPUNIT_ASSERT(pMassAction != NULL); const CChemEq* pChemEq = &pReaction1->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); const CChemEqElement* pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 1.85) / 1.85) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1); pElement = pChemEq->getProducts()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs((pElement->getMultiplicity() - 3.35) / 3.35) / 3.35 < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pB); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); //CPPUNIT_ASSERT(CCopasiMessage::size() == 5); CCopasiMessage message = CCopasiMessage::getLastMessage(); CPPUNIT_ASSERT(message.getType() == CCopasiMessage::WARNING); std::string s = message.getText(); CPPUNIT_ASSERT(!s.empty()); CPPUNIT_ASSERT(s.find(std::string("One or more stoichiometric expressions were evaluated and converted to constants values.")) != std::string::npos); // the other four messages are libSBML unit warnings I don't care about right // now. }
void test000052::test_bug988() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::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() == 1); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pA->getExpressionPtr(); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pNode); CPPUNIT_ASSERT(pChoiceNode != NULL); pNode = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeLogical* pLogicalNode = dynamic_cast<const CEvaluationNodeLogical*>(pNode); CPPUNIT_ASSERT(pLogicalNode != NULL); CPPUNIT_ASSERT(((CEvaluationNodeLogical::SubType)CEvaluationNode::subType(pLogicalNode->getType())) == CEvaluationNodeLogical::LT); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pLogicalNode->getChild()); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); std::vector<CCopasiContainer*> listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time")); CPPUNIT_ASSERT(pObject->getObjectParent() == pModel); const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 5.0) / 5.0) < 1e-3); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pLogicalNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE); CPPUNIT_ASSERT(pNumberNode->getValue() < 1e-3); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNumberNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(((CEvaluationNodeNumber::SubType)CEvaluationNode::subType(pNumberNode->getType())) == CEvaluationNodeNumber::DOUBLE); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-3); CPPUNIT_ASSERT(pModel->getModelValues().size() == 0); CPPUNIT_ASSERT(pModel->getReactions().size() == 0); }
void test000027::test_hasOnlySubstanceUnits() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); 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() == 2); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS); CPPUNIT_ASSERT(pModel->getModelValues().size() == 2); // check the kinetic law const CModelValue* pFactor = pModel->getModelValues()[1]; CPPUNIT_ASSERT(pFactor != NULL); CPPUNIT_ASSERT(pFactor->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(fabs((pFactor->getInitialValue() - pModel->getQuantity2NumberFactor()) / pModel->getQuantity2NumberFactor()) < 1e-3); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pModelValue->getExpressionPtr(); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("ParticleNumber")); CPPUNIT_ASSERT(pObject->getObjectParent() == pA); CPPUNIT_ASSERT(pModel->getReactions().size() == 2); const CReaction* pReaction1 = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction1 != NULL); CPPUNIT_ASSERT(pReaction1->isReversible() == false); const CFunction* pKineticFunction = pReaction1->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction); //FTB: this no longer is recognized as mass action reaction because of the // special case of a species with hOSU CPPUNIT_ASSERT(pMassAction == NULL); const CChemEq* pChemEq = &pReaction1->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); const CChemEqElement* pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const CReaction* pReaction2 = pModel->getReactions()[1]; CPPUNIT_ASSERT(pReaction2 != NULL); CPPUNIT_ASSERT(pReaction2->isReversible() == false); // check the kinetic law pKineticFunction = pReaction2->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)")); // check the function parameters one should be the reference to the substrate pChemEq = &pReaction2->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1); pElement = pChemEq->getProducts()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pB); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings(); CPPUNIT_ASSERT(parameterMappings.size() == 3); CPPUNIT_ASSERT(parameterMappings[0].size() == 1); const std::string parameterKey = parameterMappings[0][0]; CPPUNIT_ASSERT(parameterKey == pA->getKey()); }
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 test000043::test_hasOnlySubstanceUnits() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::number); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); 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() == 2); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS); CPPUNIT_ASSERT(pModel->getModelValues().size() == 1); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModelValue->getInitialExpression() != ""); const CExpression* pExpr = pModelValue->getInitialExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber")); CPPUNIT_ASSERT(pObject->getObjectParent() == pA); // check the reactions CPPUNIT_ASSERT(pModel->getReactions().size() == 2); const CReaction* pReaction1 = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction1 != NULL); CPPUNIT_ASSERT(pReaction1->isReversible() == false); // check the kinetic law const CFunction* pKineticFunction = pReaction1->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction); //FTB: this no longer is recognized as mass action reaction because of the // special case of a species with hOSU CPPUNIT_ASSERT(pMassAction == NULL); const CChemEq* pChemEq = &pReaction1->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); const CChemEqElement* pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const CReaction* pReaction2 = pModel->getReactions()[1]; CPPUNIT_ASSERT(pReaction2 != NULL); CPPUNIT_ASSERT(pReaction2->isReversible() == false); // check the kinetic law pKineticFunction = pReaction2->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Function for reaction_1")); const CFunctionParameters* pFunctionParameters = &pKineticFunction->getVariables(); CPPUNIT_ASSERT(pFunctionParameters->size() == 4); const CFunctionParameter* pFunctionParameter = (*pFunctionParameters)[0]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER); pFunctionParameter = (*pFunctionParameters)[1]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER); pFunctionParameter = (*pFunctionParameters)[2]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::VOLUME); pFunctionParameter = (*pFunctionParameters)[3]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::SUBSTRATE); pNode = pKineticFunction->getRoot(); const CEvaluationNodeCall* pCallNode = dynamic_cast<const CEvaluationNodeCall*>(pNode); CPPUNIT_ASSERT(pCallNode != NULL); CPPUNIT_ASSERT((pCallNode->subType()) == CEvaluationNode::S_FUNCTION); CPPUNIT_ASSERT(pCallNode->getData() == std::string("Henri-Michaelis-Menten (irreversible)_2")); const CEvaluationNodeOperator* pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pCallNode->getChild()); CPPUNIT_ASSERT(pOperatorNode != NULL); CPPUNIT_ASSERT((pOperatorNode->subType()) == CEvaluationNode::S_MULTIPLY); const CEvaluationNodeVariable* pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 3); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 2); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 1); pKineticFunction = dynamic_cast<const CFunction*>(pCallNode->getCalledTree()); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)_2")); pNode = pKineticFunction->getRoot(); CPPUNIT_ASSERT(pNode != NULL); pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode); CPPUNIT_ASSERT(pOperatorNode != NULL); CPPUNIT_ASSERT((pOperatorNode->subType()) == CEvaluationNode::S_DIVIDE); const CEvaluationNodeOperator* pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild()); CPPUNIT_ASSERT(pOperatorNode2 != NULL); CPPUNIT_ASSERT((pOperatorNode2->subType()) == CEvaluationNode::S_MULTIPLY); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 2); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild()->getSibling()); CPPUNIT_ASSERT(pOperatorNode2 != NULL); CPPUNIT_ASSERT((pOperatorNode2->subType()) == CEvaluationNode::S_PLUS); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 1); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); // check the function parameters one should be the reference to the substrate pChemEq = &pReaction2->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1); pElement = pChemEq->getProducts()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pB); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings(); CPPUNIT_ASSERT(parameterMappings.size() == 4); CPPUNIT_ASSERT(parameterMappings[2].size() == 1); std::string parameterKey = parameterMappings[2][0]; CPPUNIT_ASSERT(parameterKey == pCompartment->getKey()); CPPUNIT_ASSERT(parameterMappings[3].size() == 1); parameterKey = parameterMappings[3][0]; CPPUNIT_ASSERT(parameterKey == pA->getKey()); }
void test000053::test5_bug1000() { // load the CPS file // export to SBML // check the resulting SBML model CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000053::MODEL_STRING_5)); const CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); CPPUNIT_ASSERT(pModel->getModelValues().size() == 0); CPPUNIT_ASSERT(pModel->getReactions().size() == 0); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1); const CMetab* pMetab = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pMetab != NULL); CPPUNIT_ASSERT(pMetab->getObjectName() == "A"); CPPUNIT_ASSERT(pMetab->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pMetab->getExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); const CEvaluationNode* pRoot = pExpr->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(pRoot->mainType() == CEvaluationNode::T_CHOICE); const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pRoot); CPPUNIT_ASSERT(pChoiceNode != NULL); const CEvaluationNode* pChild1 = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); const CEvaluationNode* pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.1) / 0.1) < 1e-6); const CEvaluationNode* pChild3 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling()); CPPUNIT_ASSERT(pChild3 != NULL); CPPUNIT_ASSERT(pChild3->mainType() == CEvaluationNode::T_CHOICE); pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pChild3); CPPUNIT_ASSERT(pChoiceNode); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_LOGICAL); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_LT); pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild1); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6); // second choice level (child3 of first choice level) pChild1 = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.2) / 0.2) < 1e-6); pChild3 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling()); CPPUNIT_ASSERT(pChild3 != NULL); CPPUNIT_ASSERT(pChild3->mainType() == CEvaluationNode::T_CHOICE); pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pChild3); CPPUNIT_ASSERT(pChoiceNode); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_LOGICAL); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_GT); pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild1); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6); // third choice level (child3 of second choice level) pChild1 = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.3) / 0.3) < 1e-6); pChild3 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling()); CPPUNIT_ASSERT(pChild3 != NULL); CPPUNIT_ASSERT(pChild3->mainType() == CEvaluationNode::T_CHOICE); pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pChild3); CPPUNIT_ASSERT(pChoiceNode); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_LOGICAL); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_LE); pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild1); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6); // fourth choice level (child3 of third choice level) pChild1 = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 0.4) / 0.4) < 1e-6); pChild3 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling()); CPPUNIT_ASSERT(pChild3 != NULL); // the third child of the fourth choice level must be the otherwise element CPPUNIT_ASSERT(pChild3->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild3->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild3); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 1.5) / 1.5) < 1e-6); CPPUNIT_ASSERT(pChild3->getSibling() == NULL); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_LOGICAL); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_EQ); pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getChild()); CPPUNIT_ASSERT(pChild1 != NULL); CPPUNIT_ASSERT(pChild1->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild1->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild1); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 3.0) / 3.0) < 1e-6); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); CPPUNIT_ASSERT(pChild2 != NULL); CPPUNIT_ASSERT(pChild2->mainType() == CEvaluationNode::T_NUMBER); CPPUNIT_ASSERT((pChild2->subType()) == CEvaluationNode::S_DOUBLE); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pChild2); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 4.0) / 4.0) < 1e-6); }