END_TEST

START_TEST(test_SBMLTransforms_evaluateCustomAST)
{
  std::map<std::string, double> values;
  const char* formula = "a + b + c"; 

  ASTNode* node = SBML_parseFormula(formula);
  fail_unless(node != NULL);
  fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node, values)));
  values["a"] = 1;
  values["b"] = 1;
  fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node, values)));
  values["c"] = 1;
  fail_unless(SBMLTransforms::evaluateASTNode(node, values) == 3);
}
END_TEST


START_TEST (test_SBML_parseFormula_11)
{
  ASTNode_t *r = SBML_parseFormula("1 - -foo / 3");
  ASTNode_t *c;



  fail_unless( ASTNode_getType       (r) == AST_MINUS, NULL );
  fail_unless( ASTNode_getCharacter  (r) == '-', NULL );
  fail_unless( ASTNode_getNumChildren(r) == 2  , NULL );

  c = ASTNode_getLeftChild(r);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 1, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getRightChild(r);

  fail_unless( ASTNode_getType       (c) == AST_DIVIDE, NULL );
  fail_unless( ASTNode_getCharacter  (c) == '/', NULL );
  fail_unless( ASTNode_getNumChildren(c) == 2, NULL );

  c = ASTNode_getLeftChild( ASTNode_getRightChild(r) );

  fail_unless( ASTNode_getType       (c) == AST_MINUS, NULL );
  fail_unless( ASTNode_getCharacter  (c) == '-', NULL );
  fail_unless( ASTNode_getNumChildren(c) == 1  , NULL );

  c = ASTNode_getLeftChild( ASTNode_getLeftChild( ASTNode_getRightChild(r) ) );

  fail_unless( ASTNode_getType(c) == AST_NAME     , NULL );
  fail_unless( !strcmp(ASTNode_getName(c), "foo") , NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0     , NULL );

  c = ASTNode_getRightChild( ASTNode_getRightChild(r) );

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 3, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  ASTNode_free(r);
}
예제 #3
0
END_TEST


START_TEST (test_SBML_parseFormula_19)
{
  ASTNode_t *r = SBML_parseFormula("2.1e5-");

  fail_unless (r == NULL);


  //fail_unless( ASTNode_getType       (r) == AST_REAL_E, NULL );
  //fail_unless( ASTNode_getMantissa   (r) == 2.1, NULL );
  //fail_unless( ASTNode_getExponent   (r) ==   5, NULL );
  //fail_unless( ASTNode_getNumChildren(r) ==   0, NULL );

  //ASTNode_free(r);
}
END_TEST


START_TEST (test_Event_setTrigger2)
{
  ASTNode_t         *math1   = SBML_parseFormula("0");
  Trigger_t   *trigger 
    = Trigger_create(2, 4);
  Trigger_setMath(trigger, math1);
 
  int i = Event_setTrigger(E, trigger);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Event_getTrigger(E) != NULL );
  fail_unless( Event_isSetTrigger(E) );

}
예제 #5
0
END_TEST


//START_TEST (test_Constraint_createWithMath)
//{
//  ASTNode_t       *math = SBML_parseFormula("1 + 1");
//  Constraint_t *c   = Constraint_createWithMath(math);
//
//
//
//  fail_unless( SBase_getTypeCode  ((SBase_t *) c) == SBML_CONSTRAINT );
//  fail_unless( SBase_getMetaId    ((SBase_t *) c) == NULL );
//
//  fail_unless( Constraint_getMath(c) != math );
//  fail_unless( !Constraint_isSetMessage(c) );
//  fail_unless( Constraint_isSetMath    (c) );
//  Constraint_free(c);
//}
//END_TEST


START_TEST (test_Constraint_setMath)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");

  Constraint_setMath(C, math);

  fail_unless( Constraint_getMath(C) != math );
  fail_unless( Constraint_isSetMath(C) );

  /* Reflexive case (pathological) */
  Constraint_setMath(C, (ASTNode_t *) Constraint_getMath(C));

  fail_unless( Constraint_getMath(C) != math );

  Constraint_setMath(C, NULL);
  fail_unless( !Constraint_isSetMath(C) );

  if (Constraint_getMath(C) != NULL)
  {
    fail("Constraint_setMath(C, NULL) did not clear ASTNode.");
  }

  ASTNode_free(math);
}
END_TEST


