using HeuristicLab.Problems.ProgramSynthesis; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HeuristicLab.Tests.Interpreter.Expressions { [TestClass] public class BooleanExpressionTests : CommonTests { protected override string TypeName { get { return "BOOLEAN"; } } protected override IPushStack Stack { get { return interpreter.BooleanStack; } } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestAnd() { interpreter.BooleanStack.Push(true, false); interpreter.Run(new BooleanAndExpression()); Assert.AreEqual(false, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestAndWithInsufficientArguments() { TestWithInsufficientArguments("AND", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestOr() { interpreter.BooleanStack.Push(true, false); interpreter.Run(new BooleanOrExpression()); Assert.AreEqual(true, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestOrWithInsufficientArguments() { TestWithInsufficientArguments("OR", 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestNot() { interpreter.BooleanStack.Push(true); interpreter.Run(new BooleanNotExpression()); Assert.AreEqual(false, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestNotWithInsufficientArguments() { TestWithInsufficientArguments("NOT"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromFloat() { interpreter.FloatStack.Push(2.0); interpreter.Run(new BooleanFromFloatExpression()); Assert.AreEqual(true, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromFloatWithInsufficientArguments() { TestWithInsufficientArguments("FROMFLOAT"); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromInteger() { interpreter.IntegerStack.Push(2); interpreter.Run(new BooleanFromIntegerExpression()); Assert.AreEqual(true, interpreter.BooleanStack.Top); TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("BooleanExpressionTest")] public void TestFromIntegerWithInsufficientArguments() { 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() { TestStackCounts(booleanStack: null); } } }