1 | using System;
|
---|
2 | using System.Text;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
7 | using HeuristicLab.Random;
|
---|
8 | using System.Diagnostics;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
|
---|
11 | [TestClass]
|
---|
12 | public class ProbabilisticTreeCreaterTest {
|
---|
13 | private const int POPULATION_SIZE = 1000;
|
---|
14 | private const int MAX_TREE_SIZE = 100;
|
---|
15 | private const int MAX_TREE_HEIGHT = 10;
|
---|
16 | private TestContext testContextInstance;
|
---|
17 |
|
---|
18 | /// <summary>
|
---|
19 | ///Gets or sets the test context which provides
|
---|
20 | ///information about and functionality for the current test run.
|
---|
21 | ///</summary>
|
---|
22 | public TestContext TestContext {
|
---|
23 | get {
|
---|
24 | return testContextInstance;
|
---|
25 | }
|
---|
26 | set {
|
---|
27 | testContextInstance = value;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | [TestMethod()]
|
---|
32 | public void ProbabilisticTreeCreaterDistributionsTest() {
|
---|
33 | var randomTrees = new List<SymbolicExpressionTree>();
|
---|
34 | var grammar = Grammars.CreateSimpleArithmeticGrammar();
|
---|
35 | var random = new MersenneTwister();
|
---|
36 | for (int i = 0; i < POPULATION_SIZE; i++) {
|
---|
37 | randomTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 0, 0));
|
---|
38 | }
|
---|
39 |
|
---|
40 | foreach (var tree in randomTrees)
|
---|
41 | Assert.IsTrue(tree.IsValidExpression());
|
---|
42 | Assert.Inconclusive("ProbabilisticTreeCreator: " + Environment.NewLine +
|
---|
43 | Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
|
---|
44 | Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
|
---|
45 | Util.GetNumberOfSubTreesDistributionString(randomTrees) + Environment.NewLine +
|
---|
46 | Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
|
---|
47 | );
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | [TestMethod()]
|
---|
52 | public void ProbabilisticTreeCreaterWithAdfDistributionsTest() {
|
---|
53 | var randomTrees = new List<SymbolicExpressionTree>();
|
---|
54 | var grammar = Grammars.CreateArithmeticAndAdfGrammar();
|
---|
55 | var random = new MersenneTwister();
|
---|
56 | for (int i = 0; i < POPULATION_SIZE; i++) {
|
---|
57 | randomTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3));
|
---|
58 | }
|
---|
59 | foreach (var tree in randomTrees)
|
---|
60 | Assert.IsTrue(tree.IsValidExpression());
|
---|
61 | Assert.Inconclusive("ProbabilisticTreeCreator: " + Environment.NewLine +
|
---|
62 | Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
|
---|
63 | Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
|
---|
64 | Util.GetNumberOfSubTreesDistributionString(randomTrees) + Environment.NewLine +
|
---|
65 | Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
|
---|
66 | );
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|