- Timestamp:
- 06/01/17 09:28:34 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter
- Files:
-
- 9 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/ExpressionTest.cs
r14908 r15017 1 1 namespace HeuristicLab.Tests.Interpreter { 2 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 3 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 2 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Boolean; 3 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Float; 4 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.FloatVector; 5 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.IntegerVector; 6 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.StringVector; 4 7 5 8 using Microsoft.VisualStudio.TestTools.UnitTesting; 9 using Problems.ProgramSynthesis.Base.Erc; 10 using Problems.ProgramSynthesis.Base.Erc.Char; 11 using Problems.ProgramSynthesis.Base.Erc.Integer; 12 using Problems.ProgramSynthesis.Base.Erc.String; 13 using Problems.ProgramSynthesis.Push.Configuration; 14 using Problems.ProgramSynthesis.Push.Interpreter; 6 15 7 16 public class ExpressionTest { 8 17 protected PushInterpreter interpreter; 9 18 10 protected PushConfiguration configuration = new PushConfiguration { TopLevelPushCode = false }; 19 protected PushConfiguration configuration = new PushConfiguration { 20 TopLevelPushCode = false, 21 ErcOptions = new ErcOptions { 22 ErcProbability = 0.05, 23 CharErcOptions = new CharErcOptions(new IntegerRangeErc(0x20, 0x7e)), 24 StringErcOptions = new StringErcOptions(new StringRandomErc { 25 IsEnabled = true, 26 AllowDigits = true, 27 NewStringProbability = 1, 28 AllowLowercaseLetters = true, 29 AllowUppercaseLetters = true 30 }), 31 IntegerErcOptions = new IntegerErcOptions(new IntegerRangeErc(-10000, 10000)), 32 FloatErcOptions = new FloatErcOptions(new FloatRangeErc(-10000, 10000)), 33 BooleanErcOptions = new BooleanErcOptions(new BooleanRandomErc(true, true, true)), 34 StringVectorErcOptions = new StringVectorErcOptions( 35 new StringVectorConstantsErc(new[] { "test", "123", "asdf", "a", "b" })), 36 IntegerVectorErcOptions = new IntegerVectorErcOptions( 37 new IntegerVectorConstantsErc(new[] { 0, -5, 10, 8, -3 })), 38 FloatVectorErcOptions = new FloatVectorErcOptions( 39 new FloatVectorConstantsErc(new[] { 0.0, -5.2, 10.3, 8.1, -3.4 })) 40 } 41 }; 11 42 12 43 [TestInitialize] 13 44 public void BeforeTest() { 14 interpreter = new PushInterpreter( configuration);45 interpreter = new PushInterpreter(1337, configuration); 15 46 } 16 47 … … 21 52 int? booleanStack = 0, 22 53 int? floatStack = 0, 23 int? integerStack = 0) { 54 int? integerStack = 0, 55 int? charStack = 0, 56 int? stringStack = 0, 57 int? integerVectorStack = 0, 58 int? floatVectorStack = 0, 59 int? booleanVectorStack = 0, 60 int? stringVectorStack = 0) { 24 61 if (execStack.HasValue) Assert.AreEqual(execStack, interpreter.ExecStack.Count); 25 26 62 if (codeStack.HasValue) Assert.AreEqual(codeStack, interpreter.CodeStack.Count); 27 28 63 if (nameStack.HasValue) Assert.AreEqual(nameStack, interpreter.NameStack.Count); 29 30 64 if (booleanStack.HasValue) Assert.AreEqual(booleanStack, interpreter.BooleanStack.Count); 31 32 65 if (floatStack.HasValue) Assert.AreEqual(floatStack, interpreter.FloatStack.Count); 33 34 66 if (integerStack.HasValue) Assert.AreEqual(integerStack, interpreter.IntegerStack.Count); 67 if (charStack.HasValue) Assert.AreEqual(charStack, interpreter.CharStack.Count); 68 if (stringStack.HasValue) Assert.AreEqual(stringStack, interpreter.StringStack.Count); 69 if (integerVectorStack.HasValue) Assert.AreEqual(integerVectorStack, interpreter.IntegerVectorStack.Count); 70 if (floatVectorStack.HasValue) Assert.AreEqual(floatVectorStack, interpreter.FloatVectorStack.Count); 71 if (booleanVectorStack.HasValue) Assert.AreEqual(booleanVectorStack, interpreter.BooleanVectorStack.Count); 72 if (stringVectorStack.HasValue) Assert.AreEqual(stringVectorStack, interpreter.StringVectorStack.Count); 35 73 } 36 74 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CodeExpressionTests.cs
r14908 r15017 430 430 431 431 Assert.AreEqual(3, interpreter.IntegerStack.Top); 432 TestStackCounts( codeStack: 1, integerStack: 2);432 TestStackCounts(integerStack: 1); 433 433 } 434 434 … … 455 455 var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )"); 456 456 457 interpreter.IntegerStack.Push(2, 3);457 interpreter.IntegerStack.Push(2, 4); 458 458 interpreter.CodeStack.Push(prog); 459 459 interpreter.Run(new CodeDoTimesExpression()); … … 508 508 public void TestNestedDoTimes() { 509 509 interpreter.Run( 510 "( 3 CODE.QUOTE ( 2 3CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )");510 "( 4 CODE.QUOTE ( 2 4 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )"); 511 511 512 512 Assert.AreEqual(128, interpreter.IntegerStack.Top); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CommonTests.cs
r14908 r15017 35 35 36 36 var isBooleanStack = interpreter.BooleanStack.Count == 2; 37 38 37 Test(ExpressionTable.GetStatelessExpression(TypeName + ".=")); 39 38 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/ExampleTests.cs
r14908 r15017 145 145 public void Example10() { 146 146 interpreter.IntegerStack.Push(5); 147 interpreter.Run("( 1 INTEGER.MAX 1 EXEC.DO*RANGE ( 2 INTEGER.* ) )");148 149 Assert.AreEqual( 2, interpreter.IntegerStack.Top);147 interpreter.Run("( 1 INTEGER.MAX 1 EXEC.DO*RANGE ( 2 INTEGER.* INTEGER.* ) )"); 148 149 Assert.AreEqual(3840, interpreter.IntegerStack.Top); 150 150 Assert.IsTrue(interpreter.CodeStack.IsEmpty); 151 151 Assert.IsTrue(interpreter.ExecStack.IsEmpty); … … 254 254 interpreter.FloatStack.Push(2); 255 255 interpreter.Run(@"( ARG FLOAT.DEFINE 256 257 258 259 260 261 262 256 EXEC.Y ( 257 ARG FLOAT.* 258 1 INTEGER.- 259 INTEGER.DUP 1 INTEGER.> 260 EXEC.IF ( ) EXEC.POP 261 ) 262 )"); 263 263 264 264 Assert.AreEqual(1024, interpreter.FloatStack.Top, Delta); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/ExecExpressionTests.cs
r14908 r15017 111 111 public void TestNestedDoRange() { 112 112 interpreter.Run( 113 "( 0 2 EXEC.DO*RANGE ( 1 INTEGER.+ 0 3 EXEC.DO*RANGE ( 1 INTEGER.+ INTEGER.* ) INTEGER.+)");113 "( 1 0 2 EXEC.DO*RANGE ( INTEGER.POP 1 1 4 EXEC.DO*RANGE INTEGER.* INTEGER.* ) )"); 114 114 115 Assert.AreEqual(1 44, interpreter.IntegerStack.Top);115 Assert.AreEqual(13824, interpreter.IntegerStack.Top); 116 116 TestStackCounts(integerStack: 1); 117 117 } … … 134 134 [TestCategory("ExecExpressionTest")] 135 135 public void TestNestedDoTimes() { 136 interpreter.Run("( 3 EXEC.DO*TIMES ( 2 3EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )");136 interpreter.Run("( 4 EXEC.DO*TIMES ( 2 4 EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )"); 137 137 138 138 Assert.AreEqual(128, interpreter.IntegerStack.Top); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/IntegerExpressionTests.cs
r14908 r15017 32 32 33 33 Assert.AreEqual(10, interpreter.IntegerStack.Top); 34 35 34 TestStackCounts(integerStack: 1); 36 35 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/StandardTests.cs
r14746 r15017 13 13 public class StandardTests { 14 14 [TestMethod] 15 [TestProperty("Time", "Short")] 16 [TestCategory("ExpressionTest")] 17 [TestCategory("StandartTests")] 15 18 public void TestGetHashCode() { 16 19 var expressionTypes = from domainAssembly in AppDomain.CurrentDomain.GetAssemblies() … … 22 25 23 26 var expressions = expressionTypes.Select(et => Activator.CreateInstance(et) as Expression); 24 var ids = expressions.Select(e => new { E pxression = e, Id = e.GetHashCode() });27 var ids = expressions.Select(e => new { Expression = e, Id = e.GetHashCode() }); 25 28 26 var duplicate s = ids.GroupBy(s => s).SelectMany(grp => grp.Skip(1));29 var duplicateGroups = ids.GroupBy(s => s.Id).Where(grp => grp.Count() > 2).ToList(); 27 30 28 if (!duplicate s.Any())31 if (!duplicateGroups.Any()) 29 32 return; 30 33 31 34 Debug.WriteLine("Duplicates: "); 32 foreach (var duplicate in duplicates) 33 Debug.WriteLine("Id: {0}, Expression: {1}", duplicate.Id, duplicate.Epxression); 35 foreach (var group in duplicateGroups) { 36 foreach (var duplicate in group) { 37 string name; 38 if (!ExpressionTable.TypeToNameTable.TryGetValue(duplicate.Expression.GetType(), out name)) { 39 name = duplicate.Expression.ToString(); 40 } 41 42 Debug.WriteLine("Id: {0}, Expression: {1}", duplicate.Id, name); 43 } 44 45 Debug.WriteLine(""); 46 } 34 47 35 48 Assert.Fail(); … … 37 50 38 51 [TestMethod] 52 [TestProperty("Time", "Short")] 53 [TestCategory("ExpressionTest")] 54 [TestCategory("StandartTests")] 39 55 public void TestExpandGetHashCode() { 40 56 var expand = PushParser.Parse("( A B C D E F )"); … … 44 60 45 61 [TestMethod] 62 [TestProperty("Time", "Short")] 63 [TestCategory("ExpressionTest")] 64 [TestCategory("StandartTests")] 46 65 public void TestExecExpandCopy() { 47 66 var expressions = new Expression[] … … 59 78 60 79 [TestMethod] 80 [TestProperty("Time", "Short")] 81 [TestCategory("ExpressionTest")] 82 [TestCategory("StandartTests")] 61 83 public void TestExecExpandRecursiveCopy() { 62 84 var expressions = new List<Expression> … … 83 105 84 106 [TestMethod] 107 [TestProperty("Time", "Short")] 108 [TestCategory("ExpressionTest")] 109 [TestCategory("StandartTests")] 85 110 public void TestExecExpandRecursiveGetHashCode() { 86 111 var expressions = new List<Expression>
Note: See TracChangeset
for help on using the changeset viewer.