using HeuristicLab.Problems.ProgramSynthesis; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HeuristicLab.Tests.Interpreter.Expressions { [TestClass] public class IntegerExpressionTests : CommonTests { protected override string TypeName { get { return "INTEGER"; } } protected override IPushStack Stack { get { return interpreter.IntegerStack; } } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestAdd() { interpreter.IntegerStack.Push(5, 5); interpreter.Run(new IntegerAddExpression()); Assert.AreEqual(10, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestAddWithInsufficientArguments() { TestWithInsufficientArguments("+", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestSubtract() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerSubtractExpression()); Assert.AreEqual(5, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestSubtractWithInsufficientArguments() { TestWithInsufficientArguments("-", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMultiply() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerMultiplyExpression()); Assert.AreEqual(50, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMultiplyWithInsufficientArguments() { TestWithInsufficientArguments("*", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestDivide() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerDivideExpression()); Assert.AreEqual(2, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestDivideWithInsufficientArguments() { TestWithInsufficientArguments("/", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestModulo() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerModuloExpression()); Assert.AreEqual(0, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestModuloWithInsufficientArguments() { TestWithInsufficientArguments("%", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMin() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerMinExpression()); Assert.AreEqual(5, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMinWithInsufficientArguments() { TestWithInsufficientArguments("MIN", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMax() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerMaxExpression()); Assert.AreEqual(10, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestMaxWithInsufficientArguments() { TestWithInsufficientArguments("MAX", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestSmallerThan() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerSmallerThanExpression()); Assert.AreEqual(false, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestSmallerThanWithInsufficientArguments() { TestWithInsufficientArguments("<", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestGreaterThan() { interpreter.IntegerStack.Push(10, 5); interpreter.Run(new IntegerGreaterThanExpression()); Assert.AreEqual(true, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestGreaterThanWithInsufficientArguments() { TestWithInsufficientArguments(">", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestFromBooleanTrue() { interpreter.BooleanStack.Push(true); interpreter.Run(new IntegerFromBooleanExpression()); Assert.AreEqual(1, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestFromBooleanWithInsufficientArguments() { TestWithInsufficientArguments("FROMBOOLEAN"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestFromBooleanFalse() { interpreter.BooleanStack.Push(false); interpreter.Run(new IntegerFromBooleanExpression()); Assert.AreEqual(0, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestFromFloat() { interpreter.FloatStack.Push(1.5); interpreter.Run(new IntegerFromFloatExpression()); Assert.AreEqual(1, interpreter.IntegerStack.Top); TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("IntegerExpressionTest")] public void TestFromFloatWithInsufficientArguments() { TestWithInsufficientArguments("FROMFLOAT"); } protected override long[] GetValues(int count) { var values = new long[count]; for (long i = 0; i < count; i++) values[i] = i; return values; } protected override void CheckOtherStacksAreEmpty() { TestStackCounts(integerStack: null); } } }