Changeset 10051 for branches/HeuristicLab.Problems.GPDL/Test
- Timestamp:
- 10/17/13 15:19:45 (11 years ago)
- Location:
- branches/HeuristicLab.Problems.GPDL/Test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/Test/Test.csproj
r10031 r10051 22 22 <DebugType>full</DebugType> 23 23 <Optimize>false</Optimize> 24 <OutputPath>..\ trunk\sources\bin\</OutputPath>24 <OutputPath>..\..\..\trunk\sources\bin\</OutputPath> 25 25 <DefineConstants>DEBUG;TRACE</DefineConstants> 26 26 <ErrorReport>prompt</ErrorReport> … … 128 128 <Name>HeuristicLab.Grammars-3.3</Name> 129 129 </ProjectReference> 130 <ProjectReference Include="..\HeuristicLab.Problems.GPDL.CodeGen\3.4\HeuristicLab.Problems.GPDL.CodeGen-3.4.csproj"> 131 <Project>{F8481248-2A5B-48A0-A485-D3E1619C1E44}</Project> 132 <Name>HeuristicLab.Problems.GPDL.CodeGen-3.4</Name> 133 </ProjectReference> 130 134 <ProjectReference Include="..\HeuristicLab.Problems.GPDL.Views\3.4\HeuristicLab.Problems.GPDL.Views-3.4.csproj"> 131 135 <Project>{3f9e665a-3dcb-49c3-8806-0e47fc48ea52}</Project> -
branches/HeuristicLab.Problems.GPDL/Test/TestGpdlExamples.cs
r9846 r10051 27 27 using HeuristicLab.Algorithms.GeneticAlgorithm; 28 28 using HeuristicLab.Problems.GPDL; 29 using HeuristicLab.Problems.GPDL.CodeGen; 29 30 using HeuristicLab.Problems.GPDL.Views; 30 31 using HeuristicLab.SequentialEngine; … … 41 42 Parser parser = new Parser(scanner); 42 43 parser.Parse(); 43 Assert.IsNotNull(parser. problem);44 Assert.IsNotNull(parser.AbstractSyntaxTree); 44 45 45 46 // test: run one generation … … 48 49 ga.PopulationSize.Value = 100; 49 50 ga.MaximumGenerations.Value = 1; 50 ga.Problem = parser.problem; 51 52 var problemGenerator = new ProblemGenerator(); 53 ga.Problem = problemGenerator.GenerateFromAst(parser.AbstractSyntaxTree); 51 54 52 55 var wh = new AutoResetEvent(false); -
branches/HeuristicLab.Problems.GPDL/Test/TestGrammar.cs
r10031 r10051 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 23 25 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 31 33 @"S -> A 32 34 A->a B 33 B ->S b | S a| Bb34 B-> a aa aaa35 B ->S b | S a|C b 36 C-> a aa aaa 35 37 "; 36 38 var g = HeuristicLab.Grammars.Grammar.FromString(gStr); 37 Assert.AreEqual(g.StartSymbol, "S");39 Assert.AreEqual(g.StartSymbol, new Symbol("S")); 38 40 Assert.AreEqual(g.TerminalSymbols.Count(), 4); 39 Assert.AreEqual(g.NonTerminalSymbols.Count(), 3); 40 Assert.IsTrue(g.TerminalSymbols.Contains("aaa")); 41 Assert.IsTrue(g.TerminalSymbols.Contains("aa")); 42 Assert.IsTrue(g.NonTerminalSymbols.Contains("S")); 43 Assert.IsTrue(g.NonTerminalSymbols.Contains("B")); 44 Assert.IsTrue(g.NonTerminalSymbols.Contains("A")); 41 Assert.AreEqual(g.NonTerminalSymbols.Count(), 4); 42 Assert.IsTrue(g.TerminalSymbols.Contains(new Symbol("aaa"))); 43 Assert.IsTrue(g.TerminalSymbols.Contains(new Symbol("aa"))); 44 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("S"))); 45 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("B"))); 46 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("C"))); 47 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("A"))); 48 } 49 50 51 [TestMethod] 52 public void TestAttributedGrammar() { 53 var gStr = 54 @"S -> A 55 A<int a0, out int a1>->a B<a0, a1> 56 B<int a0, ref int a1> ->S b | S a|C<a0, a1> b 57 C<int a0, ref int a1> -> a aa aaa 58 "; 59 var g = HeuristicLab.Grammars.AttributedGrammar.FromString(gStr); 60 Assert.AreEqual(g.StartSymbol, new Symbol("S")); 61 Assert.AreEqual(g.TerminalSymbols.Count(), 4); 62 Assert.AreEqual(g.NonTerminalSymbols.Count(), 4); 63 Assert.IsTrue(g.TerminalSymbols.Contains(new Symbol("aaa"))); 64 Assert.IsTrue(g.TerminalSymbols.Contains(new Symbol("aa"))); 65 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("S"))); 66 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("B"))); 67 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("A"))); 68 Assert.IsTrue(g.NonTerminalSymbols.Contains(new Symbol("C"))); 69 } 70 71 72 [TestMethod] 73 public void TestLanguage() { 74 var gStr = 75 @"S -> a B | b A 76 A-> a | a S | b A A 77 B -> b | b S | a B B 78 "; 79 var g = HeuristicLab.Grammars.Grammar.FromString(gStr); 80 var l = new Language(g); 81 var s2 = new string[][] 82 { 83 new string[] {"a", "b"}, 84 new string[] {"b", "a"} 85 }; 86 var s4 = new string[][] 87 { 88 new [] {"a", "a", "b", "b"}, 89 new [] {"a", "b", "a", "b"}, 90 new [] {"a", "b", "b", "a"}, 91 new [] {"b", "b", "a", "a"}, 92 new [] {"b", "a", "b", "a"}, 93 new [] {"b", "a", "a", "b"} 94 }; 95 96 97 var l2 = l.Where(s => s.Count() == 2).Take(2); 98 var l4 = l.Where(s => s.Count() == 4).Take(6); 99 100 Assert.IsTrue(l2.Intersect(s2, new SequenceComparer()).Count() == l2.Count()); 101 Assert.IsTrue(l4.Intersect(s4, new SequenceComparer()).Count() == l4.Count()); 102 } 103 } 104 105 public class SequenceComparer : IEqualityComparer<IEnumerable<string>> { 106 public bool Equals(IEnumerable<string> x, IEnumerable<string> y) { 107 return x.Count() == y.Count() && 108 x.Zip(y, (s, t) => s == t).All(eq => eq); 109 } 110 111 public int GetHashCode(IEnumerable<string> obj) { 112 if (!obj.Any()) return 0; 113 else return obj.First().GetHashCode(); 45 114 } 46 115 }
Note: See TracChangeset
for help on using the changeset viewer.