using HeuristicLab.Problems.ProgramSynthesis; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HeuristicLab.Tests.Interpreter { public class ExpressionTest { protected PushInterpreter interpreter; protected PushConfiguration configuration = new PushConfiguration { TopLevelPushCode = false, FloatStringFormat = "R", ErcOptions = new ErcOptions { ErcProbability = 0.05, CharErcOptions = new CharErcOptions(new IntegerRangeErc(0x20, 0x7e)), StringErcOptions = new StringErcOptions(new StringRandomErc { IsEnabled = true, AllowDigits = true, NewStringProbability = 1, AllowLowercaseLetters = true, AllowUppercaseLetters = true }), IntegerErcOptions = new IntegerErcOptions(new IntegerRangeErc(-10000, 10000)), FloatErcOptions = new FloatErcOptions(new FloatRangeErc(-10000, 10000)), BooleanErcOptions = new BooleanErcOptions(new BooleanRandomErc(true, true, true)), StringVectorErcOptions = new StringVectorErcOptions( new StringVectorConstantsErc(new[] { "test", "123", "asdf", "a", "b" })), IntegerVectorErcOptions = new IntegerVectorErcOptions( new IntegerVectorConstantsErc(new[] { 0, -5, 10, 8, -3 })), FloatVectorErcOptions = new FloatVectorErcOptions( new FloatVectorConstantsErc(new[] { 0.0, -5.2, 10.3, 8.1, -3.4 })) } }; [TestInitialize] public void BeforeTest() { interpreter = new PushInterpreter(1337, configuration); } protected void TestStackCounts( int? execStack = 0, int? codeStack = 0, int? nameStack = 0, int? booleanStack = 0, int? floatStack = 0, int? integerStack = 0, int? charStack = 0, int? stringStack = 0, int? integerVectorStack = 0, int? floatVectorStack = 0, int? booleanVectorStack = 0, int? stringVectorStack = 0) { if (execStack.HasValue) Assert.AreEqual(execStack, interpreter.ExecStack.Count); if (codeStack.HasValue) Assert.AreEqual(codeStack, interpreter.CodeStack.Count); if (nameStack.HasValue) Assert.AreEqual(nameStack, interpreter.NameStack.Count); if (booleanStack.HasValue) Assert.AreEqual(booleanStack, interpreter.BooleanStack.Count); if (floatStack.HasValue) Assert.AreEqual(floatStack, interpreter.FloatStack.Count); if (integerStack.HasValue) Assert.AreEqual(integerStack, interpreter.IntegerStack.Count); if (charStack.HasValue) Assert.AreEqual(charStack, interpreter.CharStack.Count); if (stringStack.HasValue) Assert.AreEqual(stringStack, interpreter.StringStack.Count); if (integerVectorStack.HasValue) Assert.AreEqual(integerVectorStack, interpreter.IntegerVectorStack.Count); if (floatVectorStack.HasValue) Assert.AreEqual(floatVectorStack, interpreter.FloatVectorStack.Count); if (booleanVectorStack.HasValue) Assert.AreEqual(booleanVectorStack, interpreter.BooleanVectorStack.Count); if (stringVectorStack.HasValue) Assert.AreEqual(stringVectorStack, interpreter.StringVectorStack.Count); } } }