Пример #1
0
END_TEST


START_TEST (test_L3_Species_hasRequiredAttributes )
{
  Species_t *s = Species_create (3, 1);

  fail_unless ( !Species_hasRequiredAttributes(s));

  Species_setId(s, "id");

  fail_unless ( !Species_hasRequiredAttributes(s));

  Species_setCompartment(s, "cell");

  fail_unless ( !Species_hasRequiredAttributes(s));
  
  Species_setHasOnlySubstanceUnits(s, 0);

  fail_unless ( !Species_hasRequiredAttributes(s));

  Species_setBoundaryCondition(s, 0);

  fail_unless ( !Species_hasRequiredAttributes(s));

  Species_setConstant(s, 0);

  fail_unless ( Species_hasRequiredAttributes(s));

  Species_free(s);
}
END_TEST


/* since the setId function has been used as an
 * alias for setName we cant require it to only
 * be used on a L2 model
START_TEST (test_Species_setId1)
{
  int i = Species_setId(C, "cell");

  fail_unless( i == LIBSBML_UNEXPECTED_ATTRIBUTE );
  fail_unless( !Species_isSetId(C) );
}
END_TEST
*/

START_TEST (test_Species_setId2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setId(c, "1cell");

  fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE );
  fail_unless( !Species_isSetId(c) );

  Species_free(c);
}
Пример #3
0
END_TEST


START_TEST (test_Species_setSpatialSizeUnits)
{
  Species_t *s = 
    Species_create(2, 1);
  const char *units = "volume";


  Species_setSpatialSizeUnits(s, units);

  fail_unless( !strcmp(Species_getSpatialSizeUnits(s), units) );
  fail_unless( Species_isSetSpatialSizeUnits(s) );

  if (Species_getSpatialSizeUnits(s) == units)
  {
    fail("Species_setSpatialSizeUnits(...) did not make a copy of string.");
  }

  /* Reflexive case (pathological) */
  Species_setSpatialSizeUnits(s, Species_getSpatialSizeUnits(s));
  fail_unless( !strcmp(Species_getSpatialSizeUnits(s), units) );

  Species_setSpatialSizeUnits(s, NULL);
  fail_unless( !Species_isSetSpatialSizeUnits(s) );

  if (Species_getSpatialSizeUnits(s) != NULL)
  {
    fail("Species_setSpatialSizeUnits(S, NULL) did not clear string.");
  }

  Species_free(s);
}
Пример #4
0
END_TEST


START_TEST (test_Reaction_addProductBySpecies)
{
  Species_t *s = Species_create(2, 4);
  Species_setId(s, "s");
  Reaction_addProductBySpecies(R, s, 2.0, "sr", 0);

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 1 );
  fail_unless( Reaction_getNumModifiers(R) == 0 );

  SpeciesReference_t *sr = Reaction_getProduct(R, 0);

  fail_unless(!strcmp(SpeciesReference_getSpecies(sr), "s"));
  fail_unless(util_isEqual(SpeciesReference_getStoichiometry(sr), 2.0) == 1);
  fail_unless(!strcmp(SpeciesReference_getId(sr), "sr"));
  fail_unless(SpeciesReference_getConstant(sr) == 0);

  fail_unless(Reaction_addProductBySpecies(R, s, 1.0, "sr", 0) == LIBSBML_DUPLICATE_OBJECT_ID);
  fail_unless( Reaction_getNumProducts (R) == 1 );

  Species_free(s);
}
Пример #5
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);
}
END_TEST


