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