END_TEST


START_TEST (test_Event_addEventAssignment4)
{
  Event_t *e = Event_create(2, 2);
  EventAssignment_t *ea 
    = EventAssignment_create(2, 2);
  EventAssignment_setVariable(ea, "c");
  EventAssignment_setMath(ea, SBML_parseFormula("a-n"));
  EventAssignment_t *ea1 
    = EventAssignment_create(2, 2);
  EventAssignment_setVariable(ea1, "c");
  EventAssignment_setMath(ea1, SBML_parseFormula("a-n"));

  int i = Event_addEventAssignment(e, ea);

  fail_unless( i == LIBSBML_OPERATION_SUCCESS);
  fail_unless( Event_getNumEventAssignments(e) == 1);

  i = Event_addEventAssignment(e, ea1);

  fail_unless( i == LIBSBML_DUPLICATE_OBJECT_ID);
  fail_unless( Event_getNumEventAssignments(e) == 1);  
  
  EventAssignment_free(ea);
  EventAssignment_free(ea1);
  Event_free(e);
}
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);
}
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_EventAssignment_setMath2)
{
  ASTNode_t *math = ASTNode_createWithType(AST_DIVIDE);

  int i = EventAssignment_setMath(E, math);

  fail_unless( i == LIBSBML_INVALID_OBJECT);
  fail_unless( !EventAssignment_isSetMath(E) );

  ASTNode_free(math);
}
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);
}