[14024] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | using System;
|
---|
| 24 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 25 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Tests {
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | [TestClass]
|
---|
| 29 | public class InfixExpressionParserTest {
|
---|
| 30 | [TestMethod]
|
---|
| 31 | [TestCategory("Problems.DataAnalysis.Symbolic")]
|
---|
| 32 | [TestProperty("Time", "short")]
|
---|
[14109] | 33 | public void InfixExpressionParserTestFormatting() {
|
---|
[14024] | 34 | var formatter = new InfixExpressionFormatter();
|
---|
| 35 | var parser = new InfixExpressionParser();
|
---|
| 36 | Console.WriteLine(formatter.Format(parser.Parse("3")));
|
---|
| 37 | Console.WriteLine(formatter.Format(parser.Parse("3*3")));
|
---|
| 38 | Console.WriteLine(formatter.Format(parser.Parse("3 * 4")));
|
---|
[14826] | 39 | Console.WriteLine(formatter.Format(parser.Parse("123E-03")));
|
---|
[14024] | 40 | Console.WriteLine(formatter.Format(parser.Parse("123e-03")));
|
---|
| 41 | Console.WriteLine(formatter.Format(parser.Parse("123e+03")));
|
---|
| 42 | Console.WriteLine(formatter.Format(parser.Parse("123E+03")));
|
---|
| 43 | Console.WriteLine(formatter.Format(parser.Parse("123.0E-03")));
|
---|
| 44 | Console.WriteLine(formatter.Format(parser.Parse("123.0e-03")));
|
---|
| 45 | Console.WriteLine(formatter.Format(parser.Parse("123.0e+03")));
|
---|
| 46 | Console.WriteLine(formatter.Format(parser.Parse("123.0E+03")));
|
---|
| 47 | Console.WriteLine(formatter.Format(parser.Parse("123.0E-3")));
|
---|
| 48 | Console.WriteLine(formatter.Format(parser.Parse("123.0e-3")));
|
---|
| 49 | Console.WriteLine(formatter.Format(parser.Parse("123.0e+3")));
|
---|
| 50 | Console.WriteLine(formatter.Format(parser.Parse("123.0E+3")));
|
---|
| 51 |
|
---|
| 52 | Console.WriteLine(formatter.Format(parser.Parse("3.1415+2.0")));
|
---|
| 53 | Console.WriteLine(formatter.Format(parser.Parse("3.1415/2.0")));
|
---|
| 54 | Console.WriteLine(formatter.Format(parser.Parse("3.1415*2.0")));
|
---|
| 55 | Console.WriteLine(formatter.Format(parser.Parse("3.1415-2.0")));
|
---|
| 56 | // round-trip
|
---|
| 57 | Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0")))));
|
---|
| 58 | Console.WriteLine(formatter.Format(parser.Parse("3.1415+(2.0)")));
|
---|
| 59 | Console.WriteLine(formatter.Format(parser.Parse("(3.1415+(2.0))")));
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | Console.WriteLine(formatter.Format(parser.Parse("log(3)")));
|
---|
| 63 | Console.WriteLine(formatter.Format(parser.Parse("log(-3)")));
|
---|
| 64 | Console.WriteLine(formatter.Format(parser.Parse("exp(3)")));
|
---|
| 65 | Console.WriteLine(formatter.Format(parser.Parse("exp(-3)")));
|
---|
| 66 | Console.WriteLine(formatter.Format(parser.Parse("sqrt(3)")));
|
---|
| 67 |
|
---|
| 68 | Console.WriteLine(formatter.Format(parser.Parse("sqr((-3))")));
|
---|
| 69 |
|
---|
| 70 | Console.WriteLine(formatter.Format(parser.Parse("3/3+2/2+1/1")));
|
---|
| 71 | Console.WriteLine(formatter.Format(parser.Parse("-3+30-2+20-1+10")));
|
---|
| 72 | // round trip
|
---|
| 73 | Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("-3+30-2+20-1+10")))));
|
---|
| 74 |
|
---|
| 75 | Console.WriteLine(formatter.Format(parser.Parse("\"x1\"")));
|
---|
| 76 | Console.WriteLine(formatter.Format(parser.Parse("\'var name\'")));
|
---|
| 77 | Console.WriteLine(formatter.Format(parser.Parse("\"var name\"")));
|
---|
| 78 | Console.WriteLine(formatter.Format(parser.Parse("\"1\"")));
|
---|
| 79 |
|
---|
| 80 | Console.WriteLine(formatter.Format(parser.Parse("'var \" name\'")));
|
---|
| 81 | Console.WriteLine(formatter.Format(parser.Parse("\"var \' name\"")));
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | Console.WriteLine(formatter.Format(parser.Parse("\"x1\"*\"x2\"")));
|
---|
| 85 | Console.WriteLine(formatter.Format(parser.Parse("\"x1\"*\"x2\"+\"x3\"*\"x4\"")));
|
---|
| 86 | Console.WriteLine(formatter.Format(parser.Parse("x1*x2+x3*x4")));
|
---|
| 87 |
|
---|
[14347] | 88 |
|
---|
| 89 | Console.WriteLine(formatter.Format(parser.Parse("POW(3, 2)")));
|
---|
| 90 | Console.WriteLine(formatter.Format(parser.Parse("POW(3.1, 2.1)")));
|
---|
| 91 | Console.WriteLine(formatter.Format(parser.Parse("POW(3.1 , 2.1)")));
|
---|
| 92 | Console.WriteLine(formatter.Format(parser.Parse("POW(3.1 ,2.1)")));
|
---|
| 93 | Console.WriteLine(formatter.Format(parser.Parse("POW(-3.1 , - 2.1)")));
|
---|
| 94 | Console.WriteLine(formatter.Format(parser.Parse("ROOT(3, 2)")));
|
---|
| 95 | Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1, 2.1)")));
|
---|
| 96 | Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1 , 2.1)")));
|
---|
| 97 | Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1 ,2.1)")));
|
---|
| 98 | Console.WriteLine(formatter.Format(parser.Parse("ROOT(-3.1 , - 2.1)")));
|
---|
| 99 |
|
---|
| 100 | Console.WriteLine(formatter.Format(parser.Parse("IF(GT( 0, 1), 1, 0)")));
|
---|
| 101 | Console.WriteLine(formatter.Format(parser.Parse("IF(LT(0,1), 1 , 0)")));
|
---|
| 102 |
|
---|
[14350] | 103 | Console.WriteLine(formatter.Format(parser.Parse("LAG(x, 1)")));
|
---|
| 104 | Console.WriteLine(formatter.Format(parser.Parse("LAG(x, -1)")));
|
---|
| 105 | Console.WriteLine(formatter.Format(parser.Parse("LAG(x, +1)")));
|
---|
| 106 | Console.WriteLine(formatter.Format(parser.Parse("x * LAG('x', +1)")));
|
---|
| 107 |
|
---|
[14826] | 108 | Console.WriteLine(formatter.Format(parser.Parse("x [1.0] * y")));
|
---|
| 109 | Console.WriteLine(formatter.Format(parser.Parse("x [1.0, 2.0] * y [1.0, 2.0]")));
|
---|
| 110 | Console.WriteLine(formatter.Format(parser.Parse("x[1] * y")));
|
---|
| 111 | Console.WriteLine(formatter.Format(parser.Parse("x[1, 2] * y [1, 2]")));
|
---|
| 112 |
|
---|
| 113 | Console.WriteLine(formatter.Format(parser.Parse("x [+1.0] * y")));
|
---|
| 114 | Console.WriteLine(formatter.Format(parser.Parse("x [-1.0] * y")));
|
---|
| 115 | Console.WriteLine(formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]")));
|
---|
| 116 |
|
---|
| 117 | Console.WriteLine(formatter.Format(parser.Parse("x='bla' * y")));
|
---|
| 118 | Console.WriteLine(formatter.Format(parser.Parse("x = 'bla'")));
|
---|
| 119 | Console.WriteLine(formatter.Format(parser.Parse("x = \"bla\"")));
|
---|
| 120 | Console.WriteLine(formatter.Format(parser.Parse("1.0 * x = bla")));
|
---|
| 121 | Console.WriteLine(formatter.Format(parser.Parse("-1.0 * x = bla")));
|
---|
| 122 | Console.WriteLine(formatter.Format(parser.Parse("+1.0 * \"x\" = bla + y = \"bla2\"")));
|
---|
[14024] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|