namespace HeuristicLab.Tests.Interpreter.Expressions { using System.Linq; using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CharExpressionTests : CommonTests { protected override string TypeName { get { return "CHAR"; } } protected override IPushStack Stack { get { return interpreter.CharStack; } } protected override char[] GetValues(int count) { return Enumerable .Range(0, count) .Select(_ => interpreter.Configuration.ErcOptions.CharErcOptions.GetErcValue(interpreter.Random)) .ToArray(); } protected override void CheckOtherStacksAreEmpty() { TestStackCounts(charStack: null); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestIsWhitespace() { interpreter.CharStack.Push(' ', '_'); interpreter.Run(new CharIsWhitespaceExpression()); interpreter.Run(new CharIsWhitespaceExpression()); Assert.IsTrue(interpreter.BooleanStack[0]); Assert.IsFalse(interpreter.BooleanStack[1]); TestStackCounts(booleanStack: 2); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestIsLetter() { interpreter.CharStack.Push('a', '_'); interpreter.Run(new CharIsLetterExpression()); interpreter.Run(new CharIsLetterExpression()); Assert.IsTrue(interpreter.BooleanStack[0]); Assert.IsFalse(interpreter.BooleanStack[1]); TestStackCounts(booleanStack: 2); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestIsDigit() { interpreter.CharStack.Push('1', 'a'); interpreter.Run(new CharIsDigitExpression()); interpreter.Run(new CharIsDigitExpression()); Assert.IsTrue(interpreter.BooleanStack[0]); Assert.IsFalse(interpreter.BooleanStack[1]); TestStackCounts(booleanStack: 2); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestFromInteger() { interpreter.IntegerStack.Push(1, -1, 129); interpreter.Run(new CharFromIntegerExpression()); interpreter.Run(new CharFromIntegerExpression()); interpreter.Run(new CharFromIntegerExpression()); Assert.AreEqual(0x01, interpreter.CharStack[0]); Assert.AreEqual(0x01, interpreter.CharStack[1]); Assert.AreEqual(0x01, interpreter.CharStack[2]); TestStackCounts(charStack: 3); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestFromFloat() { interpreter.FloatStack.Push(1.5, -1.5, 129.5); interpreter.Run(new CharFromFloatExpression()); interpreter.Run(new CharFromFloatExpression()); interpreter.Run(new CharFromFloatExpression()); Assert.AreEqual(0x01, interpreter.CharStack[0]); Assert.AreEqual(0x01, interpreter.CharStack[1]); Assert.AreEqual(0x01, interpreter.CharStack[2]); TestStackCounts(charStack: 3); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CharExpressionTest")] public void TestAllFromString() { interpreter.StringStack.Push("test"); interpreter.Run(new CharAllFromStringExpression()); Assert.AreEqual('t', interpreter.CharStack[0]); Assert.AreEqual('e', interpreter.CharStack[1]); Assert.AreEqual('s', interpreter.CharStack[2]); Assert.AreEqual('t', interpreter.CharStack[3]); TestStackCounts(charStack: 4); } } }