Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubtreeCrossoverTest.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubtreeCrossoverTest.cs	(revision 3297)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubtreeCrossoverTest.cs	(revision 3338)
@@ -11,6 +11,7 @@
   [TestClass]
   public class SubtreeCrossoverTest {
-    public SubtreeCrossoverTest() {
-    }
+    private static ISymbolicExpressionGrammar grammar;
+    private static List<SymbolicExpressionTree> crossoverTrees;
+    private static double msPerCrossoverEvent;
 
     private TestContext testContextInstance;
@@ -34,8 +35,9 @@
       int populationSize = 1000;
       int generations = 5;
-      var grammar = new TestGrammar();
+      int failedEvents = 0;
+      grammar = Grammars.CreateArithmeticAndAdfGrammar();
       var random = new MersenneTwister();
       for (int i = 0; i < populationSize; i++) {
-        crossoverTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, 100, 10));
+        crossoverTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, 100, 10, 3, 3));
       }
       Stopwatch stopwatch = new Stopwatch();
@@ -47,5 +49,6 @@
           var par1 = (SymbolicExpressionTree)crossoverTrees[random.Next(populationSize)].Clone();
           bool success;
-          newPopulation.Add(SubtreeCrossover.Cross(random, grammar, par0, par1, 0.9, 100, 10, out success));
+          newPopulation.Add(SubtreeCrossover.Cross(random, par0, par1, 0.9, 100, 10, out success));
+          if (!success) failedEvents++;
         }
         crossoverTrees = newPopulation;
@@ -53,53 +56,13 @@
       stopwatch.Stop();
       foreach (var tree in crossoverTrees)
-        Assert.IsTrue(grammar.IsValidExpression(tree));
-      msPerCrossoverEvent = stopwatch.ElapsedMilliseconds / (double)populationSize / (double)generations;
+        Assert.IsTrue(tree.IsValidExpression());
+      msPerCrossoverEvent = stopwatch.ElapsedMilliseconds / (double)populationSize / (double)generations;      
     }
 
 
 
