[14906] | 1 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
[14727] | 2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
| 3 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
| 4 |
|
---|
| 5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 6 |
|
---|
| 7 | [TestClass]
|
---|
[14906] | 8 | public class IntegerExpressionTests : CommonTests<long> {
|
---|
[14727] | 9 | protected override string TypeName
|
---|
| 10 | {
|
---|
| 11 | get
|
---|
| 12 | {
|
---|
| 13 | return "INTEGER";
|
---|
| 14 | }
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[14834] | 17 | protected override IPushStack<long> Stack
|
---|
[14727] | 18 | {
|
---|
| 19 | get
|
---|
| 20 | {
|
---|
[14908] | 21 | return interpreter.IntegerStack;
|
---|
[14727] | 22 | }
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | [TestMethod]
|
---|
| 26 | [TestProperty("Time", "Short")]
|
---|
| 27 | [TestCategory("ExpressionTest")]
|
---|
| 28 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 29 | public void TestAdd() {
|
---|
[14908] | 30 | interpreter.IntegerStack.Push(5, 5);
|
---|
| 31 | interpreter.Run(new IntegerAddExpression());
|
---|
[14727] | 32 |
|
---|
[14908] | 33 | Assert.AreEqual(10, interpreter.IntegerStack.Top);
|
---|
[14727] | 34 |
|
---|
[14908] | 35 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 36 | }
|
---|
| 37 |
|
---|
| 38 | [TestMethod]
|
---|
| 39 | [TestProperty("Time", "Short")]
|
---|
| 40 | [TestCategory("ExpressionTest")]
|
---|
| 41 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 42 | public void TestAddWithInsufficientArguments() {
|
---|
[14908] | 43 | TestWithInsufficientArguments("+", 1);
|
---|
[14727] | 44 | }
|
---|
| 45 |
|
---|
| 46 | [TestMethod]
|
---|
| 47 | [TestProperty("Time", "Short")]
|
---|
| 48 | [TestCategory("ExpressionTest")]
|
---|
| 49 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 50 | public void TestSubtract() {
|
---|
[14908] | 51 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 52 | interpreter.Run(new IntegerSubtractExpression());
|
---|
[14727] | 53 |
|
---|
[14908] | 54 | Assert.AreEqual(5, interpreter.IntegerStack.Top);
|
---|
[14727] | 55 |
|
---|
[14908] | 56 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 57 | }
|
---|
| 58 |
|
---|
| 59 | [TestMethod]
|
---|
| 60 | [TestProperty("Time", "Short")]
|
---|
| 61 | [TestCategory("ExpressionTest")]
|
---|
| 62 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 63 | public void TestSubtractWithInsufficientArguments() {
|
---|
[14908] | 64 | TestWithInsufficientArguments("-", 1);
|
---|
[14727] | 65 | }
|
---|
| 66 |
|
---|
| 67 | [TestMethod]
|
---|
| 68 | [TestProperty("Time", "Short")]
|
---|
| 69 | [TestCategory("ExpressionTest")]
|
---|
| 70 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 71 | public void TestMultiply() {
|
---|
[14908] | 72 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 73 | interpreter.Run(new IntegerMultiplyExpression());
|
---|
[14727] | 74 |
|
---|
[14908] | 75 | Assert.AreEqual(50, interpreter.IntegerStack.Top);
|
---|
[14727] | 76 |
|
---|
[14908] | 77 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 78 | }
|
---|
| 79 |
|
---|
| 80 | [TestMethod]
|
---|
| 81 | [TestProperty("Time", "Short")]
|
---|
| 82 | [TestCategory("ExpressionTest")]
|
---|
| 83 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 84 | public void TestMultiplyWithInsufficientArguments() {
|
---|
[14908] | 85 | TestWithInsufficientArguments("*", 1);
|
---|
[14727] | 86 | }
|
---|
| 87 |
|
---|
| 88 | [TestMethod]
|
---|
| 89 | [TestProperty("Time", "Short")]
|
---|
| 90 | [TestCategory("ExpressionTest")]
|
---|
| 91 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 92 | public void TestDivide() {
|
---|
[14908] | 93 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 94 | interpreter.Run(new IntegerDivideExpression());
|
---|
[14727] | 95 |
|
---|
[14908] | 96 | Assert.AreEqual(2, interpreter.IntegerStack.Top);
|
---|
[14727] | 97 |
|
---|
[14908] | 98 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 99 | }
|
---|
| 100 |
|
---|
| 101 | [TestMethod]
|
---|
| 102 | [TestProperty("Time", "Short")]
|
---|
| 103 | [TestCategory("ExpressionTest")]
|
---|
| 104 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 105 | public void TestDivideWithInsufficientArguments() {
|
---|
[14908] | 106 | TestWithInsufficientArguments("/", 1);
|
---|
[14727] | 107 | }
|
---|
| 108 |
|
---|
| 109 | [TestMethod]
|
---|
| 110 | [TestProperty("Time", "Short")]
|
---|
| 111 | [TestCategory("ExpressionTest")]
|
---|
| 112 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 113 | public void TestModulo() {
|
---|
[14908] | 114 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 115 | interpreter.Run(new IntegerModuloExpression());
|
---|
[14727] | 116 |
|
---|
[14908] | 117 | Assert.AreEqual(0, interpreter.IntegerStack.Top);
|
---|
[14727] | 118 |
|
---|
[14908] | 119 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 120 | }
|
---|
| 121 |
|
---|
| 122 | [TestMethod]
|
---|
| 123 | [TestProperty("Time", "Short")]
|
---|
| 124 | [TestCategory("ExpressionTest")]
|
---|
| 125 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 126 | public void TestModuloWithInsufficientArguments() {
|
---|
[14908] | 127 | TestWithInsufficientArguments("%", 1);
|
---|
[14727] | 128 | }
|
---|
| 129 |
|
---|
| 130 | [TestMethod]
|
---|
| 131 | [TestProperty("Time", "Short")]
|
---|
| 132 | [TestCategory("ExpressionTest")]
|
---|
| 133 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 134 | public void TestMin() {
|
---|
[14908] | 135 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 136 | interpreter.Run(new IntegerMinExpression());
|
---|
[14727] | 137 |
|
---|
[14908] | 138 | Assert.AreEqual(5, interpreter.IntegerStack.Top);
|
---|
[14727] | 139 |
|
---|
[14908] | 140 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 141 | }
|
---|
| 142 |
|
---|
| 143 | [TestMethod]
|
---|
| 144 | [TestProperty("Time", "Short")]
|
---|
| 145 | [TestCategory("ExpressionTest")]
|
---|
| 146 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 147 | public void TestMinWithInsufficientArguments() {
|
---|
[14908] | 148 | TestWithInsufficientArguments("MIN", 1);
|
---|
[14727] | 149 | }
|
---|
| 150 |
|
---|
| 151 | [TestMethod]
|
---|
| 152 | [TestProperty("Time", "Short")]
|
---|
| 153 | [TestCategory("ExpressionTest")]
|
---|
| 154 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 155 | public void TestMax() {
|
---|
[14908] | 156 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 157 | interpreter.Run(new IntegerMaxExpression());
|
---|
[14727] | 158 |
|
---|
[14908] | 159 | Assert.AreEqual(10, interpreter.IntegerStack.Top);
|
---|
[14727] | 160 |
|
---|
[14908] | 161 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 162 | }
|
---|
| 163 |
|
---|
| 164 | [TestMethod]
|
---|
| 165 | [TestProperty("Time", "Short")]
|
---|
| 166 | [TestCategory("ExpressionTest")]
|
---|
| 167 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 168 | public void TestMaxWithInsufficientArguments() {
|
---|
[14908] | 169 | TestWithInsufficientArguments("MAX", 1);
|
---|
[14727] | 170 | }
|
---|
| 171 |
|
---|
| 172 | [TestMethod]
|
---|
| 173 | [TestProperty("Time", "Short")]
|
---|
| 174 | [TestCategory("ExpressionTest")]
|
---|
| 175 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 176 | public void TestSmallerThan() {
|
---|
[14908] | 177 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 178 | interpreter.Run(new IntegerSmallerThanExpression());
|
---|
[14727] | 179 |
|
---|
[14908] | 180 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
[14727] | 181 |
|
---|
[14908] | 182 | TestStackCounts(booleanStack: 1);
|
---|
[14727] | 183 | }
|
---|
| 184 |
|
---|
| 185 | [TestMethod]
|
---|
| 186 | [TestProperty("Time", "Short")]
|
---|
| 187 | [TestCategory("ExpressionTest")]
|
---|
| 188 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 189 | public void TestSmallerThanWithInsufficientArguments() {
|
---|
[14908] | 190 | TestWithInsufficientArguments("<", 1);
|
---|
[14727] | 191 | }
|
---|
| 192 |
|
---|
| 193 | [TestMethod]
|
---|
| 194 | [TestProperty("Time", "Short")]
|
---|
| 195 | [TestCategory("ExpressionTest")]
|
---|
| 196 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 197 | public void TestGreaterThan() {
|
---|
[14908] | 198 | interpreter.IntegerStack.Push(10, 5);
|
---|
| 199 | interpreter.Run(new IntegerGreaterThanExpression());
|
---|
[14727] | 200 |
|
---|
[14908] | 201 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
[14727] | 202 |
|
---|
[14908] | 203 | TestStackCounts(booleanStack: 1);
|
---|
[14727] | 204 | }
|
---|
| 205 |
|
---|
| 206 | [TestMethod]
|
---|
| 207 | [TestProperty("Time", "Short")]
|
---|
| 208 | [TestCategory("ExpressionTest")]
|
---|
| 209 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 210 | public void TestGreaterThanWithInsufficientArguments() {
|
---|
[14908] | 211 | TestWithInsufficientArguments(">", 1);
|
---|
[14727] | 212 | }
|
---|
| 213 |
|
---|
| 214 | [TestMethod]
|
---|
| 215 | [TestProperty("Time", "Short")]
|
---|
| 216 | [TestCategory("ExpressionTest")]
|
---|
| 217 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 218 | public void TestFromBooleanTrue() {
|
---|
[14908] | 219 | interpreter.BooleanStack.Push(true);
|
---|
| 220 | interpreter.Run(new IntegerFromBooleanExpression());
|
---|
[14727] | 221 |
|
---|
[14908] | 222 | Assert.AreEqual(1, interpreter.IntegerStack.Top);
|
---|
[14727] | 223 |
|
---|
[14908] | 224 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 225 | }
|
---|
| 226 |
|
---|
| 227 | [TestMethod]
|
---|
| 228 | [TestProperty("Time", "Short")]
|
---|
| 229 | [TestCategory("ExpressionTest")]
|
---|
| 230 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 231 | public void TestFromBooleanWithInsufficientArguments() {
|
---|
[14908] | 232 | TestWithInsufficientArguments("FROMBOOLEAN");
|
---|
[14727] | 233 | }
|
---|
| 234 |
|
---|
| 235 | [TestMethod]
|
---|
| 236 | [TestProperty("Time", "Short")]
|
---|
| 237 | [TestCategory("ExpressionTest")]
|
---|
| 238 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 239 | public void TestFromBooleanFalse() {
|
---|
[14908] | 240 | interpreter.BooleanStack.Push(false);
|
---|
| 241 | interpreter.Run(new IntegerFromBooleanExpression());
|
---|
[14727] | 242 |
|
---|
[14908] | 243 | Assert.AreEqual(0, interpreter.IntegerStack.Top);
|
---|
[14727] | 244 |
|
---|
[14908] | 245 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 246 | }
|
---|
| 247 |
|
---|
| 248 | [TestMethod]
|
---|
| 249 | [TestProperty("Time", "Short")]
|
---|
| 250 | [TestCategory("ExpressionTest")]
|
---|
| 251 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 252 | public void TestFromFloat() {
|
---|
[14908] | 253 | interpreter.FloatStack.Push(1.5);
|
---|
| 254 | interpreter.Run(new IntegerFromFloatExpression());
|
---|
[14727] | 255 |
|
---|
[14908] | 256 | Assert.AreEqual(1, interpreter.IntegerStack.Top);
|
---|
[14727] | 257 |
|
---|
[14908] | 258 | TestStackCounts(integerStack: 1);
|
---|
[14727] | 259 | }
|
---|
| 260 |
|
---|
| 261 | [TestMethod]
|
---|
| 262 | [TestProperty("Time", "Short")]
|
---|
| 263 | [TestCategory("ExpressionTest")]
|
---|
| 264 | [TestCategory("IntegerExpressionTest")]
|
---|
[14906] | 265 | public void TestFromFloatWithInsufficientArguments() {
|
---|
[14908] | 266 | TestWithInsufficientArguments("FROMFLOAT");
|
---|
[14727] | 267 | }
|
---|
| 268 |
|
---|
[14906] | 269 | protected override long[] GetValues(int count) {
|
---|
[14727] | 270 | var values = new long[count];
|
---|
| 271 |
|
---|
| 272 | for (long i = 0; i < count; i++) values[i] = i;
|
---|
| 273 |
|
---|
| 274 | return values;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[14906] | 277 | protected override void CheckOtherStacksAreEmpty() {
|
---|
[14908] | 278 | TestStackCounts(integerStack: null);
|
---|
[14727] | 279 | }
|
---|
| 280 | }
|
---|
| 281 | } |
---|