START_TEST (test_SBML_parseFormula_16)
{
  ASTNode_t *r = SBML_parseFormula("foo(1, bar, 2^-3)");
  ASTNode_t *c;


  fail_unless( ASTNode_getType(r) == AST_FUNCTION , NULL );
  fail_unless( !strcmp(ASTNode_getName(r), "foo") , NULL );
  fail_unless( ASTNode_getNumChildren(r) == 3     , NULL );

  c = ASTNode_getChild(r, 0);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 1, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getChild(r, 1);

  fail_unless( ASTNode_getType(c) == AST_NAME     , NULL );
  fail_unless( !strcmp(ASTNode_getName(c), "bar") , NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0     , NULL );

  c = ASTNode_getChild(r, 2);

  fail_unless( ASTNode_getType       (c) == AST_POWER, NULL );
  fail_unless( ASTNode_getCharacter  (c) == '^', NULL );
  fail_unless( ASTNode_getNumChildren(c) == 2  , NULL );

  c = ASTNode_getLeftChild( ASTNode_getChild(r, 2) );

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 2, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getRightChild( ASTNode_getChild(r, 2) );

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == -3, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0 , NULL );

  ASTNode_free(r);
}
예제 #7
0
END_TEST


START_TEST (test_FunctionDefinition_setMath)
{
  ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)");

  const ASTNode_t * math1;
  char * formula;

  FunctionDefinition_setMath(FD, math);

  math1 = FunctionDefinition_getMath(FD);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  fail_unless( FunctionDefinition_getMath(FD) != math );
  fail_unless( FunctionDefinition_isSetMath(FD) );
  fail_unless( FunctionDefinition_isSetBody(FD) );

  /* Reflexive case (pathological) */
  FunctionDefinition_setMath(FD, (ASTNode_t *) FunctionDefinition_getMath(FD));
  math1 = FunctionDefinition_getMath(FD);
  fail_unless( math1 != NULL );

  safe_free(formula);
  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  fail_unless( FunctionDefinition_getMath(FD) != math );

  FunctionDefinition_setMath(FD, NULL);
  fail_unless( !FunctionDefinition_isSetMath(FD) );
  fail_unless( !FunctionDefinition_isSetBody(FD) );

  if (FunctionDefinition_getMath(FD) != NULL)
  {
    fail("FunctionDefinition_setMath(FD, NULL) did not clear ASTNode.");
  }

  ASTNode_free(math);
  safe_free(formula);
}
예제 #8
0
END_TEST


START_TEST (test_AlgebraicRule_createWithMath)
{
  ASTNode_t       *math = SBML_parseFormula("1 + 1");
  Rule_t *ar   = Rule_createAlgebraic(2, 4);
  Rule_setMath(ar, math);


  fail_unless( SBase_getTypeCode  ((SBase_t *) ar) == SBML_ALGEBRAIC_RULE );
  fail_unless( SBase_getMetaId    ((SBase_t *) ar) == NULL );

  fail_unless( !strcmp(Rule_getFormula((Rule_t *) ar), "1 + 1") );
  fail_unless( Rule_getMath((Rule_t *) ar) != math );

  Rule_free(ar);
}
END_TEST


START_TEST (test_EventAssignment_setMath)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");
  char *formula;
  const ASTNode_t *math1;

  EventAssignment_setMath(EA, math);

  math1 = EventAssignment_getMath(EA);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "2 * k") );
  safe_free(formula);

  fail_unless( EventAssignment_getMath(EA) != math);
  fail_unless( EventAssignment_isSetMath(EA) );

  /* Reflexive case (pathological) */
  EventAssignment_setMath(EA, (ASTNode_t *) EventAssignment_getMath(EA));

  math1 = EventAssignment_getMath(EA);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "2 * k") );
  fail_unless( EventAssignment_getMath(EA) != math );
  safe_free(formula);

  EventAssignment_setMath(EA, NULL);
  fail_unless( !EventAssignment_isSetMath(EA) );

  if (EventAssignment_getMath(EA) != NULL)
  {
    fail("EventAssignment_setMath(EA, NULL) did not clear ASTNode.");
  }

  ASTNode_free(math);
}
예제 #10
0
END_TEST


