END_TEST


START_TEST (test_AssignmentRule_setVariable)
{
  const char *variable = "x";


  Rule_setVariable(AR, variable);

  fail_unless( !strcmp(Rule_getVariable(AR), variable) );
  fail_unless( Rule_isSetVariable(AR) );

  if (Rule_getVariable(AR) == variable)
  {
    fail("Rule_setVariable(...) did not make a copy of string.");
  }

  /* Reflexive case (pathological) */
  Rule_setVariable(AR, Rule_getVariable(AR));
  fail_unless( !strcmp(Rule_getVariable(AR), variable) );

  Rule_setVariable(AR, NULL);
  fail_unless( !Rule_isSetVariable(AR) );

  if (Rule_getVariable(AR) != NULL)
  {
    fail("Rule_setVariable(AR, NULL) did not clear string.");
  }
}
Beispiel #2
0
END_TEST


START_TEST (test_ParameterRule_setName)
{
  const char *name = "cell";
  const char *c;


  Rule_setVariable(PR, name);

  fail_unless( !strcmp(Rule_getVariable(PR), name));
  fail_unless( Rule_isSetVariable(PR) );

  if (Rule_getVariable(PR) == name)
  {
    fail( "ParameterRule_setName(...) did not make a copy of string." );
          
  }

  /* Reflexive case (pathological) */
  c = Rule_getVariable(PR);
  Rule_setVariable(PR, c);
  fail_unless( !strcmp(Rule_getVariable(PR), name),
               NULL );

  Rule_setVariable(PR, NULL);
  fail_unless( !Rule_isSetVariable(PR) );

  if (Rule_getVariable(PR) != NULL)
  {
    fail( "Rule_setVariable(PR, NULL)"
          " did not clear string." );
  }
}
END_TEST


START_TEST (test_AssignmentRule_createWithFormula)
{
  const ASTNode_t *math;
  char *formula;

  Rule_t *ar = Rule_createAssignment(2, 4);
  Rule_setVariable(ar, "s");
  Rule_setFormula(ar, "1 + 1");


  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") );

  math = Rule_getMath((Rule_t *) ar);
  fail_unless(math != NULL);

  formula = SBML_formulaToString(math);
  fail_unless( formula != NULL );
  fail_unless( !strcmp(formula, "1 + 1") );

  fail_unless( !strcmp(Rule_getFormula((Rule_t *) ar), formula) );

  Rule_free(ar);
  safe_free(formula);
}
END_TEST


START_TEST (test_SpeciesConcentrationRule_setSpecies)
{
  const char       *species = "s2";
  const char *s;


  Rule_setVariable(SCR, species);

  fail_unless( !strcmp(Rule_getVariable(SCR), species),
               NULL );
  fail_unless( Rule_isSetVariable(SCR) );

  if (Rule_getVariable(SCR) == species)
  {
    fail( "SpeciesConcentrationRule_setSpecies(...)"
          " did not make a copy of string." );
  }

  /* Reflexive case (pathological) */
  s = Rule_getVariable(SCR);
  Rule_setVariable(SCR, s);
  fail_unless( !strcmp(Rule_getVariable(SCR), species),
               NULL );

  Rule_setVariable(SCR, NULL);
  fail_unless( !Rule_isSetVariable(SCR) );

  if (Rule_getVariable(SCR) != NULL)
  {
    fail( "SpeciesConcentrationRule_setSpecies(SCR, NULL)"
          " did not clear string." );
  }
}
END_TEST


START_TEST (test_CompartmentVolumeRule_setCompartment)
{
  const char *c;
  const char *compartment = "cell";


  Rule_setVariable(CVR, compartment);

  fail_unless( !strcmp(Rule_getVariable(CVR), compartment),
               NULL );
  fail_unless( Rule_isSetVariable(CVR) );

  if (Rule_getVariable(CVR) == compartment)
  {
    fail( "Rule_setVariable(...)"
          " did not make a copy of string." );
  }

  /* Reflexive case (pathological) */
  c = Rule_getVariable(CVR);
  Rule_setVariable(CVR, c);
  fail_unless( !strcmp(Rule_getVariable(CVR), compartment),
               NULL );

  Rule_setVariable(CVR, NULL);
  fail_unless( !Rule_isSetVariable(CVR) );

  if (Rule_getVariable(CVR) != NULL)
  {
    fail( "Rule_setVariable(CVR, NULL)"
          " did not clear string." );
  }
}
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_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);
}
Beispiel #8
0
void myRule_initTarget(
    myRule *rule,
    mySpecies **species, unsigned int num_of_species,
    myParameter **parameters, unsigned int num_of_parameters,
    myCompartment **compartments, unsigned int num_of_compartments,
    myReaction **reactions, unsigned int num_of_reactions) {
  unsigned int i, j;
  Rule_t *origin;
  const char *origin_var;
  mySpecies *sp;
  myParameter *param;
  myCompartment *comp;
  myReaction *re;
  mySpeciesReference *product, *reactant;

  origin = myRule_getOrigin(rule);
  origin_var = Rule_getVariable(origin);

  for (i = 0; i < num_of_species; i++) {
    sp = species[i];
    if (strcmp(origin_var, Species_getId(sp->origin)) == 0) {
      myRule_setTargetSpecies(rule, sp);
      mySpecies_setDependingRule(sp, rule);
      return;
    }
  }

  for (i = 0; i < num_of_parameters; i++) {
    param = parameters[i];
    if (strcmp(origin_var, Parameter_getId(param->origin)) == 0) {
      myRule_setTargetParameter(rule, param);
      myParameter_setDependingRule(param, rule);
      return;
    }
  }

  for (i = 0; i < num_of_compartments; i++) {
    comp = compartments[i];
    if (strcmp(origin_var, Compartment_getId(comp->origin)) == 0) {
      myRule_setTargetCompartment(rule, comp);
      myCompartment_setDependingRule(comp, rule);
      return;
    }
  }

  for (i=0; i < num_of_reactions; i++) {
    re = reactions[i];

    for (j = 0; j < re->num_of_products; j++) {
      product = re->products[j];
      if (SpeciesReference_isSetId(product->origin)
          && strcmp(origin_var, SpeciesReference_getId(product->origin)) == 0) {
        myRule_setTargetSpeciesReference(rule, product);
        mySpeciesReference_setDependingRule(product, rule);
        return;
      }
    }

    for (j = 0; j < re->num_of_reactants; j++) {
      reactant = re->reactants[j];
      if (SpeciesReference_isSetId(reactant->origin)
          && strcmp(origin_var, SpeciesReference_getId(reactant->origin)) == 0) {
        myRule_setTargetSpeciesReference(rule, reactant);
        mySpeciesReference_setDependingRule(reactant, rule);
        return;
      }
    }
  }
}