START_TEST (test_SBMLConvert_convertToL1_Species_Amount)
{
  SBMLDocument_t *d   = SBMLDocument_createWithLevelAndVersion(2, 4);
  Model_t        *m   = SBMLDocument_createModel(d);
  const char     *sid = "C";
  Compartment_t  *c   = Compartment_create(2, 4);
  Species_t      *s   = Species_create(2, 4);


  Compartment_setId   ( c, sid );
  Model_addCompartment( m, c   );

  Species_setCompartment  ( s, sid  ); 
  Species_setInitialAmount( s, 2.34 );
  Model_addSpecies        ( m, s    );
  
  fail_unless( SBMLDocument_setLevelAndVersion(d, 1, 2) == 1, NULL );

  fail_unless( Species_getInitialAmount(s) == 2.34, NULL );

  SBMLDocument_free(d);
}
Пример #7
0
void
SpeciesTest_setup (void)
{
  S = Species_create(2, 4);

  if (S == NULL)
  {
    fail("Species_create() returned a NULL pointer.");
  }
}
void
SpeciesTest1_setup (void)
{
  C = Species_create(1, 2);

  if (C == NULL)
  {
    fail("Species_create() returned a NULL pointer.");
  }
}
Пример #9
0
END_TEST


START_TEST (test_L3_Species_initDefaults)
{
  Species_t *s = Species_create(3,1);

  fail_unless( Species_getId     (s) == NULL );
  fail_unless( Species_getName   (s) == NULL );
  fail_unless( Species_getCompartment  (s) == NULL );
  fail_unless( util_isNaN(Species_getInitialAmount (s)) );
  fail_unless( util_isNaN(Species_getInitialConcentration (s)) );
  fail_unless( Species_getSubstanceUnits  (s) == NULL );
  fail_unless( Species_getHasOnlySubstanceUnits(s) == 0   );
  fail_unless( Species_getBoundaryCondition(s) == 0   );
  fail_unless( Species_getConstant(s) == 0   );
  fail_unless( Species_getConversionFactor  (s) == NULL );

  fail_unless( !Species_isSetId     (s) );
  fail_unless( !Species_isSetName   (s) );
  fail_unless( !Species_isSetCompartment (s) );
  fail_unless( !Species_isSetInitialAmount (s) );
  fail_unless( !Species_isSetInitialConcentration (s) );
  fail_unless( !Species_isSetSubstanceUnits  (s) );
  fail_unless( !Species_isSetHasOnlySubstanceUnits(s)   );
  fail_unless( !Species_isSetBoundaryCondition(s)   );
  fail_unless( !Species_isSetConstant(s)   );
  fail_unless( !Species_isSetConversionFactor  (s) );

  Species_initDefaults(s);

  fail_unless( Species_getId     (s) == NULL );
  fail_unless( Species_getName   (s) == NULL );
  fail_unless( Species_getCompartment  (s) == NULL );
  fail_unless( util_isNaN(Species_getInitialAmount (s)) );
  fail_unless( util_isNaN(Species_getInitialConcentration (s)) );
  fail_unless( !strcmp(Species_getSubstanceUnits  (s),"mole" ));
  fail_unless( Species_getHasOnlySubstanceUnits(s) == 0   );
  fail_unless( Species_getBoundaryCondition(s) == 0   );
  fail_unless( Species_getConstant(s) == 0   );
  fail_unless( Species_getConversionFactor  (s) == NULL );

  fail_unless( !Species_isSetId     (s) );
  fail_unless( !Species_isSetName   (s) );
  fail_unless( !Species_isSetCompartment (s) );
  fail_unless( !Species_isSetInitialAmount (s) );
  fail_unless( !Species_isSetInitialConcentration (s) );
  fail_unless( Species_isSetSubstanceUnits  (s) );
  fail_unless( Species_isSetHasOnlySubstanceUnits(s)   );
  fail_unless( Species_isSetBoundaryCondition(s)   );
  fail_unless( Species_isSetConstant(s)   );
  fail_unless( !Species_isSetConversionFactor  (s) );

  Species_free(s);
}
Пример #10
0
END_TEST


