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