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