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 BooleanExpressionTests : CommonTests { protected override string TypeName { get { return "BOOLEAN"; } } protected override IStack Stack { get { return this.interpreter.BooleanStack; } } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestAnd() { this.interpreter.BooleanStack.Push(true, false); this.interpreter.Run(new BooleanAndExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestAndWithInsufficientArguments() { this.TestWithInsufficientArguments("AND", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestOr() { this.interpreter.BooleanStack.Push(true, false); this.interpreter.Run(new BooleanOrExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestOrWithInsufficientArguments() { this.TestWithInsufficientArguments("OR", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestNot() { this.interpreter.BooleanStack.Push(true); this.interpreter.Run(new BooleanNotExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestNotWithInsufficientArguments() { this.TestWithInsufficientArguments("NOT"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromFloat() { this.interpreter.FloatStack.Push(2.0); this.interpreter.Run(new BooleanFromFloatExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromFloatWithInsufficientArguments() { this.TestWithInsufficientArguments("FROMFLOAT"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromInteger() { this.interpreter.IntegerStack.Push(2); this.interpreter.Run(new BooleanFromIntegerExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromIntegerWithInsufficientArguments() { this.TestWithInsufficientArguments("FROMINTEGER"); } protected override bool[] GetValues(int count) { var values = new bool[count]; for (var i = 0; i < count; i++) values[i] = i % 2 == 0; return values; } protected override void CheckOtherStacksAreEmpty() { this.TestStackCounts(booleanStack: null); } } }