[14906] | 1 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
[14727] | 2 | using System;
|
---|
| 3 |
|
---|
| 4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
| 5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
| 6 |
|
---|
| 7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 8 |
|
---|
| 9 | [TestClass]
|
---|
[14906] | 10 | public class FloatExpressionTests : CommonTests<double> {
|
---|
[14727] | 11 | private const double delta = 0.00001;
|
---|
| 12 |
|
---|
| 13 | protected override string TypeName
|
---|
| 14 | {
|
---|
| 15 | get
|
---|
| 16 | {
|
---|
| 17 | return "FLOAT";
|
---|
| 18 | }
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[14834] | 21 | protected override IPushStack<double> Stack
|
---|
[14727] | 22 | {
|
---|
| 23 | get
|
---|
| 24 | {
|
---|
[14908] | 25 | return interpreter.FloatStack;
|
---|
[14727] | 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | [TestMethod]
|
---|
| 30 | [TestProperty("Time", "Short")]
|
---|
| 31 | [TestCategory("ExpressionTest")]
|
---|
| 32 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 33 | public void TestAdd() {
|
---|
[14908] | 34 | interpreter.FloatStack.Push(5.3, 5.3);
|
---|
| 35 | interpreter.Run(new FloatAddExpression());
|
---|
[14727] | 36 |
|
---|
[14908] | 37 | Assert.AreEqual(10.6, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 38 |
|
---|
[14908] | 39 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 40 | }
|
---|
| 41 |
|
---|
| 42 | [TestMethod]
|
---|
| 43 | [TestProperty("Time", "Short")]
|
---|
| 44 | [TestCategory("ExpressionTest")]
|
---|
| 45 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 46 | public void TestAddWithInsufficientArguments() {
|
---|
[14908] | 47 | TestWithInsufficientArguments("+", 1);
|
---|
[14727] | 48 | }
|
---|
| 49 |
|
---|
| 50 | [TestMethod]
|
---|
| 51 | [TestProperty("Time", "Short")]
|
---|
| 52 | [TestCategory("ExpressionTest")]
|
---|
| 53 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 54 | public void TestSubtract() {
|
---|
[14908] | 55 | interpreter.FloatStack.Push(10.2, 5.3);
|
---|
| 56 | interpreter.Run(new FloatSubtractExpression());
|
---|
[14727] | 57 |
|
---|
[14908] | 58 | Assert.AreEqual(4.9, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 59 |
|
---|
[14908] | 60 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 61 | }
|
---|
| 62 |
|
---|
| 63 | [TestMethod]
|
---|
| 64 | [TestProperty("Time", "Short")]
|
---|
| 65 | [TestCategory("ExpressionTest")]
|
---|
| 66 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 67 | public void TestSubractWithInsufficientArguments() {
|
---|
[14908] | 68 | TestWithInsufficientArguments("-", 1);
|
---|
[14727] | 69 | }
|
---|
| 70 |
|
---|
| 71 | [TestMethod]
|
---|
| 72 | [TestProperty("Time", "Short")]
|
---|
| 73 | [TestCategory("ExpressionTest")]
|
---|
| 74 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 75 | public void TestMultiply() {
|
---|
[14908] | 76 | interpreter.FloatStack.Push(9.9, 3.3);
|
---|
| 77 | interpreter.Run(new FloatMultiplyExpression());
|
---|
[14727] | 78 |
|
---|
[14908] | 79 | Assert.AreEqual(32.67, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 80 |
|
---|
[14908] | 81 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 82 | }
|
---|
| 83 |
|
---|
| 84 | [TestMethod]
|
---|
| 85 | [TestProperty("Time", "Short")]
|
---|
| 86 | [TestCategory("ExpressionTest")]
|
---|
| 87 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 88 | public void TestMultiplyWithInsufficientArguments() {
|
---|
[14908] | 89 | TestWithInsufficientArguments("*", 1);
|
---|
[14727] | 90 | }
|
---|
| 91 |
|
---|
| 92 | [TestMethod]
|
---|
| 93 | [TestProperty("Time", "Short")]
|
---|
| 94 | [TestCategory("ExpressionTest")]
|
---|
| 95 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 96 | public void TestDivide() {
|
---|
[14908] | 97 | interpreter.FloatStack.Push(9.9, 3.3);
|
---|
| 98 | interpreter.Run(new FloatDivideExpression());
|
---|
[14727] | 99 |
|
---|
[14908] | 100 | Assert.AreEqual(3.0, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 101 |
|
---|
[14908] | 102 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 103 | }
|
---|
| 104 |
|
---|
| 105 | [TestMethod]
|
---|
| 106 | [TestProperty("Time", "Short")]
|
---|
| 107 | [TestCategory("ExpressionTest")]
|
---|
| 108 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 109 | public void TestDivideWithInsufficientArguments() {
|
---|
[14908] | 110 | TestWithInsufficientArguments("/", 1);
|
---|
[14727] | 111 | }
|
---|
| 112 |
|
---|
| 113 | [TestMethod]
|
---|
| 114 | [TestProperty("Time", "Short")]
|
---|
| 115 | [TestCategory("ExpressionTest")]
|
---|
| 116 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 117 | public void TestModulo() {
|
---|
[14908] | 118 | interpreter.FloatStack.Push(11.6, 5.3);
|
---|
| 119 | interpreter.Run(new FloatModuloExpression());
|
---|
[14727] | 120 |
|
---|
[14908] | 121 | Assert.AreEqual(1, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 122 |
|
---|
[14908] | 123 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 124 | }
|
---|
| 125 |
|
---|
| 126 | [TestMethod]
|
---|
| 127 | [TestProperty("Time", "Short")]
|
---|
| 128 | [TestCategory("ExpressionTest")]
|
---|
| 129 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 130 | public void TestModuloWithInsufficientArguments() {
|
---|
[14908] | 131 | TestWithInsufficientArguments("%", 1);
|
---|
[14727] | 132 | }
|
---|
| 133 |
|
---|
| 134 | [TestMethod]
|
---|
| 135 | [TestProperty("Time", "Short")]
|
---|
| 136 | [TestCategory("ExpressionTest")]
|
---|
| 137 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 138 | public void TestMin() {
|
---|
[14908] | 139 | interpreter.FloatStack.Push(10.2, 5.3);
|
---|
| 140 | interpreter.Run(new FloatMinExpression());
|
---|
[14727] | 141 |
|
---|
[14908] | 142 | Assert.AreEqual(5.3, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 143 |
|
---|
[14908] | 144 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 145 | }
|
---|
| 146 |
|
---|
| 147 | [TestMethod]
|
---|
| 148 | [TestProperty("Time", "Short")]
|
---|
| 149 | [TestCategory("ExpressionTest")]
|
---|
| 150 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 151 | public void TestMinWithInsufficientArguments() {
|
---|
[14908] | 152 | TestWithInsufficientArguments("MIN", 1);
|
---|
[14727] | 153 | }
|
---|
| 154 |
|
---|
| 155 | [TestMethod]
|
---|
| 156 | [TestProperty("Time", "Short")]
|
---|
| 157 | [TestCategory("ExpressionTest")]
|
---|
| 158 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 159 | public void TestMax() {
|
---|
[14908] | 160 | interpreter.FloatStack.Push(10.3, 5.3);
|
---|
| 161 | interpreter.Run(new FloatMaxExpression());
|
---|
[14727] | 162 |
|
---|
[14908] | 163 | Assert.AreEqual(10.3, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 164 |
|
---|
[14908] | 165 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 166 | }
|
---|
| 167 |
|
---|
| 168 | [TestMethod]
|
---|
| 169 | [TestProperty("Time", "Short")]
|
---|
| 170 | [TestCategory("ExpressionTest")]
|
---|
| 171 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 172 | public void TestMaxWithInsufficientArguments() {
|
---|
[14908] | 173 | TestWithInsufficientArguments("MAX", 1);
|
---|
[14727] | 174 | }
|
---|
| 175 |
|
---|
| 176 | [TestMethod]
|
---|
| 177 | [TestProperty("Time", "Short")]
|
---|
| 178 | [TestCategory("ExpressionTest")]
|
---|
| 179 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 180 | public void TestSmallerThan() {
|
---|
[14908] | 181 | interpreter.FloatStack.Push(10.2, 5.3);
|
---|
| 182 | interpreter.Run(new FloatSmallerThanExpression());
|
---|
[14727] | 183 |
|
---|
[14908] | 184 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
[14727] | 185 |
|
---|
[14908] | 186 | TestStackCounts(booleanStack: 1);
|
---|
[14727] | 187 | }
|
---|
| 188 |
|
---|
| 189 | [TestMethod]
|
---|
| 190 | [TestProperty("Time", "Short")]
|
---|
| 191 | [TestCategory("ExpressionTest")]
|
---|
| 192 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 193 | public void TestSmallerThanWithInsufficientArguments() {
|
---|
[14908] | 194 | TestWithInsufficientArguments("<", 1);
|
---|
[14727] | 195 | }
|
---|
| 196 |
|
---|
| 197 | [TestMethod]
|
---|
| 198 | [TestProperty("Time", "Short")]
|
---|
| 199 | [TestCategory("ExpressionTest")]
|
---|
| 200 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 201 | public void TestGreaterThan() {
|
---|
[14908] | 202 | interpreter.FloatStack.Push(10.2, 5.3);
|
---|
| 203 | interpreter.Run(new FloatGreaterThanExpression());
|
---|
[14727] | 204 |
|
---|
[14908] | 205 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
[14727] | 206 |
|
---|
[14908] | 207 | TestStackCounts(booleanStack: 1);
|
---|
[14727] | 208 | }
|
---|
| 209 |
|
---|
| 210 | [TestMethod]
|
---|
| 211 | [TestProperty("Time", "Short")]
|
---|
| 212 | [TestCategory("ExpressionTest")]
|
---|
| 213 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 214 | public void TestGreaterThanWithInsufficientArguments() {
|
---|
[14908] | 215 | TestWithInsufficientArguments(">", 1);
|
---|
[14727] | 216 | }
|
---|
| 217 |
|
---|
| 218 | [TestMethod]
|
---|
| 219 | [TestProperty("Time", "Short")]
|
---|
| 220 | [TestCategory("ExpressionTest")]
|
---|
| 221 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 222 | public void TestFromBooleanTrue() {
|
---|
[14908] | 223 | interpreter.BooleanStack.Push(true);
|
---|
| 224 | interpreter.Run(new FloatFromBooleanExpression());
|
---|
[14727] | 225 |
|
---|
[14908] | 226 | Assert.AreEqual(1d, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 227 |
|
---|
[14908] | 228 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 229 | }
|
---|
| 230 |
|
---|
| 231 | [TestMethod]
|
---|
| 232 | [TestProperty("Time", "Short")]
|
---|
| 233 | [TestCategory("ExpressionTest")]
|
---|
| 234 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 235 | public void TestFromBooleanFalse() {
|
---|
[14908] | 236 | interpreter.BooleanStack.Push(false);
|
---|
| 237 | interpreter.Run(new FloatFromBooleanExpression());
|
---|
[14727] | 238 |
|
---|
[14908] | 239 | Assert.AreEqual(0d, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 240 |
|
---|
[14908] | 241 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 242 | }
|
---|
| 243 |
|
---|
| 244 | [TestMethod]
|
---|
| 245 | [TestProperty("Time", "Short")]
|
---|
| 246 | [TestCategory("ExpressionTest")]
|
---|
| 247 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 248 | public void TestFromBooleanWithInsufficientArguments() {
|
---|
[14908] | 249 | TestWithInsufficientArguments("FROMBOOLEAN");
|
---|
[14727] | 250 | }
|
---|
| 251 |
|
---|
| 252 | [TestMethod]
|
---|
| 253 | [TestProperty("Time", "Short")]
|
---|
| 254 | [TestCategory("ExpressionTest")]
|
---|
| 255 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 256 | public void TestFromInteger() {
|
---|
[14908] | 257 | interpreter.IntegerStack.Push(5);
|
---|
| 258 | interpreter.Run(new FloatFromIntegerExpression());
|
---|
[14727] | 259 |
|
---|
[14908] | 260 | Assert.AreEqual(5d, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 261 |
|
---|
[14908] | 262 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 263 | }
|
---|
| 264 |
|
---|
| 265 | [TestMethod]
|
---|
| 266 | [TestProperty("Time", "Short")]
|
---|
| 267 | [TestCategory("ExpressionTest")]
|
---|
| 268 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 269 | public void TestFromIntegerWithInsufficientArguments() {
|
---|
[14908] | 270 | TestWithInsufficientArguments("FROMINTEGER");
|
---|
[14727] | 271 | }
|
---|
| 272 |
|
---|
| 273 | [TestMethod]
|
---|
| 274 | [TestProperty("Time", "Short")]
|
---|
| 275 | [TestCategory("ExpressionTest")]
|
---|
| 276 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 277 | public void TestSine() {
|
---|
[14908] | 278 | interpreter.FloatStack.Push(Math.PI / 2);
|
---|
| 279 | interpreter.Run(new FloatSineExpression());
|
---|
[14727] | 280 |
|
---|
[14908] | 281 | Assert.AreEqual(1, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 282 |
|
---|
[14908] | 283 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 284 | }
|
---|
| 285 |
|
---|
| 286 | [TestMethod]
|
---|
| 287 | [TestProperty("Time", "Short")]
|
---|
| 288 | [TestCategory("ExpressionTest")]
|
---|
| 289 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 290 | public void TestSineWithInsufficientArguments() {
|
---|
[14908] | 291 | TestWithInsufficientArguments("SIN");
|
---|
[14727] | 292 | }
|
---|
| 293 |
|
---|
| 294 | [TestMethod]
|
---|
| 295 | [TestProperty("Time", "Short")]
|
---|
| 296 | [TestCategory("ExpressionTest")]
|
---|
| 297 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 298 | public void TestCosine() {
|
---|
[14908] | 299 | interpreter.FloatStack.Push(Math.PI);
|
---|
| 300 | interpreter.Run(new FloatCosineExpression());
|
---|
[14727] | 301 |
|
---|
[14908] | 302 | Assert.AreEqual(-1, interpreter.FloatStack.Top, delta);
|
---|
[14727] | 303 |
|
---|
[14908] | 304 | TestStackCounts(floatStack: 1);
|
---|
[14727] | 305 | }
|
---|
| 306 |
|
---|
| 307 | [TestMethod]
|
---|
| 308 | [TestProperty("Time", "Short")]
|
---|
| 309 | [TestCategory("ExpressionTest")]
|
---|
| 310 | [TestCategory("FloatExpressionTest")]
|
---|
[14906] | 311 | public void TestCosineWithInsufficientArguments() {
|
---|
[14908] | 312 | TestWithInsufficientArguments("COS");
|
---|
[14727] | 313 | }
|
---|
| 314 |
|
---|
[14906] | 315 | protected override double[] GetValues(int count) {
|
---|
[14727] | 316 | var values = new double[count];
|
---|
| 317 |
|
---|
| 318 | for (var i = 0; i < count; i++) values[i] = i * 0.9;
|
---|
| 319 |
|
---|
| 320 | return values;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[14906] | 323 | protected override void CheckOtherStacksAreEmpty() {
|
---|
[14908] | 324 | TestStackCounts(floatStack: null);
|
---|
[14727] | 325 | }
|
---|
| 326 | }
|
---|
| 327 | } |
---|