END_TEST


START_TEST (test_L3_KineticLaw_addParameter1)
{
  KineticLaw_t *kl = KineticLaw_create(3, 1);
  Parameter_t *p 
    = Parameter_create(3, 1);

  int i = KineticLaw_addParameter(KL, p);

  fail_unless( i == LIBSBML_INVALID_OBJECT);
  
  Parameter_setId(p, "p");
  i = KineticLaw_addParameter(KL, p);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( KineticLaw_getNumParameters(KL) == 1);
  fail_unless( KineticLaw_getNumLocalParameters(KL) == 1);
  fail_unless( KineticLaw_getNumParameters(kl) == 0);
  fail_unless( KineticLaw_getNumLocalParameters(kl) == 0);

  i = KineticLaw_addParameter(kl, p);
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( KineticLaw_getNumParameters(KL) == 1);
  fail_unless( KineticLaw_getNumLocalParameters(KL) == 1);
  fail_unless( KineticLaw_getNumParameters(kl) == 1);
  fail_unless( KineticLaw_getNumLocalParameters(kl) == 1);


  Parameter_free(p);
  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_KineticLaw_createWithNS )
{
  XMLNamespaces_t *xmlns = XMLNamespaces_create();
  XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml");
  SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(2,1);
  SBMLNamespaces_addNamespaces(sbmlns,xmlns);

  KineticLaw_t *object = 
    KineticLaw_createWithNS (sbmlns);


  fail_unless( SBase_getTypeCode  ((SBase_t *) object) == SBML_KINETIC_LAW );
  fail_unless( SBase_getMetaId    ((SBase_t *) object) == NULL );
  fail_unless( SBase_getNotes     ((SBase_t *) object) == NULL );
  fail_unless( SBase_getAnnotation((SBase_t *) object) == NULL );

  fail_unless( SBase_getLevel       ((SBase_t *) object) == 2 );
  fail_unless( SBase_getVersion     ((SBase_t *) object) == 1 );

  fail_unless( KineticLaw_getNamespaces     (object) != NULL );
  fail_unless( XMLNamespaces_getLength(KineticLaw_getNamespaces(object)) == 2 );

  KineticLaw_free(object);
  XMLNamespaces_free(xmlns);
  SBMLNamespaces_free(sbmlns);
}
END_TEST


START_TEST (test_L3_KineticLaw_addParameter2)
{
  KineticLaw_t *kl = KineticLaw_create(3, 1);
  LocalParameter_t *lp 
    = LocalParameter_create(3, 1);
  LocalParameter_t *lp1 
    = LocalParameter_create(3, 1);

  int i = KineticLaw_addLocalParameter(kl, lp);

  fail_unless( i == LIBSBML_INVALID_OBJECT);
    
  LocalParameter_setId(lp, "p");
  LocalParameter_setId(lp1, "p1");
  i = KineticLaw_addLocalParameter(kl, lp);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( KineticLaw_getNumParameters(kl) == 1);
  fail_unless( KineticLaw_getNumLocalParameters(kl) == 1);

  i = KineticLaw_addParameter(kl, (Parameter_t *)lp1);
  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( KineticLaw_getNumParameters(kl) == 2);
  fail_unless( KineticLaw_getNumLocalParameters(kl) == 2);

  LocalParameter_free(lp);
  LocalParameter_free(lp1);
  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_L3_KineticLaw_free_NULL)
{
  KineticLaw_free(NULL);
}
END_TEST


START_TEST (test_Reaction_setKineticLaw3)
{
  KineticLaw_t *kl = 
    KineticLaw_create(1, 2);

  int i = Reaction_setKineticLaw(R, kl);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Reaction_isSetKineticLaw(R) );

  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_KineticLaw_createParameter)
{
  KineticLaw_t *kl = KineticLaw_create(2, 2);
  
  Parameter_t *p = KineticLaw_createParameter(kl);

  fail_unless( KineticLaw_getNumParameters(kl) == 1);
  fail_unless( SBase_getLevel((SBase_t *) (p)) == 2 );
  fail_unless( SBase_getVersion((SBase_t *) (p)) == 2 );

  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_Reaction_setKineticLaw2)
{
  KineticLaw_t *kl = 
    KineticLaw_create(1, 1);

  int i = Reaction_setKineticLaw(R, kl);

  fail_unless( i == LIBSBML_VERSION_MISMATCH );
  fail_unless( !Reaction_isSetKineticLaw(R) );

  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_KineticLaw_addParameter4)
{
  KineticLaw_t *kl = KineticLaw_create(2, 2);
  Parameter_t *p = NULL;

  int i = KineticLaw_addParameter(kl, p);

  fail_unless( i == LIBSBML_OPERATION_FAILED);
  fail_unless( KineticLaw_getNumParameters(kl) == 0);

  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_KineticLaw_setSubstanceUnits4)
{
  KineticLaw_t *kl1 = 
    KineticLaw_create(1, 2);
  
  int i = KineticLaw_setSubstanceUnits(kl1, NULL);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( !KineticLaw_isSetSubstanceUnits(kl1)   );

  KineticLaw_free(kl1);
}
END_TEST


