/// /// @file TestWriteMathML.cs /// @brief Write MathML unit tests /// @author Frank Bergmann (Csharp conversion) /// @author Akiya Jouraku (Csharp conversion) /// @author Ben Bornstein /// /// $Id: TestWriteMathML.cs 8704 2009-01-04 02:26:05Z mhucka $ /// $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/trunk/libsbml/src/bindings/csharp/test/math/TestWriteMathML.cs $ /// /// This test file was converted from src/sbml/test/TestWriteMathML.cpp /// with the help of conversion sciprt (ctest_converter.pl). /// /// */ namespace LibSBMLCSTest { using libsbml; using System.IO; public class TestWriteMathML { public class AssertionError : System.Exception { public AssertionError() : base() { } } static void assertTrue(bool condition) { if (condition == true) { return; } throw new AssertionError(); } static void assertEquals(object a, object b) { if ( (a == null) && (b == null) ) { return; } else if (a.Equals(b)) { return; } throw new AssertionError(); } static void assertNotEquals(object a, object b) { if ( (a == null) && (b == null) ) { throw new AssertionError(); } else if (a.Equals(b)) { throw new AssertionError(); } } static void assertEquals(bool a, bool b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(bool a, bool b) { if ( a != b ) { return; } throw new AssertionError(); } static void assertEquals(int a, int b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(int a, int b) { if ( a != b ) { return; } throw new AssertionError(); } private string S; private ASTNode N; public string MATHML_FOOTER() { return ""; } public string MATHML_HEADER() { return "\n"; } public string XML_HEADER() { return "\n"; } public string wrapMathML(string s) { string r = XML_HEADER(); r += MATHML_HEADER(); r += s; r += MATHML_FOOTER(); return r; } public double util_NaN() { double z = 0.0; return 0.0/z; } public double util_PosInf() { double z = 0.0; return 1.0/z; } public double util_NegInf() { double z = 0.0; return -1.0/z; } public bool equals(string s1, string s2) { return (s1 ==s2); } public void setUp() { N = null; S = null; } public void tearDown() { S = null; } public void test_MathMLFormatter_ci() { string expected = wrapMathML(" foo \n"); N = libsbml.parseFormula("foo"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_1() { string expected = wrapMathML(" 0 3 \n" ); N = libsbml.parseFormula("0e3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_2() { string expected = wrapMathML(" 2 3 \n" ); N = libsbml.parseFormula("2e3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_3() { string expected = wrapMathML(" 1234567.8 3 \n" ); N = libsbml.parseFormula("1234567.8e3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_4() { string expected = wrapMathML(" 6.0221367 23 \n" ); N = libsbml.parseFormula("6.0221367e+23"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_5() { string expected = wrapMathML(" 4 -6 \n" ); N = libsbml.parseFormula(".000004"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_6() { string expected = wrapMathML(" 4 -12 \n" ); N = libsbml.parseFormula(".000004e-6"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_e_notation_7() { string expected = wrapMathML(" -1 -6 \n" ); N = libsbml.parseFormula("-1e-6"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_integer() { string expected = wrapMathML(" 5 \n"); N = libsbml.parseFormula("5"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_rational() { string expected = wrapMathML(" 1 3 \n" ); N = new ASTNode(); N.setValue(1,3); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_real_1() { string expected = wrapMathML(" 1.2 \n"); N = libsbml.parseFormula("1.2"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_real_2() { string expected = wrapMathML(" 1234567.8 \n"); N = libsbml.parseFormula("1234567.8"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_real_3() { string expected = wrapMathML(" -3.14 \n"); N = libsbml.parseFormula("-3.14"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_cn_real_locale() { string expected = wrapMathML(" 2.72 \n"); N = libsbml.parseFormula("2.72"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_exponentiale() { string expected = wrapMathML(" \n"); N = new ASTNode(libsbml.AST_CONSTANT_E); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_false() { string expected = wrapMathML(" \n"); N = new ASTNode(libsbml.AST_CONSTANT_FALSE); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_infinity() { string expected = wrapMathML(" \n"); N = new ASTNode(); N.setValue( util_PosInf() ); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_infinity_neg() { string expected = wrapMathML(" \n" ); N = new ASTNode(); N.setValue(- util_PosInf()); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_notanumber() { string expected = wrapMathML(" \n"); N = new ASTNode(libsbml.AST_REAL); N.setValue( util_NaN() ); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_constant_true() { string expected = wrapMathML(" \n"); N = new ASTNode(libsbml.AST_CONSTANT_TRUE); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_csymbol_delay() { string expected = wrapMathML(" \n" + " my_delay \n" + " x \n" + " 0.1 \n" + " \n"); N = libsbml.parseFormula("delay(x, 0.1)"); N.setName("my_delay"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_csymbol_time() { string expected = wrapMathML(" t \n"); N = new ASTNode(libsbml.AST_NAME_TIME); N.setName("t"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_function_1() { string expected = wrapMathML(" \n" + " foo \n" + " 1 \n" + " 2 \n" + " 3 \n" + " \n"); N = libsbml.parseFormula("foo(1, 2, 3)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_function_2() { string expected = wrapMathML(" \n" + " foo \n" + " 1 \n" + " 2 \n" + " \n" + " bar \n" + " z \n" + " \n" + " \n"); N = libsbml.parseFormula("foo(1, 2, bar(z))"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_lambda() { string expected = wrapMathML(" \n" + " \n" + " x \n" + " \n" + " \n" + " y \n" + " \n" + " \n" + " \n" + " \n" + " 2 \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " x \n" + " 2 \n" + " \n" + " \n" + " \n" + " y \n" + " 2 \n" + " \n" + " \n" + " \n" + " \n"); N = libsbml.parseFormula("lambda(x, y, root(2, x^2 + y^2))"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_lambda_no_bvars() { string expected = wrapMathML(" \n" + " \n" + " \n" + " 2 \n" + " 2 \n" + " \n" + " \n"); N = libsbml.parseFormula("lambda(2 + 2)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_log() { string expected = wrapMathML(" \n" + " \n" + " \n" + " 2 \n" + " \n" + " N \n" + " \n"); N = libsbml.parseFormula("log(2, N)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_minus() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " \n"); N = libsbml.parseFormula("1 - 2"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_minus_unary_1() { string expected = wrapMathML(" -2 \n" ); N = libsbml.parseFormula("-2"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_minus_unary_2() { string expected = wrapMathML(" \n" + " \n" + " a \n" + " \n"); N = libsbml.parseFormula("-a"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_piecewise() { string expected = wrapMathML(" \n" + " \n" + " \n" + " \n" + " x \n" + " \n" + " \n" + " \n" + " x \n" + " 0 \n" + " \n" + " \n" + " \n" + " 0 \n" + " \n" + " \n" + " x \n" + " 0 \n" + " \n" + " \n" + " \n" + " x \n" + " \n" + " \n" + " x \n" + " 0 \n" + " \n" + " \n" + " \n"); string f = "piecewise(-x, lt(x, 0), 0, eq(x, 0), x, gt(x, 0))";; N = libsbml.parseFormula(f); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_piecewise_otherwise() { string expected = wrapMathML(" \n" + " \n" + " 0 \n" + " \n" + " \n" + " x \n" + " 0 \n" + " \n" + " \n" + " \n" + " x \n" + " \n" + " \n"); N = libsbml.parseFormula("piecewise(0, lt(x, 0), x)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_plus_binary() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " \n"); N = libsbml.parseFormula("1 + 2"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_plus_nary_1() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " 3 \n" + " \n"); N = libsbml.parseFormula("1 + 2 + 3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_plus_nary_2() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " 3 \n" + " \n"); N = libsbml.parseFormula("(1 + 2) + 3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_plus_nary_3() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " 3 \n" + " \n"); N = libsbml.parseFormula("1 + (2 + 3)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_plus_nary_4() { string expected = wrapMathML(" \n" + " \n" + " 1 \n" + " 2 \n" + " \n" + " \n" + " x \n" + " y \n" + " z \n" + " \n" + " 3 \n" + " \n"); N = libsbml.parseFormula("1 + 2 + x * y * z + 3"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_root() { string expected = wrapMathML(" \n" + " \n" + " \n" + " 3 \n" + " \n" + " x \n" + " \n"); N = libsbml.parseFormula("root(3, x)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } public void test_MathMLFormatter_sin() { string expected = wrapMathML(" \n" + " \n" + " x \n" + " \n"); N = libsbml.parseFormula("sin(x)"); S = libsbml.writeMathMLToString(N); assertEquals( true, equals(expected,S) ); } } }