namespace HeuristicLab.Tests.Interpreter.Expressions { using System; using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class FloatExpressionTests : CommonTests { private const double delta = 0.00001; protected override string TypeName { get { return "FLOAT"; } } protected override IPushStack Stack { get { return interpreter.FloatStack; } } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestAdd() { interpreter.FloatStack.Push(5.3, 5.3); interpreter.Run(new FloatAddExpression()); Assert.AreEqual(10.6, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestAddWithInsufficientArguments() { TestWithInsufficientArguments("+", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSubtract() { interpreter.FloatStack.Push(10.2, 5.3); interpreter.Run(new FloatSubtractExpression()); Assert.AreEqual(4.9, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSubractWithInsufficientArguments() { TestWithInsufficientArguments("-", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMultiply() { interpreter.FloatStack.Push(9.9, 3.3); interpreter.Run(new FloatMultiplyExpression()); Assert.AreEqual(32.67, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMultiplyWithInsufficientArguments() { TestWithInsufficientArguments("*", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestDivide() { interpreter.FloatStack.Push(9.9, 3.3); interpreter.Run(new FloatDivideExpression()); Assert.AreEqual(3.0, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestDivideWithInsufficientArguments() { TestWithInsufficientArguments("/", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestModulo() { interpreter.FloatStack.Push(11.6, 5.3); interpreter.Run(new FloatModuloExpression()); Assert.AreEqual(1, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestModuloWithInsufficientArguments() { TestWithInsufficientArguments("%", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMin() { interpreter.FloatStack.Push(10.2, 5.3); interpreter.Run(new FloatMinExpression()); Assert.AreEqual(5.3, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMinWithInsufficientArguments() { TestWithInsufficientArguments("MIN", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMax() { interpreter.FloatStack.Push(10.3, 5.3); interpreter.Run(new FloatMaxExpression()); Assert.AreEqual(10.3, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestMaxWithInsufficientArguments() { TestWithInsufficientArguments("MAX", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSmallerThan() { interpreter.FloatStack.Push(10.2, 5.3); interpreter.Run(new FloatSmallerThanExpression()); Assert.AreEqual(false, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSmallerThanWithInsufficientArguments() { TestWithInsufficientArguments("<", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestGreaterThan() { interpreter.FloatStack.Push(10.2, 5.3); interpreter.Run(new FloatGreaterThanExpression()); Assert.AreEqual(true, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestGreaterThanWithInsufficientArguments() { TestWithInsufficientArguments(">", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestFromBooleanTrue() { interpreter.BooleanStack.Push(true); interpreter.Run(new FloatFromBooleanExpression()); Assert.AreEqual(1d, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestFromBooleanFalse() { interpreter.BooleanStack.Push(false); interpreter.Run(new FloatFromBooleanExpression()); Assert.AreEqual(0d, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestFromBooleanWithInsufficientArguments() { TestWithInsufficientArguments("FROMBOOLEAN"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestFromInteger() { interpreter.IntegerStack.Push(5); interpreter.Run(new FloatFromIntegerExpression()); Assert.AreEqual(5d, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestFromIntegerWithInsufficientArguments() { TestWithInsufficientArguments("FROMINTEGER"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSine() { interpreter.FloatStack.Push(Math.PI / 2); interpreter.Run(new FloatSineExpression()); Assert.AreEqual(1, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestSineWithInsufficientArguments() { TestWithInsufficientArguments("SIN"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestCosine() { interpreter.FloatStack.Push(Math.PI); interpreter.Run(new FloatCosineExpression()); Assert.AreEqual(-1, interpreter.FloatStack.Top, delta); TestStackCounts(floatStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("FloatExpressionTest")] public void TestCosineWithInsufficientArguments() { TestWithInsufficientArguments("COS"); } protected override double[] GetValues(int count) { var values = new double[count]; for (var i = 0; i < count; i++) values[i] = i * 0.9; return values; } protected override void CheckOtherStacksAreEmpty() { TestStackCounts(floatStack: null); } } }