START_TEST (test_KineticLaw_addParameter3)
{
  KineticLaw_t *kl = KineticLaw_create(2, 2);
  Parameter_t *p 
    = Parameter_create(1, 2);
  Parameter_setId(p, "p");

  int i = KineticLaw_addParameter(kl, p);

  fail_unless( i == LIBSBML_LEVEL_MISMATCH);
  fail_unless( KineticLaw_getNumParameters(kl) == 0);

  Parameter_free(p);
  KineticLaw_free(kl);
}
END_TEST


START_TEST (test_KineticLaw_setSubstanceUnits3)
{
  KineticLaw_t *kl1 = 
    KineticLaw_create(1, 2);
  
  int i = KineticLaw_setSubstanceUnits(kl1, "1second");

  fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE);
  fail_unless( !KineticLaw_isSetSubstanceUnits(kl1)   );

  i = KineticLaw_unsetSubstanceUnits(kl1);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( !KineticLaw_isSetSubstanceUnits(kl1)   );

  KineticLaw_free(kl1);
}
END_TEST


START_TEST (test_KineticLaw_setTimeUnits2)
{
  KineticLaw_t *kl1 = 
    KineticLaw_create(1, 2);
  
  int i = KineticLaw_setTimeUnits(kl1, "second");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( KineticLaw_isSetTimeUnits(kl1)   );

  i = KineticLaw_unsetTimeUnits(kl1);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( !KineticLaw_isSetTimeUnits(kl1)   );

  KineticLaw_free(kl1);
}
END_TEST


//START_TEST (test_KineticLaw_createWith)
//{
//  const ASTNode_t *math;
//  char *formula;
//
//  KineticLaw_t *kl = KineticLaw_createWithFormula("k1 * X0");
//
//
//  fail_unless( SBase_getTypeCode  ((SBase_t *) kl) == SBML_KINETIC_LAW );
//  fail_unless( SBase_getMetaId    ((SBase_t *) kl) == NULL );
//  fail_unless( SBase_getNotes     ((SBase_t *) kl) == NULL );
//  fail_unless( SBase_getAnnotation((SBase_t *) kl) == NULL );
//
//  math = KineticLaw_getMath(kl);
//  fail_unless( math != NULL );
//
//  formula = SBML_formulaToString(math);
//  fail_unless( formula != NULL );
//  fail_unless( !strcmp(formula, "k1 * X0") );
//
//  fail_unless( !strcmp( KineticLaw_getFormula       (kl), formula  ) );
//
//  fail_unless( KineticLaw_isSetMath          (kl) );
//  fail_unless( KineticLaw_isSetFormula       (kl) );
//
//  fail_unless(KineticLaw_getNumParameters(kl) == 0);
//
//  KineticLaw_free(kl);
//  safe_free(formula);
//}
//END_TEST



//START_TEST (test_KineticLaw_createWithMath)
//{
//  ASTNode_t *math1 = SBML_parseFormula("k3 / k2");
//  const ASTNode_t *math;
//  char *formula;
//
//  KineticLaw_t *kl = KineticLaw_createWithMath(math1);
//
//
//  fail_unless( SBase_getTypeCode  ((SBase_t *) kl) == SBML_KINETIC_LAW );
//  fail_unless( SBase_getMetaId    ((SBase_t *) kl) == NULL );
//  fail_unless( SBase_getNotes     ((SBase_t *) kl) == NULL );
//  fail_unless( SBase_getAnnotation((SBase_t *) kl) == NULL );
//
//  math = KineticLaw_getMath(kl);
//  fail_unless( math != NULL );
//
//  formula = SBML_formulaToString(math);
//  fail_unless( formula != NULL );
//  fail_unless( !strcmp(formula, "k3 / k2") );
//
//  fail_unless( !strcmp( KineticLaw_getFormula       (kl), formula  ) );
//
//  fail_unless( KineticLaw_isSetMath          (kl) );
//  fail_unless( KineticLaw_isSetFormula       (kl) );
//  fail_unless( !KineticLaw_isSetTimeUnits     (kl) );
//  fail_unless( !KineticLaw_isSetSubstanceUnits(kl) );
//
//  fail_unless(KineticLaw_getNumParameters(kl) == 0);
//
//  KineticLaw_free(kl);
//  safe_free(formula);
//}
//END_TEST



START_TEST (test_KineticLaw_free_NULL)
{
  KineticLaw_free(NULL);
}
void
KineticLawTest_teardown (void)
{
  KineticLaw_free(kl);
}
void
L3KineticLawTest_teardown (void)
{
  KineticLaw_free(KL);
}