예제 #1
0
END_TEST


START_TEST (test_SBMLDocument_setModel)
{
  SBMLDocument_t *d  = SBMLDocument_createWithLevelAndVersion(2, 4);
  Model_t        *m1 = Model_create(2, 4);
  Model_t        *m2 = Model_create(2, 4);
  Model_t        *mout;

  fail_unless(SBMLDocument_getModel(d) == NULL);

  int i = SBMLDocument_setModel(d, m1);
  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  mout = SBMLDocument_getModel(d);
  fail_unless(mout != NULL);
  fail_unless(mout != m1);

  /* Reflexive case (pathological) */
  i = SBMLDocument_setModel(d, SBMLDocument_getModel(d));
  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  mout = SBMLDocument_getModel(d);
  fail_unless(mout != NULL);
  fail_unless(mout != m1);

  i = SBMLDocument_setModel(d, m2);
  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  mout = SBMLDocument_getModel(d);
  fail_unless(mout != NULL);
  fail_unless(mout != m2);

  SBMLDocument_free(d);
  /* m1 is freed by SBMLDocument_setModel(d, m2); */
}
예제 #2
0
END_TEST


START_TEST (test_SBMLDocument_setLevelAndVersion_Error)
{
  SBMLDocument_t *d  = SBMLDocument_create();
  SBMLDocument_setLevelAndVersion(d, 2, 1);
  
  Model_t        *m1 = Model_create(2, 1);

  /* add unitDefinition */
  Unit_t * u = Unit_create(2, 1);
  Unit_setKind(u, UnitKind_forName("mole"));
  Unit_setOffset(u, 3.2);

  UnitDefinition_t *ud = 
    UnitDefinition_create(2, 1);
  UnitDefinition_setId(ud, "ud");
  UnitDefinition_addUnit(ud, u);

  Model_addUnitDefinition(m1, ud);
  SBMLDocument_setModel(d, m1);

  fail_unless(SBMLDocument_setLevelAndVersionStrict(d,2,2) == 0);
  fail_unless(SBMLDocument_setLevelAndVersionStrict(d,2,3) == 0);
  fail_unless(SBMLDocument_setLevelAndVersionStrict(d,1,2) == 0);
  fail_unless(SBMLDocument_setLevelAndVersionStrict(d,1,1) == 0);

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


START_TEST (test_ListOf_append)
{
  Model_t *m = Model_create(2, 4);
  Model_createCompartment(m);

  ListOf_t *loc = Model_getListOfCompartments(m);

  fail_unless(ListOf_size(loc) == 1);

  SBase_t *c = (SBase_t*)Compartment_create(2, 4);
  int i = ListOf_append(loc, c);

  fail_unless(i == LIBSBML_OPERATION_SUCCESS);
  fail_unless(ListOf_size(loc) == 2);

  SBase_t *sp = (SBase_t*)Species_create(2, 4);
  i = ListOf_append(loc, sp);

  fail_unless(i == LIBSBML_INVALID_OBJECT);
  fail_unless(ListOf_size(loc) == 2);

  Model_free(m);
  Species_free((Species_t*)sp);
}
예제 #4
0
void
L3ModelTest_setup (void)
{
  M = Model_create(3, 1);

  if (M == NULL)
  {
    fail("Model_create(3, 1) returned a NULL pointer.");
  }
}
예제 #5
0
END_TEST


START_TEST (test_SBMLDocument_setModel3)
{
  SBMLDocument_t *d  = SBMLDocument_createWithLevelAndVersion(2, 2);
  
  Model_t        *m1 = Model_create(2, 2);

  int i = SBMLDocument_setModel(d, m1);

  fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless (SBMLDocument_getModel(d) != 0);

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


START_TEST (test_SBMLDocument_setModel2)
{
  SBMLDocument_t *d  = SBMLDocument_createWithLevelAndVersion(2, 2);
  
  Model_t        *m1 = Model_create(1, 2);

  int i = SBMLDocument_setModel(d, m1);

  fail_unless ( i == LIBSBML_LEVEL_MISMATCH);
  fail_unless (SBMLDocument_getModel(d) == 0);

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


START_TEST (test_SBMLDocument_setLevelAndVersion)
{
  SBMLDocument_t *d  = SBMLDocument_createWithLevelAndVersion(2, 2);
   
  Model_t        *m1 = Model_create(2, 2);

  SBMLDocument_setModel(d, m1);

  fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,2,3) == 1);
  fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,2,1) == 1);
  fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,1,2) == 1);
  fail_unless(SBMLDocument_setLevelAndVersionNonStrict(d,1,1) == 0);

  SBMLDocument_free(d);
}
예제 #8
0
파일: doc.c 프로젝트: cran/rsbml
static Model_t *
rsbml_build_doc_model(SEXP r_model)
{
  Model_t *model = Model_create();
  
  SET_ATTR(Model, model, Id, id, STRING);
  SET_ATTR(Model, model, Name, name, STRING);

  ADD_LIST(Model, model, Species, species, species);
  ADD_LIST(Model, model, FunctionDefinition, functionDefinitions, function_definition);
  ADD_LIST(Model, model, UnitDefinition, unitDefinitions, unit_definition);
  ADD_LIST(Model, model, Compartment, compartments, compartment);
  ADD_LIST(Model, model, Parameter, parameters, parameter);
  ADD_LIST(Model, model, Rule, rules, rule);
  ADD_LIST(Model, model, Reaction, reactions, reaction);
  ADD_LIST(Model, model, Event, events, event);
  #ifdef USE_LAYOUT
  ADD_LIST(Model, model, Layout, layouts, layout);
  #endif
  
  return model;
}
END_TEST


