Changeset 5549 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentCreaterTest.cs
- Timestamp:
- 02/22/11 19:04:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ArgumentCreaterTest.cs
r5445 r5549 24 24 using System.Collections.Generic; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;28 26 using HeuristicLab.Random; 29 27 using Microsoft.VisualStudio.TestTools.UnitTesting; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;31 28 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._ 3.Tests {29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests { 33 30 [TestClass] 34 31 public class ArgumentCreaterTest { 35 32 private const int POPULATION_SIZE = 1000; 36 private const int MAX_TREE_ SIZE= 100;37 private const int MAX_TREE_ HEIGHT= 10;33 private const int MAX_TREE_LENGTH = 100; 34 private const int MAX_TREE_DEPTH = 10; 38 35 private TestContext testContextInstance; 39 36 … … 53 50 [TestMethod()] 54 51 public void ArgumentCreaterDistributionsTest() { 55 var trees = new List< SymbolicExpressionTree>();52 var trees = new List<ISymbolicExpressionTree>(); 56 53 var grammar = Grammars.CreateArithmeticAndAdfGrammar(); 57 54 var random = new MersenneTwister(31415); 58 55 int failedOps = 0; 59 56 for (int i = 0; i < POPULATION_SIZE; i++) { 60 SymbolicExpressionTree tree;57 ISymbolicExpressionTree tree; 61 58 do { 62 tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_ SIZE, MAX_TREE_HEIGHT, 3, 3);59 tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3); 63 60 } while (!TreeHasAdfWithParameter(tree, 3)); 64 var success = ArgumentCreater.CreateNewArgument(random, tree, grammar,60000, 100, 3, 3);61 var success = ArgumentCreater.CreateNewArgument(random, tree, 60000, 100, 3, 3); 65 62 if (!success) failedOps++; 66 63 Util.IsValid(tree); … … 79 76 } 80 77 81 private bool TreeHasAdfWithParameter(SymbolicExpressionTree tree, int maxParameters) { 82 return tree.Root.SubTrees.Count == 2 && 83 tree.Root.SubTrees[1].GetAllowedSymbols(0).Where(x => x is Argument).Count() < maxParameters; 78 private bool TreeHasAdfWithParameter(ISymbolicExpressionTree tree, int maxParameters) { 79 if(tree.Root.SubTrees.Count() != 2 ) return false; 80 var firstAdf = tree.Root.GetSubTree(1); 81 return firstAdf.Grammar.GetAllowedSymbols(firstAdf.Symbol, 0).Where(x => x is Argument).Count() < maxParameters; 84 82 } 85 83 }
Note: See TracChangeset
for help on using the changeset viewer.