START_TEST (test_ListOf_clear)
{
  ListOf_t *lo = (ListOf_t*) ListOf_create(2,4);

  SBase_t *sp = (SBase_t*)Species_create(2, 4); 

  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);

  fail_unless( ListOf_size(lo) == 5 );

  /* clear and delete */

  ListOf_clear(lo, 1);

  fail_unless( ListOf_size(lo) == 0 );

  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_appendAndOwn(lo, sp);

  fail_unless( ListOf_size(lo) == 5 );

  /* delete each item */

  SBase_t *elem;
  elem = ListOf_get(lo, 0);
  Species_free((Species_t*) elem);
  elem = ListOf_get(lo, 1);
  Species_free((Species_t*) elem);
  elem = ListOf_get(lo, 2);
  Species_free((Species_t*) elem);
  elem = ListOf_get(lo, 3);
  Species_free((Species_t*) elem);
  elem = ListOf_get(lo, 4);
  Species_free((Species_t*) elem);

  /* clear only */

  ListOf_clear(lo, 0);

  fail_unless( ListOf_size(lo) == 0 );

  ListOf_free(lo);
  
}
END_TEST


START_TEST (test_Species_setSpatialSizeUnits2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setSpatialSizeUnits(c, "1cell");

  fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE );
  fail_unless( !Species_isSetSpatialSizeUnits(c) );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setConstant2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setConstant(c, 1);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_getConstant(c) == 1 );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setSpatialSizeUnits4)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setSpatialSizeUnits(c, NULL);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !Species_isSetSpatialSizeUnits(c) );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setCharge2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setCharge(c, 4);

  fail_unless( i == LIBSBML_UNEXPECTED_ATTRIBUTE );
  fail_unless( !Species_isSetCharge(c));

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setCharge3)
{
  Species_t *c = 
    Species_create(2, 1);

  int i = Species_unsetCharge(c);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !Species_isSetCharge(c));

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setId3)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setId(c, "cell");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_isSetId(c) );
  fail_unless( !strcmp(Species_getId(c), "cell" ));

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setSpatialSizeUnits3)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setSpatialSizeUnits(c, "mole");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !strcmp(Species_getSpatialSizeUnits(c), "mole") );
  fail_unless( Species_isSetSpatialSizeUnits(c) );

  Species_free(c);
}
Пример #18
0
END_TEST


START_TEST (test_ListOf_remove)
{
  ListOf_t *lo = (ListOf_t*) ListOf_create(2,4);

  SBase_t *sp = (SBase_t*)Species_create(2, 4);

  fail_unless( ListOf_size(lo) == 0 );

  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);

  fail_unless( ListOf_size(lo) == 5 );

  SBase_t *elem;
  elem = ListOf_remove(lo, 0);
  Species_free((Species_t*) elem);
  elem = ListOf_remove(lo, 0);
  Species_free((Species_t*) elem);
  elem = ListOf_remove(lo, 0);
  Species_free((Species_t*) elem);
  elem = ListOf_remove(lo, 0);
  Species_free((Species_t*) elem);
  elem = ListOf_remove(lo, 0);
  Species_free((Species_t*) elem);

  fail_unless( ListOf_size(lo) == 0 );

  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_append(lo, sp);
  ListOf_appendAndOwn(lo, sp);

  fail_unless( ListOf_size(lo) == 5 );

  ListOf_free(lo);
}
Пример #19
0
END_TEST


START_TEST (test_SBMLConvert_convertToL1_Species_Concentration)
{
  SBMLDocument_t *d = SBMLDocument_createWithLevelAndVersion(2, 1);
  Model_t        *m = SBMLDocument_createModel(d);
  const char   *sid = "C";
  Compartment_t  *c = 
    Compartment_create(2, 1);
  Species_t      *s = 
    Species_create(2, 1);


  Compartment_setId   ( c, sid );
  Compartment_setSize ( c, 1.2 ); 
  Model_addCompartment( m, c   );

  Species_setId                  ( s, "s"  );
  Species_setCompartment         ( s, sid  ); 
  Species_setInitialConcentration( s, 2.34 );
  Model_addSpecies               ( m, s    );
  
  fail_unless( SBMLDocument_setLevelAndVersion(d, 1, 2) == 1, NULL);

  /**
   * These tests will fail under Cygwin because of a minimal
   * setlocale() implementation (see setlocale manpage).
   */
#ifndef CYGWIN
  fail_unless( Species_getInitialAmount(Model_getSpecies(m, 0)) == 2.808, NULL );
#endif

  Species_t * s1 = Model_getSpecies(m, 0);
  fail_unless (s1 != NULL);
  fail_unless (!strcmp(Species_getCompartment(s1), "C"));
  fail_unless(Compartment_getSize(Model_getCompartmentById(m, "C")) == 1.2);
  fail_unless(Species_getInitialConcentration(s1) == 2.34);
  fail_unless(Species_isSetInitialConcentration(s1) == 1);

  SBMLDocument_free(d);
}
END_TEST