START_TEST (test_create_l1v1_units)
{
  Model_t            *m;
  Compartment_t      *c;
  KineticLaw_t       *kl;
  Parameter_t        *p;
  Reaction_t         *r;
  Species_t          *s;
  SpeciesReference_t *sr;
  Unit_t             *u;
  UnitDefinition_t   *ud;


  /**
   * <sbml level="1" version="1">
   */
  m = Model_create(2, 4);

  /**
   * <unitDefinition name="substance">
   *   <listOfUnits>
   *     <unit kind="mole" scale="-3"/>
   *   </listOfUnits>
   * </unitDefinition>
   */
  ud = Model_createUnitDefinition(m);
  UnitDefinition_setName(ud, "substance");

  u = Model_createUnit(m);
  Unit_setKind(u,UNIT_KIND_MOLE);
  Unit_setScale(u, -3);

  /**
   * <unitDefinition name="mls">
   *   <listOfUnits>
   *     <unit kind="mole"   scale="-3"/>
   *     <unit kind="liter"  exponent="-1"/>
   *     <unit kind="second" exponent="-1"/>
   *   </listOfUnits>
   * </unitDefinition>
   */
  ud = Model_createUnitDefinition(m);
  UnitDefinition_setName(ud, "mls");

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_MOLE);
  Unit_setScale(u, -3);

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_LITER);
  Unit_setExponent(u, -1);

  u = Model_createUnit(m);
  Unit_setKind(u, UNIT_KIND_SECOND);
  Unit_setExponent(u, -1);

  /**
   * <listOfCompartments>
   *   <compartment name="cell"/>
   * </listOfCompartments>
   */
  c = Model_createCompartment(m);
  Compartment_setName(c, "cell");

  /**
   * <listOfSpecies>
   *   <specie name="x0" compartment="cell" initialAmount="1"/>
   *   <specie name="x1" compartment="cell" initialAmount="1"/>
   *   <specie name="s1" compartment="cell" initialAmount="1"/>
   *   <specie name="s2" compartment="cell" initialAmount="1"/>
   * </listOfSpecies>
   */
  s = Model_createSpecies(m);
  Species_setName(s, "x0");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "x1");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "s1");
  Species_setCompartment(s, "cell");
  Species_setInitialAmount(s, 1);

  s = Model_createSpecies(m);
  Species_setName(s, "s2");
  Species_setCompartment(s, "cell"); 
  Species_setInitialAmount(s, 1);

  /**
   * <listOfParameters>
   *   <parameter name="vm" value="2" units="mls"/>
   *   <parameter name="km" value="2"/>
   * </listOfParameters>
   */
  p = Model_createParameter(m);
  Parameter_setName (p, "vm");
  Parameter_setUnits(p, "mls");
  Parameter_setValue(p, 2);

  p = Model_createParameter(m);
  Parameter_setName (p, "km");
  Parameter_setValue(p, 2);

  /**
   * <reaction name="v1">
   *   <listOfReactants>
   *     <specieReference specie="x0"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="s1"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s1)/(km + s1)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v1");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "x0");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "s1");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s1)/(km + s1)");

  /**
   * <reaction name="v2">
   *   <listOfReactants>
   *     <specieReference specie="s1"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="s2"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s2)/(km + s2)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v2");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "s1");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "s2");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s2)/(km + s2)");

  /**
   * <reaction name="v3">
   *   <listOfReactants>
   *     <specieReference specie="s2"/>
   *   </listOfReactants>
   *   <listOfProducts>
   *     <specieReference specie="x1"/>
   *   </listOfProducts>
   *   <kineticLaw formula="(vm * s1)/(km + s1)"/>
   * </reaction>
   */
  r = Model_createReaction(m);
  Reaction_setName(r, "v3");

  sr = Model_createReactant(m);
  SpeciesReference_setSpecies(sr, "s2");

  sr = Model_createProduct(m);
  SpeciesReference_setSpecies(sr, "x1");

  kl = Model_createKineticLaw(m);
  KineticLaw_setFormula(kl, "(vm * s1)/(km + s1)");

  Model_free(m);
}