-    private static List<SymbolicExpressionTree> crossoverTrees;
-    private static double msPerCrossoverEvent;
-
-    private class Addition : Symbol { }
-    private class Subtraction : Symbol { }
-    private class Multiplication : Symbol { }
-    private class Division : Symbol { }
-    private class Terminal : Symbol { }
-
-    private class TestGrammar : DefaultSymbolicExpressionGrammar {
-      public TestGrammar()
-        : base(0, 0, 0, 0) {
-        Initialize();
-      }
-
-      private void Initialize() {
-        var add = new Addition();
-        var sub = new Subtraction();
-        var mul = new Multiplication();
-        var div = new Division();
-        var terminal = new Terminal();
-
-        var allSymbols = new List<Symbol>() { add, sub, mul, div, terminal };
-        var functionSymbols = new List<Symbol>() { add, sub, mul, div };
-        allSymbols.ForEach(s => AddAllowedSymbols(StartSymbol, 0, s));
-
-        SetMinSubTreeCount(terminal, 0);
-        SetMaxSubTreeCount(terminal, 0);
-        int maxSubTrees = 3;
-        foreach (var functionSymbol in functionSymbols) {
-          SetMinSubTreeCount(functionSymbol, 1);
-          SetMaxSubTreeCount(functionSymbol, maxSubTrees);
-          foreach (var childSymbol in allSymbols) {
-            for (int argumentIndex = 0; argumentIndex < maxSubTrees; argumentIndex++) {
-              AddAllowedSymbols(functionSymbol, argumentIndex, childSymbol);
-            }
-          }
-        }
-      }
-    }
-
     [TestMethod()]
     public void SubtreeCrossoverSpeed() {
+
       Assert.Inconclusive(msPerCrossoverEvent + " ms per crossover event (~" +
         Math.Round(1000.0 / (msPerCrossoverEvent)) + "crossovers / s)");
@@ -107,60 +70,16 @@
 
     [TestMethod()]
-    public void SubtreeCrossoverSizeDistributionTest() {
-      int[] histogram = new int[105 / 5];
-      for (int i = 0; i < crossoverTrees.Count; i++) {
-        histogram[crossoverTrees[i].Size / 5]++;
-      }
-      StringBuilder strBuilder = new StringBuilder();
-      for (int i = 0; i < histogram.Length; i++) {
-        strBuilder.Append(Environment.NewLine);
-        strBuilder.Append("< "); strBuilder.Append((i + 1) * 5);
-        strBuilder.Append(": "); strBuilder.AppendFormat("{0:#0.00%}", histogram[i] / (double)crossoverTrees.Count);
-      }
-      Assert.Inconclusive("Size distribution of SubtreeCrossover: " + strBuilder);
+    public void SubtreeCrossoverSizeDistributions() {
+      Assert.Inconclusive("SubtreeCrossover: " + Util.GetSizeDistributionString(crossoverTrees, 105, 5));
     }
 
     [TestMethod()]
     public void SubtreeCrossoverFunctionDistributionTest() {
-      Dictionary<Symbol, int> occurances = new Dictionary<Symbol, int>();
-      double n = 0.0;
-      for (int i = 0; i < crossoverTrees.Count; i++) {
-        foreach (var node in crossoverTrees[i].IterateNodesPrefix()) {
-          if (node.SubTrees.Count > 0) {
-            if (!occurances.ContainsKey(node.Symbol))
-              occurances[node.Symbol] = 0;
-            occurances[node.Symbol]++;
-            n++;
-          }
-        }
-      }
-      StringBuilder strBuilder = new StringBuilder();
-      foreach (var function in occurances.Keys) {
-        strBuilder.Append(Environment.NewLine);
-        strBuilder.Append(function.Name); strBuilder.Append(": ");
-        strBuilder.AppendFormat("{0:#0.00%}", occurances[function] / n);
-      }
-      Assert.Inconclusive("Function distribution of SubtreeCrossover: " + strBuilder);
+      Assert.Inconclusive("SubtreeCrossover: " + Util.GetFunctionDistributionString(crossoverTrees));
     }
 
     [TestMethod()]
     public void SubtreeCrossoverNumberOfSubTreesDistributionTest() {
-      Dictionary<int, int> occurances = new Dictionary<int, int>();
-      double n = 0.0;
-      for (int i = 0; i < crossoverTrees.Count; i++) {
-        foreach (var node in crossoverTrees[i].IterateNodesPrefix()) {
-          if (!occurances.ContainsKey(node.SubTrees.Count))
-            occurances[node.SubTrees.Count] = 0;
-          occurances[node.SubTrees.Count]++;
-          n++;
-        }
-      }
-      StringBuilder strBuilder = new StringBuilder();
-      foreach (var arity in occurances.Keys) {
-        strBuilder.Append(Environment.NewLine);
-        strBuilder.Append(arity); strBuilder.Append(": ");
-        strBuilder.AppendFormat("{0:#0.00%}", occurances[arity] / n);
-      }
-      Assert.Inconclusive("Distribution of function arities of SubtreeCrossover: " + strBuilder);
+      Assert.Inconclusive("SubtreeCrossover: " + Util.GetNumberOfSubTreesDistributionString(crossoverTrees));
     }
 
@@ -168,23 +87,5 @@
     [TestMethod()]
     public void SubtreeCrossoverTerminalDistributionTest() {
-      Dictionary<Symbol, int> occurances = new Dictionary<Symbol, int>();
-      double n = 0.0;
-      for (int i = 0; i < crossoverTrees.Count; i++) {
-        foreach (var node in crossoverTrees[i].IterateNodesPrefix()) {
-          if (node.SubTrees.Count == 0) {
-            if (!occurances.ContainsKey(node.Symbol))
-              occurances[node.Symbol] = 0;
-            occurances[node.Symbol]++;
-            n++;
-          }
-        }
-      }
-      StringBuilder strBuilder = new StringBuilder();
-      foreach (var function in occurances.Keys) {
-        strBuilder.Append(Environment.NewLine);
-        strBuilder.Append(function.Name); strBuilder.Append(": ");
-        strBuilder.AppendFormat("{0:#0.00%}", occurances[function] / n);
-      }
-      Assert.Inconclusive("Terminal distribution of SubtreeCrossover: " + strBuilder);
+      Assert.Inconclusive("SubtreeCrossover: " + Util.GetTerminalDistributionString(crossoverTrees));
     }
   }
