/* function used by the isTranslatedModulo function to compare 
 * children of the piecewise that can be used to construct
 * the modulo function
 */
int equals(const ASTNode_t* a, const ASTNode_t* b)
{
  char* ach = SBML_formulaToL3String(a);
  char* bch = SBML_formulaToL3String(b);
  int ret = !strcmp (ach, bch);
  free(ach);
  free(bch);
  return ret;
}
END_TEST


START_TEST (test_parse_brackets_2args)
{
  ASTNode_t *r = SBML_parseL3Formula("a[x, y]");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "a[x, y]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(a, x, y)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_matrix_emptyrows)
{
  ASTNode_t *r = SBML_parseL3Formula("matrix(matrixrow(), matrixrow())");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "matrix(matrixrow(), matrixrow())") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "matrix(matrixrow(), matrixrow())") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_vector_2args)
{
  ASTNode_t *r = SBML_parseL3Formula("vector(a+b, x^y)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{a + b, x^y}") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "vector(a + b, x^y)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_outer)
{
  ASTNode_t *r = SBML_parseL3Formula("outer(a, x)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "outerproduct(a, x)") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "outerproduct(a, x)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_selector_1args)
{
  ASTNode_t *r = SBML_parseL3Formula("selector(a)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "a[]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(a)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_trans)
{
  ASTNode_t *r = SBML_parseL3Formula("trans(a)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "transpose(a)") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "transpose(a)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_curlybraces_semicolons_short)
{
  ASTNode_t *r = SBML_parseL3Formula("{x; p}");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{x; p}") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "matrix(matrixrow(x), matrixrow(p))") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST

#if (0)
START_TEST (test_parse_curlybraces_semicolons)
{
  ASTNode_t *r = SBML_parseL3Formula("{x, y, z; p, d, q}");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{x, y, z; p, d, q}") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "matrix(matrixrow(x, y, z), matrixrow(p, d, q))") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_curlybraces_nested)
{
  ASTNode_t *r = SBML_parseL3Formula("{{x, y, z}, {p, d, q}}");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{{x, y, z}, {p, d, q}}") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "vector(vector(x, y, z), vector(p, d, q))") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_curlybraces_2args)
{
  ASTNode_t *r = SBML_parseL3Formula("{x, a^b}");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{x, a^b}") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "vector(x, a^b)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST

#if (0)
START_TEST (test_parse_function_selector_needNoParens3)
{
  ASTNode_t *r = SBML_parseL3Formula("selector({1, 2; 3, 4},x, y)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{1, 2; 3, 4}[x, y]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(matrix(matrixrow(1, 2), matrixrow(3, 4)), x, y)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_selector_needNoParens2)
{
  ASTNode_t *r = SBML_parseL3Formula("selector({1, 2, 3, 4},x)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "{1, 2, 3, 4}[x]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(vector(1, 2, 3, 4), x)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_selector_needNoParens1)
{
  ASTNode_t *r = SBML_parseL3Formula("selector(f(a),x,y)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "f(a)[x, y]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(f(a), x, y)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST


START_TEST (test_parse_function_selector_0args)
{
  ASTNode_t *r = new ASTNode(AST_LINEAR_ALGEBRA_SELECTOR);
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "selector()") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector()") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
END_TEST
#endif


START_TEST (test_parse_function_sum)
{
  ASTNode_t *r = SBML_parseL3Formula("sum(a, b, c)");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "sum(a, b, c)") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "sum(a, b, c)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
LIBSBML_CPP_NAMESPACE_USE
CK_CPPSTART
#endif


START_TEST (test_parse_brackets_0args)
{
  ASTNode_t *r = SBML_parseL3Formula("a[]");
  char* roundtrip = SBML_formulaToL3String(r);
  fail_unless( !strcmp(roundtrip, "a[]") );
  char* oldroundtrip = SBML_formulaToString(r);
  fail_unless( !strcmp(oldroundtrip, "selector(a)") );

  delete r;
  delete roundtrip;
  delete oldroundtrip;
}
Example #18
0
END_TEST

START_TEST (test_L3FormulaFormatter_accessWithNULL)
{

  // ensure we survive NULL arguments
  L3FormulaFormatter_format(NULL, NULL, NULL);
  L3FormulaFormatter_formatFunction(NULL, NULL, NULL);
  L3FormulaFormatter_formatOperator(NULL, NULL);
  L3FormulaFormatter_visit(NULL, NULL, NULL, NULL);
  L3FormulaFormatter_visitFunction(NULL, NULL, NULL, NULL);
  L3FormulaFormatter_visitLog10(NULL, NULL, NULL, NULL);
  L3FormulaFormatter_visitOther(NULL, NULL, NULL, NULL);
  L3FormulaFormatter_visitSqrt(NULL, NULL, NULL, NULL);
  L3FormulaFormatter_visitUMinus(NULL, NULL, NULL, NULL);

  fail_unless( L3FormulaFormatter_isFunction(NULL, NULL) == 0 );
  fail_unless( L3FormulaFormatter_isGrouped(NULL, NULL, NULL) == 0 );
  fail_unless( SBML_formulaToL3String(NULL) == NULL );
  
}
Example #19
0
END_TEST


START_TEST (test_SBML_formulaToL3String_L1toL3)
{
  ASTNode_t *n;
  char      *s;


  /** acos(x) -> acos(x) **/
  n = SBML_parseL3Formula("acos(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "acos(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** arcsin(x) -> asin(x) **/
  n = SBML_parseL3Formula("asin(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "asin(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** atan(x) -> atan(x) **/
  n = SBML_parseL3Formula("atan(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "atan(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** ceil(x) -> ceil(x) **/
  n = SBML_parseL3Formula("ceil(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "ceil(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** log(x) -> log10(x) **/
  n = SBML_parseL3Formula("log(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "log10(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);

  /** log(x) -> log10(x), if parsed with the old parser **/
  n = SBML_parseFormula("log(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "ln(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);

  /** log10( x) -> log10(x) **/
  n = SBML_parseL3Formula("log10(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "log10(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** pow(x, y) -> x^y **/
  n = SBML_parseL3Formula("pow(x, y)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "x^y"), NULL );

  safe_free(s);
  ASTNode_free(n);

  /** sqr(x) -> x^2 **/
  n = SBML_parseL3Formula("sqr(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "x^2"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** sqrt(x) -> sqrt(x) **/
  n = SBML_parseL3Formula("sqrt(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "sqrt(x)"), NULL );


  n = SBML_parseL3Formula("x + (y + z)");
  s = SBML_formulaToL3String(n);
  fail_unless( !strcmp(s, "x + (y + z)"), NULL );

  n = SBML_parseL3Formula("(x + y) + z");
  s = SBML_formulaToL3String(n);
  fail_unless( !strcmp(s, "x + y + z"), NULL );

  safe_free(s);
  ASTNode_free(n);
}
Example #20
0
END_TEST


START_TEST (test_SBML_formulaToL3String_L2toL3)
{
  ASTNode_t *n;
  char      *s;


  /** arccos(x) -> acos(x) **/
  n = SBML_parseL3Formula("arccos(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "acos(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** arcsin(x) -> asin(x) **/
  n = SBML_parseL3Formula("arcsin(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "asin(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** arctan(x) -> atan(x) **/
  n = SBML_parseL3Formula("arctan(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "atan(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** ceiling(x) -> ceil(x) **/
  n = SBML_parseL3Formula("ceiling(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "ceil(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** ln(x) -> log(x) **/
  n = SBML_parseL3Formula("ln(x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "ln(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);

  /** log(10, x) -> log10(x) **/
  n = SBML_parseL3Formula("log(10, x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "log10(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** power(x, y) -> pow(x, y) **/
  n = SBML_parseL3Formula("power(x, y)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "x^y"), NULL );

  safe_free(s);
  ASTNode_free(n);

  /** power(x, 2) -> pow(x, 2) **/
  n = SBML_parseL3Formula("power(x, 2)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "x^2"), NULL );

  safe_free(s);
  ASTNode_free(n);


  /** root(2, x) -> sqrt(x) **/
  n = SBML_parseL3Formula("root(2, x)");
  s = SBML_formulaToL3String(n);

  fail_unless( !strcmp(s, "sqrt(x)"), NULL );

  safe_free(s);
  ASTNode_free(n);
}
Example #21
0
END_TEST


START_TEST (test_SBML_formulaToL3String)
{
  const char *formulae[] =
  {
    "1",
    "2.1",
#if defined(WIN32) && !defined(CYGWIN)
    "2.100000e-010",
#else
    "2.100000e-10",
#endif
    "foo",
    "1 + foo",
    "1 + 2",
    "1 + 2 * 3",
    "(1 - 2) * 3",
    "1 + -2 / 3",
    "1 + -2.000000e-100 / 3",
    "1 - -foo / 3",
    "2 * foo^bar + 3.1",
    "foo()",
    "foo(1)",
    "foo(1, bar)",
    "foo(1, bar, 2^-3)",
    "a / b * c",
    "a / (b * c)",
    "1 + 2 + 3",
    "x % y",
    "(1 + x) % (3 / y)",
    "x^2 % -y",
    "x && y == z",
    "(x && y) == z",
    "a && b || c",
    "a && (b || c)",
    "-x^y",
    "(-x)^y",
    "x^-y",
    "!x^2",
    "(!x)^2",
    "x^!2",
    "x == y == z",
    "x >= y <= z",
    "x > y == z",
    "1 ml",
    "(3/4) uM",
    "INF",
    "NaN",
    "avogadro",
    "time",
    "pi",
    "true",
    "false",
    "(x > y) + (p == q)",
    "gt(x, y, z) + eq(p, d, q)",
    "gt(x) + eq(p)",
    "gt() + eq()",
    "(x || y) > (p && q)",
    "or(x) > and(p)",
    "or() > and()",
    "(x * y)^2",
    "(x * y * z)^2",
    "times(x)^2",
    "times()^2",
    ""
  };

  ASTNode_t *n;
  char      *s;
  int        i;


  for (i = 0; i < *formulae[i]; i++)
  {
    n = SBML_parseL3Formula( formulae[i] );
    s = SBML_formulaToL3String(n);

    fail_unless( !strcmp(s, formulae[i]), NULL );

    ASTNode_free(n);
    safe_free(s);
  }
}