- Timestamp:
- 12/27/21 09:39:42 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
r18168 r18169 51 51 52 52 Assert.AreEqual("(3.1415 + 2)",formatter.Format(parser.Parse("3.1415+2.0"))); 53 Assert.AreEqual("(3.1415 * 1/2)",formatter.Format(parser.Parse("3.1415/2.0")));53 Assert.AreEqual("(3.1415 / 2)",formatter.Format(parser.Parse("3.1415/2.0"))); 54 54 Assert.AreEqual("(3.1415 * 2)",formatter.Format(parser.Parse("3.1415*2.0"))); 55 Assert.AreEqual("(3.1415 + (-(2)))", formatter.Format(parser.Parse("3.1415-2.0")));55 Assert.AreEqual("(3.1415 - 2)", formatter.Format(parser.Parse("3.1415-2.0"))); 56 56 // round-trip 57 Assert.AreEqual("(3.1415 + (-(2)))",formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0")))));57 Assert.AreEqual("(3.1415 - 2)",formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0"))))); 58 58 Assert.AreEqual("(3.1415 + 2)",formatter.Format(parser.Parse("3.1415+(2.0)"))); 59 59 Assert.AreEqual("(3.1415 + 2)", formatter.Format(parser.Parse("(3.1415+(2.0))"))); … … 61 61 62 62 Assert.AreEqual("LOG(3)",formatter.Format(parser.Parse("log(3)"))); 63 Assert.AreEqual("LOG( -3)",formatter.Format(parser.Parse("log(-3)")));63 Assert.AreEqual("LOG((-3))",formatter.Format(parser.Parse("log(-3)"))); 64 64 Assert.AreEqual("EXP(3)",formatter.Format(parser.Parse("exp(3)"))); 65 Assert.AreEqual("EXP( -3)",formatter.Format(parser.Parse("exp(-3)")));65 Assert.AreEqual("EXP((-3))",formatter.Format(parser.Parse("exp(-3)"))); 66 66 Assert.AreEqual("SQRT(3)", formatter.Format(parser.Parse("sqrt(3)"))); 67 67 68 Assert.AreEqual("SQR( -3)", formatter.Format(parser.Parse("sqr((-3))")));68 Assert.AreEqual("SQR((-3))", formatter.Format(parser.Parse("sqr((-3))"))); 69 69 70 Assert.AreEqual("((3/3) + (2/2) + (1/1))",formatter.Format(parser.Parse("3/3+2/2+1/1"))); 71 Assert.AreEqual("-3 + 30 - 2 + 20 - 1 + 10", formatter.Format(parser.Parse("-3+30-2+20-1+10"))); 70 Assert.AreEqual("((3 / 3) + (2 / 2) + (1 / 1))",formatter.Format(parser.Parse("3/3+2/2+1/1"))); 71 Assert.AreEqual("((((((-3) + 30) - 2) + 20) - 1) + 10)", formatter.Format(parser.Parse("-3+30-2+20-1+10"))); 72 73 // 'flattening' of nested addition, subtraction, multiplication, or division 74 Assert.AreEqual("(1 + 2 + 3 + 4)", formatter.Format(parser.Parse("1 + 2 + 3 + 4"))); 75 Assert.AreEqual("(1 - 2 - 3 - 4)", formatter.Format(parser.Parse("1 - 2 - 3 - 4"))); 76 Assert.AreEqual("(1 * 2 * 3 * 4)", formatter.Format(parser.Parse("1 * 2 * 3 * 4"))); 77 Assert.AreEqual("(1 / 2 / 3 / 4)", formatter.Format(parser.Parse("1 / 2 / 3 / 4"))); 78 79 // signed variables / constants 80 Assert.AreEqual("(-1*'x1')", formatter.Format(parser.Parse("-x1"))); 81 Assert.AreEqual("1", formatter.Format(parser.Parse("--1.0"))); 82 Assert.AreEqual("1", formatter.Format(parser.Parse("----1.0"))); 83 Assert.AreEqual("1", formatter.Format(parser.Parse("-+-1.0"))); 84 Assert.AreEqual("1", formatter.Format(parser.Parse("+-+-1.0"))); 85 Assert.AreEqual("((-3) + (-1))", formatter.Format(parser.Parse("-3 + -1.0"))); 86 72 87 73 88 Assert.AreEqual("'x1'",formatter.Format(parser.Parse("\"x1\""))); … … 89 104 Assert.AreEqual("(3.1 ^ 2.1)",formatter.Format(parser.Parse("POW(3.1 , 2.1)"))); 90 105 Assert.AreEqual("(3.1 ^ 2.1)",formatter.Format(parser.Parse("POW(3.1 ,2.1)"))); 91 Assert.AreEqual(" -3.1 ^ -2.1",formatter.Format(parser.Parse("POW(-3.1 , - 2.1)")));106 Assert.AreEqual("((-3.1) ^ (-2.1))",formatter.Format(parser.Parse("POW(-3.1 , - 2.1)"))); 92 107 Assert.AreEqual("ROOT(3, 2)",formatter.Format(parser.Parse("ROOT(3, 2)"))); 93 108 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1, 2.1)"))); 94 109 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 , 2.1)"))); 95 110 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 ,2.1)"))); 96 Assert.AreEqual("ROOT( -3.1, -2.1)", formatter.Format(parser.Parse("ROOT(-3.1 , -2.1)")));111 Assert.AreEqual("ROOT((-3.1), (-2.1))", formatter.Format(parser.Parse("ROOT(-3.1 , -2.1)"))); 97 112 98 113 Assert.AreEqual("IF(GT(0, 1), 1, 0)",formatter.Format(parser.Parse("IF(GT( 0, 1), 1, 0)"))); … … 117 132 Assert.AreEqual("'x' = 'val'",formatter.Format(parser.Parse("x = \"val\""))); 118 133 Assert.AreEqual("(1 * 'x' = 'val')",formatter.Format(parser.Parse("1.0 * x = val"))); 119 Assert.AreEqual("( -((1 * 'x' = 'val')))",formatter.Format(parser.Parse("-1.0 * x = val")));134 Assert.AreEqual("((-1) * 'x' = 'val')",formatter.Format(parser.Parse("-1.0 * x = val"))); 120 135 Assert.AreEqual("((1 * 'x' = 'val1') + 'y' = 'val2')", formatter.Format(parser.Parse("+1.0 * \"x\" = val1 + y = \"val2\""))); 136 137 // numeric parameters 138 Assert.AreEqual("0", formatter.Format(parser.Parse("<num>"))); // default initial value is zero 139 Assert.AreEqual("0", formatter.Format(parser.Parse("< num >"))); 140 Assert.AreEqual("1", formatter.Format(parser.Parse("< num=1.0>"))); 141 Assert.AreEqual("1", formatter.Format(parser.Parse("< num = 1.0>"))); 142 Assert.AreEqual("(-1)", formatter.Format(parser.Parse("< num =-1.0>"))); 143 Assert.AreEqual("(-1)", formatter.Format(parser.Parse("< num = - 1.0>"))); 144 145 // numeric parameter with sign 146 Assert.AreEqual("1", formatter.Format(parser.Parse("-<num=-1.0>"))); 121 147 } 122 148 }
Note: See TracChangeset
for help on using the changeset viewer.