START_TEST (test_FunctionDefinition_getBody)
{
  const ASTNode_t *math;

  ASTNode_t * math1 = SBML_parseFormula("lambda(x, x)");

  FunctionDefinition_setMath(FD, math1 );
  math = FunctionDefinition_getBody(FD);

  fail_unless( math != NULL                        );
  fail_unless( ASTNode_isName(math)                );
  fail_unless( !strcmp(ASTNode_getName(math), "x") );
  fail_unless( ASTNode_getNumChildren(math) == 0   );

  ASTNode_free(math1);
}
END_TEST


START_TEST (test_Event_addEventAssignment2)
{
  Event_t *e = Event_create(2, 2);
  EventAssignment_t *ea 
    = EventAssignment_create(2, 3);
  EventAssignment_setVariable(ea, "f");
  EventAssignment_setMath(ea, SBML_parseFormula("a-n"));

  int i = Event_addEventAssignment(e, ea);

  fail_unless( i == LIBSBML_VERSION_MISMATCH);
  fail_unless( Event_getNumEventAssignments(e) == 0);

  EventAssignment_free(ea);
  Event_free(e);
}
예제 #12
0
END_TEST


START_TEST (test_KineticLaw_setMath)
{
  ASTNode_t *math = SBML_parseFormula("k3 / k2");
  char *formula;
  const ASTNode_t *math1;


  KineticLaw_setMath(kl, math);

  math1 = KineticLaw_getMath(kl);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "k3 / k2") );
  fail_unless( KineticLaw_getMath(kl) != math );
  fail_unless( KineticLaw_isSetMath(kl) );
  safe_free(formula);

  /* Reflexive case (pathological) */
  KineticLaw_setMath(kl, (ASTNode_t *) KineticLaw_getMath(kl));
  math1 = KineticLaw_getMath(kl);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "k3 / k2") );
  fail_unless( KineticLaw_getMath(kl) != math );
  safe_free(formula);

  KineticLaw_setMath(kl, NULL);
  fail_unless( !KineticLaw_isSetMath(kl) );

  if (KineticLaw_getMath(kl) != NULL)
  {
    fail( "KineticLaw_setMath(kl, NULL) did not clear ASTNode." );
  }

  ASTNode_free(math);
}
예제 #13
0
END_TEST


START_TEST (test_AssignmentRule_createWithMath)
{
  ASTNode_t       *math = SBML_parseFormula("1 + 1");

  Rule_t *ar = Rule_createAssignment(2, 4);
  Rule_setVariable(ar, "s");
  Rule_setMath(ar, math);


  fail_unless( SBase_getTypeCode  ((SBase_t *) ar) == SBML_ASSIGNMENT_RULE );
  fail_unless( SBase_getMetaId    ((SBase_t *) ar) == NULL );
  fail_unless( !strcmp(Rule_getVariable(ar), "s") );
  fail_unless( !strcmp(Rule_getFormula((Rule_t *) ar), "1 + 1") );
  fail_unless( Rule_getMath((Rule_t *) ar) != math );

  Rule_free(ar);
}
END_TEST


START_TEST (test_Event_setDelay2)
{
  ASTNode_t         *math1   = SBML_parseFormula("0");
  Delay_t   *Delay = 
    Delay_create(2, 1);
  Delay_setMath(Delay, math1);

  int i = Event_setDelay(E, Delay);

  fail_unless( i == LIBSBML_VERSION_MISMATCH );
  fail_unless( !Event_isSetDelay(E) );

  i = Event_unsetDelay(E);
  
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);

}
예제 #15
0
END_TEST


START_TEST (test_StoichiometryMath_setMath)
{
  ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)");

  const ASTNode_t * math1;
  char * formula;

  StoichiometryMath_setMath(D, math);

  math1 = StoichiometryMath_getMath(D);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  fail_unless( StoichiometryMath_getMath(D) != math );
  fail_unless( StoichiometryMath_isSetMath(D) );
  safe_free(formula);

  /* Reflexive case (pathological) */
  StoichiometryMath_setMath(D, (ASTNode_t *) StoichiometryMath_getMath(D));
  math1 = StoichiometryMath_getMath(D);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  safe_free(formula);

  StoichiometryMath_setMath(D, NULL);
  fail_unless( !StoichiometryMath_isSetMath(D) );

  if (StoichiometryMath_getMath(D) != NULL)
  {
    fail("StoichiometryMath_setMath(D, NULL) did not clear ASTNode.");
  }
  ASTNode_free(math);
}
예제 #16
0
END_TEST


