namespace HeuristicLab.Tests.Interpreter.Expressions { using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; using HeuristicLab.Problems.ProgramSynthesis.Push.Parser; using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CodeExpressionTests : CommonTests { protected override string TypeName { get { return "CODE"; } } protected override IStack Stack { get { return this.interpreter.CodeStack; } } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAppendLists() { var first = PushParser.Parse("( A )"); var second = PushParser.Parse("( B )"); var result = PushParser.Parse("( A B )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeAppendExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAppendListAndLiteral() { var first = PushParser.Parse("( A )"); var second = PushParser.Parse("5"); var result = PushParser.Parse("( A 5 )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeAppendExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAppendLiterals() { var first = PushParser.Parse("4"); var second = PushParser.Parse("5"); var result = PushParser.Parse("( 4 5 )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeAppendExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDuplicateList() { var list = PushParser.Parse("( A B C )"); var result = PushParser.Parse("( A B C )"); this.interpreter.CodeStack.Push(list); this.interpreter.Run(new CodeDuplicateExpression()); Assert.AreEqual(this.Stack.Count, 2); Assert.AreEqual(this.Stack[0], list); Assert.AreEqual(this.Stack[1], result); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAtomList() { var first = PushParser.Parse("( A )"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeAtomExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAtomLiteral() { var first = PushParser.Parse("5"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeAtomExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestAtomSingleInstruction() { var first = PushParser.Parse("INTEGER.+"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeAtomExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestCarList() { var first = PushParser.Parse("( A B C )"); var result = PushParser.Parse("A"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeCarExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestCarNoList() { var first = PushParser.Parse("5"); var result = PushParser.Parse("5"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeCarExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestCdrList() { var first = PushParser.Parse("( A B C )"); var result = PushParser.Parse("( B C )"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestCdrNoList() { var first = PushParser.Parse("5"); var result = PushParser.Parse("( )"); this.interpreter.CodeStack.Push(first); this.interpreter.Run(new CodeCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestCons() { var first = PushParser.Parse("( B C )"); var second = PushParser.Parse("A"); var result = PushParser.Parse("( A B C )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeConsExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestContainsTrue() { var first = PushParser.Parse("A"); var second = PushParser.Parse("( A B C )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeContainsExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestContainsFalse() { var first = PushParser.Parse("D"); var second = PushParser.Parse("( A B C )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeContainsExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestContainer() { var first = PushParser.Parse("( A )"); var second = PushParser.Parse("( B ( C ( A ) ) ( D ( A ) ) )"); var result = PushParser.Parse("( C ( A ) )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeContainerExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDefinition() { var code = PushParser.Parse("( A )"); this.interpreter.CustomExpressions.Add("Test", code); this.interpreter.NameStack.Push("Test"); this.interpreter.Run(new CodeDefinitionExpression()); Assert.AreEqual(code, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDefinitionWithoutMatchingName() { var code = PushParser.Parse("( A )"); var program = new CodeDefinitionExpression(); this.interpreter.CustomExpressions.Add("Test1", code); this.interpreter.NameStack.Push("Test2"); this.interpreter.Run(program); this.TestStackCounts(nameStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDiscrepancy() { var first = PushParser.Parse("( A B )"); var second = PushParser.Parse("( B C )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeDiscrepancyExpression()); Assert.AreEqual(2, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDiscrepancyAllEqual() { var first = PushParser.Parse("( A B )"); var second = PushParser.Parse("( B A )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeDiscrepancyExpression()); Assert.AreEqual(0, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDiscrepancyComplex() { var first = PushParser.Parse("( A A B C D A )"); var second = PushParser.Parse("( A A B D E )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeDiscrepancyExpression()); Assert.AreEqual(3, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDiscrepancWithLists() { var first = PushParser.Parse("( ( A ) A ( B ) C D A )"); var second = PushParser.Parse("( A ( A ) B D E )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeDiscrepancyExpression()); Assert.AreEqual(5, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDo() { var prog = PushParser.Parse("( 10 )"); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoExpression()); Assert.AreEqual(10, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoX() { var prog = PushParser.Parse("( 10 )"); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoXExpression()); Assert.AreEqual(10, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoCount() { var prog = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoCountExpression()); Assert.AreEqual(6, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoCountWithNegativeCounter() { var prog = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(-1); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoCountExpression()); Assert.AreEqual(-1, this.interpreter.IntegerStack.Top); this.TestStackCounts(codeStack: 1, integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoRange() { var prog = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(3, 5); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoRangeExpression()); Assert.AreEqual(12, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoRangeWithEqualIndecators() { var prog = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(3, 3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoRangeExpression()); Assert.AreEqual(3, this.interpreter.IntegerStack.Top); this.TestStackCounts(codeStack: 1, integerStack: 2); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoRangeWithNegativeIndecators() { var prog = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(-3, -5); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoRangeExpression()); Assert.AreEqual(-12, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoTimes() { var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )"); this.interpreter.IntegerStack.Push(2, 3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoTimesExpression()); Assert.AreEqual(32, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestDoTimesWithNegativeCounter() { var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )"); this.interpreter.IntegerStack.Push(2, -3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeDoTimesExpression()); Assert.AreEqual(-3, this.interpreter.IntegerStack.Top); this.TestStackCounts(codeStack: 1, integerStack: 2); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNestedDoRange() { this.interpreter.Run( "( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )"); Assert.AreEqual(144, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNestedDoCount() { this.interpreter.Run( "( 2 CODE.QUOTE ( 1 INTEGER.+ 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*COUNT INTEGER.+ ) CODE.DO*COUNT )"); Assert.AreEqual(144, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNestedDoTimes() { this.interpreter.Run( "( 3 CODE.QUOTE ( 2 3 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )"); Assert.AreEqual(128, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestExtract() { var prog = PushParser.Parse("( A ( B C ( D ) E ) F G H I J ( K ) L )"); var result = PushParser.Parse("( D )"); this.interpreter.IntegerStack.Push(5); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeExtractExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestExtractInteger() { var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )"); var result = PushParser.Parse("5"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeExtractExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestExtractFloat() { var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )"); var result = PushParser.Parse("4.2"); this.interpreter.IntegerStack.Push(6); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeExtractExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestExtractBoolean() { var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )"); var result = PushParser.Parse("FALSE"); this.interpreter.IntegerStack.Push(8); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeExtractExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestExtractInstruction() { var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )"); var result = PushParser.Parse("INTEGER.+"); this.interpreter.IntegerStack.Push(7); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeExtractExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestFromBoolean() { var result = PushParser.Parse("FALSE"); this.interpreter.BooleanStack.Push(false); this.interpreter.Run(new CodeFromBooleanExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestFromFloat() { var result = PushParser.Parse("4.1"); this.interpreter.FloatStack.Push(4.1); this.interpreter.Run(new CodeFromFloatExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestFromInteger() { var result = PushParser.Parse("4"); this.interpreter.IntegerStack.Push(4); this.interpreter.Run(new CodeFromIntegerExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestFromName() { var result = PushParser.Parse("A"); this.interpreter.NameStack.Push("A"); this.interpreter.Run(new CodeFromNameExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestIfTrue() { var first = PushParser.Parse("FALSCH"); var second = PushParser.Parse("WAHR"); this.interpreter.BooleanStack.Push(true); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeIfExpression()); Assert.AreEqual("WAHR", this.interpreter.NameStack.Top); this.TestStackCounts(nameStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestIfFalse() { var first = PushParser.Parse("FALSCH"); var second = PushParser.Parse("WAHR"); this.interpreter.BooleanStack.Push(false); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeIfExpression()); Assert.AreEqual("FALSCH", this.interpreter.NameStack.Top); this.TestStackCounts(nameStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestInsert() { var first = PushParser.Parse("( A ( B ) C D )"); var second = PushParser.Parse("( E )"); var result = PushParser.Parse("( A ( B ) ( E ) D )"); this.interpreter.IntegerStack.Push(2); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeInsertExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestInsertWithNegativeN() { var first = PushParser.Parse("( A ( B ) C D )"); var second = PushParser.Parse("( E )"); var result = PushParser.Parse("( A ( B ) ( E ) D )"); this.interpreter.IntegerStack.Push(-2); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeInsertExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestInsertWithTooBigN() { var first = PushParser.Parse("( A ( B ) C D )"); var second = PushParser.Parse("( E )"); var result = PushParser.Parse("( A ( B ) ( E ) D )"); this.interpreter.IntegerStack.Push(10); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeInsertExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestList() { var first = PushParser.Parse("A"); var second = PushParser.Parse("( B )"); var result = PushParser.Parse("( A ( B ) )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeListExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestMemberTrue() { var first = PushParser.Parse("( A B ( B ) C "); var second = PushParser.Parse("( B )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeMemberExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestMemberFalse() { var first = PushParser.Parse("( A B C "); var second = PushParser.Parse("( B )"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeMemberExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestMemberIfNoList() { var first = PushParser.Parse("B"); var second = PushParser.Parse("B"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodeMemberExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNoop() { this.interpreter.Run(new CodeNoopExpression()); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthIfNoList() { var prog = PushParser.Parse("A"); var result = PushParser.Parse("A"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthIfEmpty() { var prog = PushParser.Parse("( )"); var result = PushParser.Parse("( )"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNth() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthWithTooBigN() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(13); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthWithNegativeN() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(-3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthCdr() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(2); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthCdrWithTooBigN() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(10); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthCdrWithNegativeN() { var prog = PushParser.Parse("( A B C D E )"); var result = PushParser.Parse("D"); this.interpreter.IntegerStack.Push(-2); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthCdrIfEmpty() { var prog = PushParser.Parse("( )"); var result = PushParser.Parse("( )"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNthCdrIfNoList() { var prog = PushParser.Parse("A"); var result = PushParser.Parse("A"); this.interpreter.IntegerStack.Push(3); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNthCdrExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNullTrue() { var prog = PushParser.Parse("( )"); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNullExpression()); Assert.AreEqual(true, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestNullFalse() { var prog = PushParser.Parse("A"); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeNullExpression()); Assert.AreEqual(false, this.interpreter.BooleanStack.Top); this.TestStackCounts(booleanStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestPosition() { var first = PushParser.Parse("( A B C D )"); var second = PushParser.Parse("C"); this.interpreter.CodeStack.Push(second, first); this.interpreter.Run(new CodePositionExpression()); Assert.AreEqual(2, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestQuote() { var result = PushParser.Parse("A"); this.interpreter.Run("( CODE.QUOTE A )"); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestSize() { var prog = PushParser.Parse("( A ( B ( C ) ) ( D ) INTEGER.+ )"); this.interpreter.CodeStack.Push(prog); this.interpreter.Run(new CodeSizeExpression()); Assert.AreEqual(4, this.interpreter.IntegerStack.Top); this.TestStackCounts(integerStack: 1); } [TestMethod] [TestProperty("Time", "Short")] [TestCategory("ExpressionTest")] [TestCategory("CodeExpressionTest")] public void TestSubstitude() { var first = PushParser.Parse("( A B C D A B C D )"); var second = PushParser.Parse("E"); var third = PushParser.Parse("A"); var result = PushParser.Parse("( E B C D E B C D )"); this.interpreter.CodeStack.Push(third, second, first); this.interpreter.Run(new CodeSubstitutionExpression()); Assert.AreEqual(result, this.interpreter.CodeStack.Top); this.CheckOtherStacksAreEmpty(); } protected override Expression[] GetValues(int count) { var values = new Expression[count]; for (var i = 0; i < count; i++) values[i] = new CodeNoopExpression(); return values; } protected override Expression[] Get2Different() { return new Expression[] { new CodeNoopExpression(), new CodeNullExpression() }; } protected override void CheckOtherStacksAreEmpty() { this.TestStackCounts(codeStack: null); } } }