START_TEST (test_Species_setName2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setName(c, "1cell");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_isSetName(c) );

  i = Species_unsetName(c);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !Species_isSetName(c) );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setSpeciesType2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setSpeciesType(c, "1cell");

  fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE );
  fail_unless( !Species_isSetSpeciesType(c) );

  i = Species_unsetSpeciesType(c);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !Species_isSetSpeciesType(c) );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setHasOnlySubstanceUnits2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setHasOnlySubstanceUnits(c, 0);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_getHasOnlySubstanceUnits(c) == 0 );

  i = Species_setHasOnlySubstanceUnits(c, 1);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_getHasOnlySubstanceUnits(c) == 1 );

  Species_free(c);
}
END_TEST


START_TEST (test_Species_setInitialAmount2)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setInitialAmount(c, 4);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_getInitialAmount(c) == 4.0 );
  fail_unless( Species_isSetInitialAmount(c));

  i = Species_unsetInitialAmount(c);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( !Species_isSetInitialAmount(c));

  Species_free(c);
}
Пример #24
0
END_TEST


START_TEST (test_Reaction_addModifierBySpecies)
{
  Species_t *s = Species_create(2, 4);
  Species_setId(s, "s");
  Reaction_addModifierBySpecies(R, s, "sr");

  fail_unless( Reaction_getNumReactants(R) == 0 );
  fail_unless( Reaction_getNumProducts (R) == 0 );
  fail_unless( Reaction_getNumModifiers(R) == 1 );

  SpeciesReference_t *sr = Reaction_getModifier(R, 0);

  fail_unless(!strcmp(SpeciesReference_getSpecies(sr), "s"));
  fail_unless(!strcmp(SpeciesReference_getId(sr), "sr"));

  fail_unless(Reaction_addModifierBySpecies(R, s, "sr") == LIBSBML_DUPLICATE_OBJECT_ID);
  fail_unless( Reaction_getNumModifiers (R) == 1 );

  Species_free(s);
}
Пример #25
0
Файл: doc.c Проект: cran/rsbml
static Species_t *
rsbml_build_doc_species(SEXP r_species)
{
  Species_t * species;
  
  species = Species_create();
  
  rsbml_build_doc_s_base((SBase_t *)species, r_species);
  
  SET_ATTR(Species, species, Id, id, STRING);
  SET_ATTR(Species, species, Name, name, STRING);
  SET_ATTR(Species, species, InitialConcentration, initialConcentration, REAL);
  SET_ATTR(Species, species, InitialAmount, initialAmount, REAL);
  SET_ATTR(Species, species, SubstanceUnits, substanceUnits, STRING);
  SET_ATTR(Species, species, SpatialSizeUnits, spatialSizeUnits, STRING);
  SET_ATTR(Species, species, Units, units, STRING);
  SET_ATTR(Species, species, HasOnlySubstanceUnits, hasOnlySubstanceUnits, LOGICAL);
  SET_ATTR(Species, species, BoundaryCondition, boundaryCondition, LOGICAL);
  SET_ATTR(Species, species, Charge, charge, INTEGER);
  SET_ATTR(Species, species, Constant, constant, LOGICAL);
  
  return species;
}