START_TEST (test_Priority_setMath)
{
  ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)");

  const ASTNode_t * math1;
  char * formula;

  Priority_setMath(P, math);

  math1 = Priority_getMath(P);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  fail_unless( Priority_getMath(P) != math );
  fail_unless( Priority_isSetMath(P) );
  safe_free(formula);

  /* Reflexive case (pathological) */
  Priority_setMath(P, (ASTNode_t *) Priority_getMath(P));
  math1 = Priority_getMath(P);
  fail_unless( math1 != NULL );

  formula = SBML_formulaToString(math1);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "lambda(x, x^3)") );
  safe_free(formula);

  Priority_setMath(P, NULL);
  fail_unless( !Priority_isSetMath(P) );

  if (Priority_getMath(P) != NULL)
  {
    fail("Priority_setMath(P, NULL) did not clear ASTNode.");
  }
  ASTNode_free(math);
}
예제 #17
0
END_TEST


START_TEST (test_SBMLConvert_convertToL3_stoichiometryMath)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(2, 1);
  Model_t        *m = SBMLDocument_createModel(d);

  Compartment_t  *c = Model_createCompartment(m);
  Compartment_setId   ( c, "c" );

  Species_t *s = Model_createSpecies(m);
  Species_setId(s, "s");
  Species_setCompartment(s, "c");

  Reaction_t * r = Model_createReaction(m);
  SpeciesReference_t *sr = Reaction_createReactant(r);
  SpeciesReference_setSpecies(sr, "s");
  StoichiometryMath_t *sm = SpeciesReference_createStoichiometryMath(sr);

  ASTNode_t * ast = SBML_parseFormula("c*2");
  StoichiometryMath_setMath(sm, ast);

  fail_unless(Model_getNumRules(m) == 0);
  fail_unless(SpeciesReference_isSetId(sr) == 0);
  
  fail_unless( SBMLDocument_setLevelAndVersionNonStrict(d, 3, 1) == 1);

  m = SBMLDocument_getModel(d);
  r = Model_getReaction(m, 0);
  sr = Reaction_getReactant(r, 0);

  fail_unless(Model_getNumRules(m) == 1);
  fail_unless(SpeciesReference_isSetId(sr) == 1);
  
  Rule_t *rule = Model_getRule(m, 0);

  fail_unless( strcmp(SpeciesReference_getId(sr), Rule_getVariable(rule)) == 0 );

  SBMLDocument_free(d);
}
예제 #18
0
END_TEST


START_TEST (test_SBML_parseFormula_10)
{
  ASTNode_t *r = SBML_parseFormula("1 + -2e100 / 3");
  ASTNode_t *c;


  fail_unless( ASTNode_getType       (r) == AST_PLUS, NULL );
  fail_unless( ASTNode_getCharacter  (r) == '+', NULL );
  fail_unless( ASTNode_getNumChildren(r) == 2  , NULL );

  c = ASTNode_getLeftChild(r);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 1, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getRightChild(r);

  fail_unless( ASTNode_getType       (c) == AST_DIVIDE, NULL );
  fail_unless( ASTNode_getCharacter  (c) == '/', NULL );
  fail_unless( ASTNode_getNumChildren(c) == 2  , NULL );

  c = ASTNode_getLeftChild(c);

  fail_unless( ASTNode_getType       (c) == AST_REAL_E, NULL );
  fail_unless( ASTNode_getMantissa   (c) ==  -2, NULL );
  fail_unless( ASTNode_getExponent   (c) == 100, NULL );
  fail_unless( ASTNode_getReal       (c) == -2e+100, NULL );
  fail_unless( ASTNode_getNumChildren(c) ==   0, NULL );

  c = ASTNode_getRightChild( ASTNode_getRightChild(r) );

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 3, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  ASTNode_free(r);
}
END_TEST


START_TEST (test_FunctionDefinition_setMath1)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");

  int i = FunctionDefinition_setMath(E, math);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( FunctionDefinition_getMath(E) != math );
  fail_unless( FunctionDefinition_isSetMath(E) );

  i = FunctionDefinition_setMath(E, NULL);
  
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( FunctionDefinition_getMath(E) == NULL );
  fail_unless( !FunctionDefinition_isSetMath(E) );

  ASTNode_free(math);
}
예제 #20
0
END_TEST


