Changeset 14353 for trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4
- Timestamp:
- 10/23/16 19:31:18 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/GrammarsTest.cs
r14352 r14353 87 87 Assert.AreEqual(2, grammar.GetMinimumExpressionLength(y)); 88 88 } 89 90 { 91 var grammar = CreateTestGrammar6(); 92 var prs = grammar.ProgramRootSymbol; 93 var ss = grammar.StartSymbol; 94 var x = grammar.Symbols.First(s => s.Name == "<x>"); 95 var s_ = grammar.Symbols.First(s => s.Name == "<s>"); 96 var a = grammar.Symbols.First(s => s.Name == "<a>"); 97 var b = grammar.Symbols.First(s => s.Name == "<b>"); 98 var c = grammar.Symbols.First(s => s.Name == "<c>"); 99 var d = grammar.Symbols.First(s => s.Name == "<d>"); 100 Assert.AreEqual(4, grammar.GetMinimumExpressionLength(prs)); 101 Assert.AreEqual(3, grammar.GetMinimumExpressionLength(ss)); 102 Assert.AreEqual(2, grammar.GetMinimumExpressionLength(x)); 103 Assert.AreEqual(5, grammar.GetMinimumExpressionLength(s_)); 104 Assert.AreEqual(4, grammar.GetMinimumExpressionLength(a)); 105 Assert.AreEqual(3, grammar.GetMinimumExpressionLength(b)); 106 Assert.AreEqual(4, grammar.GetMinimumExpressionLength(c)); 107 Assert.AreEqual(3, grammar.GetMinimumExpressionLength(d)); 108 } 89 109 } 90 110 … … 170 190 Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(y)); 171 191 } 192 193 { 194 var grammar = CreateTestGrammar6(); 195 var prs = grammar.ProgramRootSymbol; 196 var ss = grammar.StartSymbol; 197 var x = grammar.Symbols.First(s => s.Name == "<x>"); 198 var s_ = grammar.Symbols.First(s => s.Name == "<s>"); 199 var a = grammar.Symbols.First(s => s.Name == "<a>"); 200 var b = grammar.Symbols.First(s => s.Name == "<b>"); 201 var c = grammar.Symbols.First(s => s.Name == "<c>"); 202 var d = grammar.Symbols.First(s => s.Name == "<d>"); 203 Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(prs)); 204 Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(ss)); 205 Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(x)); 206 Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(s_)); 207 Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(a)); 208 Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(b)); 209 Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(c)); 210 Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(d)); 211 } 172 212 } 173 213 … … 286 326 return grammar; 287 327 } 328 329 private static ISymbolicExpressionGrammar CreateTestGrammar6() { 330 var grammar = new SimpleSymbolicExpressionGrammar(); 331 var x = new SimpleSymbol("<x>", 1); 332 var s = new SimpleSymbol("<s>", 1); 333 var a = new SimpleSymbol("<a>", 1); 334 var b = new SimpleSymbol("<b>", 1); 335 var c = new SimpleSymbol("<c>", 1); 336 var d = new SimpleSymbol("<d>", 1); 337 var e = new SimpleSymbol("<e>", 1); 338 339 var _x = new SimpleSymbol("x", 0); 340 var _y = new SimpleSymbol("y", 0); 341 342 grammar.AddSymbol(x); 343 grammar.AddSymbol(s); 344 grammar.AddSymbol(a); 345 grammar.AddSymbol(b); 346 grammar.AddSymbol(c); 347 grammar.AddSymbol(d); 348 grammar.AddSymbol(e); 349 grammar.AddSymbol(_x); 350 grammar.AddSymbol(_y); 351 352 grammar.AddAllowedChildSymbol(grammar.StartSymbol, x); 353 grammar.AddAllowedChildSymbol(x, s); 354 grammar.AddAllowedChildSymbol(x, _x); 355 grammar.AddAllowedChildSymbol(s, a); 356 grammar.AddAllowedChildSymbol(a, b); 357 grammar.AddAllowedChildSymbol(a, c); 358 grammar.AddAllowedChildSymbol(b, x); 359 grammar.AddAllowedChildSymbol(c, d); 360 grammar.AddAllowedChildSymbol(d, e); 361 grammar.AddAllowedChildSymbol(e, _y); 362 363 return grammar; 364 } 288 365 } 289 366 }
Note: See TracChangeset
for help on using the changeset viewer.