- Timestamp:
- 07/26/10 16:18:45 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Grammars.cs
r4068 r4106 26 26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { 27 27 public static class Grammars { 28 private class Addition : Symbol { }29 private class Subtraction : Symbol { }30 private class Multiplication : Symbol { }31 private class Division : Symbol { }32 private class Terminal : Symbol { }28 private class Addition : Symbol { public Addition() : base("Addition", "") { } } 29 private class Subtraction : Symbol { public Subtraction() : base("Subtraction", "") { } } 30 private class Multiplication : Symbol { public Multiplication() : base("Multiplication", "") { } } 31 private class Division : Symbol { public Division() : base("Division", "") { } } 32 private class Terminal : Symbol { public Terminal() : base("Terminal", "") { } } 33 33 34 34 private class SimpleArithmeticGrammar : DefaultSymbolicExpressionGrammar { … … 89 89 return g; 90 90 } 91 92 public static void HasValidAdfGrammars(SymbolicExpressionTree tree) {93 //Assert.AreEqual(tree.Root.Grammar.Symbols.Count(), 8);94 //Assert.AreEqual(tree.Root.GetAllowedSymbols(0).Count(), 1); // only the start symbol is allowed95 //// we allow 3 ADF branches96 //Assert.AreEqual(tree.Root.GetAllowedSymbols(1).Count(), 1); // only the defun branch is allowed97 //Assert.AreEqual(tree.Root.GetAllowedSymbols(2).Count(), 1); // only the defun symbol is allowed98 //Assert.AreEqual(tree.Root.GetAllowedSymbols(3).Count(), 1); // only the defun symbol is allowed99 //foreach (var subtree in tree.Root.SubTrees) {100 // // check consistency of each sub-tree grammar independently101 // var allowedSymbols = subtree.GetAllowedSymbols(0);102 // int numberOfAllowedSymbols = allowedSymbols.Count();103 // foreach (var parent in allowedSymbols) {104 // for (int argIndex = 0; argIndex < subtree.Grammar.GetMaxSubtreeCount(parent); argIndex++) {105 // var allowedChildren = from child in subtree.Grammar.Symbols106 // where subtree.Grammar.IsAllowedChild(parent, child, argIndex)107 // select child;108 // Assert.AreEqual(numberOfAllowedSymbols, allowedChildren.Count());109 // }110 // }111 //}112 }113 114 91 } 115 92 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ProbabilisticTreeCreaterTest.cs
r4068 r4106 76 76 for (int i = 0; i < POPULATION_SIZE; i++) { 77 77 var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3); 78 Grammars.HasValidAdfGrammars(tree);79 78 Util.IsValid(tree); 80 79 randomTrees.Add(tree); -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Util.cs
r4068 r4106 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using Microsoft.VisualStudio.TestTools.UnitTesting; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 29 29 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { … … 114 115 115 116 public static void IsValid(SymbolicExpressionTree tree) { 116 Grammars.HasValidAdfGrammars(tree); 117 foreach (var defunTreeNode in tree.Root.SubTrees.OfType<DefunTreeNode>()) { 118 int arity = defunTreeNode.NumberOfArguments; 119 var invoke = new InvokeFunction(defunTreeNode.FunctionName); 120 foreach (var otherRootNode in tree.Root.SubTrees) { 121 if (otherRootNode.Grammar.ContainsSymbol(invoke)) { 122 Assert.IsTrue(otherRootNode.Grammar.GetMinSubtreeCount(invoke) == arity); 123 Assert.IsTrue(otherRootNode.Grammar.GetMaxSubtreeCount(invoke) == arity); 124 } 125 } 126 } 117 127 //Assert.AreEqual(tree.Root.Symbol, tree.Root.Grammar.StartSymbol); 118 128 //foreach (var subtree in tree.Root.SubTrees) … … 122 132 123 133 public static void IsValid(SymbolicExpressionTreeNode treeNode) { 124 //var matchingSymbol = (from symb in treeNode.Grammar.Symbols125 //where symb.Name == treeNode.Symbol.Name126 //select symb).SingleOrDefault();127 //Assert.IsTrue(treeNode.SubTrees.Count >= treeNode.Grammar.GetMinSubtreeCount(matchingSymbol));128 //Assert.IsTrue(treeNode.SubTrees.Count <= treeNode.Grammar.GetMaxSubtreeCount(matchingSymbol));134 var matchingSymbol = (from symb in treeNode.Grammar.Symbols 135 where symb.Name == treeNode.Symbol.Name 136 select symb).SingleOrDefault(); 137 Assert.IsTrue(treeNode.SubTrees.Count >= treeNode.Grammar.GetMinSubtreeCount(matchingSymbol)); 138 Assert.IsTrue(treeNode.SubTrees.Count <= treeNode.Grammar.GetMaxSubtreeCount(matchingSymbol)); 129 139 for (int i = 0; i < treeNode.SubTrees.Count; i++) { 130 140 Assert.IsTrue(treeNode.GetAllowedSymbols(i).Select(x => x.Name).Contains(treeNode.SubTrees[i].Symbol.Name));
Note: See TracChangeset
for help on using the changeset viewer.