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