START_TEST (test_StoichiometryMath_setMath1)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");

  int i = StoichiometryMath_setMath(D, math);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( StoichiometryMath_getMath(D) != math );
  fail_unless( StoichiometryMath_isSetMath(D) );

  i = StoichiometryMath_setMath(D, NULL);
  
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( StoichiometryMath_getMath(D) == NULL );
  fail_unless( !StoichiometryMath_isSetMath(D) );

  ASTNode_free(math);
}
예제 #21
0
END_TEST


START_TEST (test_Trigger_setMath1)
{
    ASTNode_t *math = SBML_parseFormula("2 * k");

    int i = Trigger_setMath(D, math);

    fail_unless( i == LIBSBML_OPERATION_SUCCESS);
    fail_unless( Trigger_getMath(D) != math );
    fail_unless( Trigger_isSetMath(D) );

    i = Trigger_setMath(D, NULL);

    fail_unless( i == LIBSBML_OPERATION_SUCCESS);
    fail_unless( Trigger_getMath(D) == NULL );
    fail_unless( !Trigger_isSetMath(D) );

    ASTNode_free(math);
}
예제 #22
0
END_TEST


START_TEST (test_Priority_setMath1)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");

  int i = Priority_setMath(P, math);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( Priority_getMath(P) != math );
  fail_unless( Priority_isSetMath(P) );

  i = Priority_setMath(P, NULL);
  
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( Priority_getMath(P) == NULL );
  fail_unless( !Priority_isSetMath(P) );

  ASTNode_free(math);
}
END_TEST


START_TEST (test_EventAssignment_setMath1)
{
  ASTNode_t *math = SBML_parseFormula("2 * k");

  int i = EventAssignment_setMath(E, math);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( EventAssignment_getMath(E) != math );
  fail_unless( EventAssignment_isSetMath(E) );

  i = EventAssignment_setMath(E, NULL);
  
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( EventAssignment_getMath(E) == NULL );
  fail_unless( !EventAssignment_isSetMath(E) );

  ASTNode_free(math);
}
END_TEST


START_TEST (test_SBML_parseFormula_14)
{
  ASTNode_t *r = SBML_parseFormula("foo(1)");
  ASTNode_t *c;


  fail_unless( ASTNode_getType(r) == AST_FUNCTION , NULL );
  fail_unless( !strcmp(ASTNode_getName(r), "foo") , NULL );
  fail_unless( ASTNode_getNumChildren(r) == 1     , NULL );

  c = ASTNode_getLeftChild(r);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 1, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  ASTNode_free(r);
}
예제 #25
0
SedDataGenerator * createDataGenerator(
  SedDocument* mpSEDMLDocument,
  const std::string &sbmlId,
  const std::string &targetXPathString,
  const std::string& taskId,
  size_t i,
  size_t j)
{
  SedDataGenerator *pPDGen = mpSEDMLDocument->createDataGenerator();
  std::ostringstream idStrStream;
  idStrStream << sbmlId;
  idStrStream << "_";
  idStrStream << j + 1;
  pPDGen->setId(idStrStream.str());

  pPDGen->setName(sbmlId);

  SedVariable * pPVar = pPDGen->createVariable();
  std::ostringstream idVarStrStream;
  idVarStrStream << "p";
  idVarStrStream << i + 1;
  idVarStrStream << "_";
  idVarStrStream << pPDGen->getName();
  pPVar->setId(idVarStrStream.str());
  pPVar->setTaskReference(taskId);
  pPVar->setName(pPDGen->getName());

  pPDGen->setMath(SBML_parseFormula(pPVar->getId().c_str()));

  if (targetXPathString == SEDML_TIME_URN)
    {
      pPVar->setSymbol(targetXPathString);
    }
  else
    {
      pPVar->setTarget(targetXPathString);
    }

  return pPDGen;
}
END_TEST


START_TEST (test_SBML_parseFormula_7)
{
  ASTNode_t *r = SBML_parseFormula("1 + 2 * 3");
  ASTNode_t *c;



  fail_unless( ASTNode_getType       (r) == AST_PLUS, NULL );
  fail_unless( ASTNode_getCharacter  (r) == '+', NULL );
  fail_unless( ASTNode_getNumChildren(r) == 2  , NULL );

  c = ASTNode_getLeftChild(r);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 1, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getRightChild(r);

  fail_unless( ASTNode_getType       (c) == AST_TIMES, NULL );
  fail_unless( ASTNode_getCharacter  (c) == '*', NULL );
  fail_unless( ASTNode_getNumChildren(c) == 2  , NULL );

  c = ASTNode_getLeftChild(c);

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 2, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  c = ASTNode_getRightChild( ASTNode_getRightChild(r) );

  fail_unless( ASTNode_getType       (c) == AST_INTEGER, NULL );
  fail_unless( ASTNode_getInteger    (c) == 3, NULL );
  fail_unless( ASTNode_getNumChildren(c) == 0, NULL );

  ASTNode_free(r);
}
예제 #27
0
END_TEST


START_TEST (test_L3_Event_hasRequiredElements )
{
  Event_t *e = Event_create (3, 1);

  fail_unless ( !Event_hasRequiredElements(e));

  Trigger_t *t = Trigger_create(3, 1);
  ASTNode_t* math = SBML_parseFormula("true");
  Trigger_setMath(t, math);
  ASTNode_free(math);
  Trigger_setInitialValue(t, 1);
  Trigger_setPersistent(t, 1);
  Event_setTrigger(e, t);

  fail_unless ( Event_hasRequiredElements(e));

  Event_free(e);
  Trigger_free(t);
}
예제 #28
0
END_TEST


START_TEST (test_Trigger_setMath)
{
    ASTNode_t *math = SBML_parseFormula("lambda(x, x^3)");

    const ASTNode_t * math1;
    char * formula;

    Trigger_setMath(D, math);

    math1 = Trigger_getMath(D);
    fail_unless( math1 != NULL );

    formula = SBML_formulaToString(math1);
    fail_unless( formula != NULL );
    fail_unless( !strcmp(formula, "lambda(x, x^3)") );
    fail_unless( Trigger_getMath(D) != math );
    fail_unless( Trigger_isSetMath(D) );

    /* Reflexive case (pathological) */
    Trigger_setMath(D, (ASTNode_t *) Trigger_getMath(D));
    math1 = Trigger_getMath(D);
    fail_unless( math1 != NULL );

    formula = SBML_formulaToString(math1);
    fail_unless( formula != NULL );
    fail_unless( !strcmp(formula, "lambda(x, x^3)") );

    Trigger_setMath(D, NULL);
    fail_unless( !Trigger_isSetMath(D) );

    if (Trigger_getMath(D) != NULL)
    {
        fail("Trigger_setMath(D, NULL) did not clear ASTNode.");
    }
}
예제 #29
0
void
createNoValueStoichMath(Model & m, SpeciesReference & sr, unsigned int idCount)
{
  char newid[15];
  std::string id;

  // no stoichiometry and no id to set the stoichiometry
  // replace with stoichiometryMath using a parameter with no value

  sprintf(newid, "parameterId_%u", idCount);
  id.assign(newid);

  Parameter *p = m.createParameter();
  p->setId(id);
  p->setConstant(false);

  StoichiometryMath *sm = sr.createStoichiometryMath();
  if (sm != NULL)
  {
    ASTNode *ast = SBML_parseFormula(id.c_str());
    sm->setMath(ast);
  }
}
예제 #30
0
/**
 * This program asks the user to enter an infix formula, translates it to
 * an Abstract Syntax tree using the function:
 *
 *   ASTNode_t *SBML_parseFormula(char *)
 *
 * evaluates the formula and returns the result.  See comments for
 * double evalAST(ASTNode_t *n) for further information.
 */
int
main()
{  
  char               *line;
  unsigned long long  start, stop;
     
  ASTNode_t *n;
  double result;    
    
  printf( "\n" );
  printf( "This program evaluates math formulas in infix notation.\n" );
  printf( "Typing 'enter' triggers evaluation.\n" );
  printf( "Typing 'enter' on an empty line stops the program.\n" );
  printf( "\n" );

  while (1)
  {
    printf( "Enter an infix formula (empty line to quit):\n\n" );
    printf( "> " );

    if ( strlen(line = trim_whitespace(get_line( stdin ))) == 0 ) break;

    n = SBML_parseFormula(line);
    
    start  = getCurrentMillis();   
    result = evalAST(n);
    stop   = getCurrentMillis();
    
    printf("\n%s\n= %.10g\n\n", SBML_formulaToString(n), result);
    printf("evaluation time: %llu ms\n\n", stop - start);
    
    free(line);
    ASTNode_free(n);  
  }
   
  return 0;
}