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 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
|
---|
10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
|
---|
13 | [TestClass]
|
---|
14 | public class SubroutineCreaterTest {
|
---|
15 | private static ISymbolicExpressionGrammar grammar;
|
---|
16 | private static List<SymbolicExpressionTree> subroutineTrees;
|
---|
17 | private static int failedEvents;
|
---|
18 |
|
---|
19 | private TestContext testContextInstance;
|
---|
20 |
|
---|
21 | /// <summary>
|
---|
22 | ///Gets or sets the test context which provides
|
---|
23 | ///information about and functionality for the current test run.
|
---|
24 | ///</summary>
|
---|
25 | public TestContext TestContext {
|
---|
26 | get {
|
---|
27 | return testContextInstance;
|
---|
28 | }
|
---|
29 | set {
|
---|
30 | testContextInstance = value;
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | [ClassInitialize()]
|
---|
35 | public static void SubroutineCreaterTestInitialize(TestContext testContext) {
|
---|
36 | var randomTrees = new List<SymbolicExpressionTree>();
|
---|
37 | subroutineTrees = new List<SymbolicExpressionTree>();
|
---|
38 | int populationSize = 1000;
|
---|
39 | failedEvents = 0;
|
---|
40 | grammar = Grammars.CreateArithmeticAndAdfGrammar();
|
---|
41 | var random = new MersenneTwister();
|
---|
42 | for (int i = 0; i < populationSize; i++) {
|
---|
43 | var randTree = ProbabilisticTreeCreator.Create(random, grammar, 100, 10);
|
---|
44 | // PTC create is tested separately
|
---|
45 | randomTrees.Add(randTree);
|
---|
46 | }
|
---|
47 | var newPopulation = new List<SymbolicExpressionTree>();
|
---|
48 | for (int i = 0; i < populationSize; i++) {
|
---|
49 | var par0 = (SymbolicExpressionTree)randomTrees[random.Next(populationSize)].Clone();
|
---|
50 | bool success = SubroutineCreater.CreateSubroutine(random, par0, grammar, 100, 10, 3, 3);
|
---|
51 | if (!success) failedEvents++;
|
---|
52 | subroutineTrees.Add(par0);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | [TestMethod()]
|
---|
58 | public void SubroutineCreaterCreateTest() {
|
---|
59 | foreach (var tree in subroutineTrees)
|
---|
60 | Assert.IsTrue(grammar.IsValidExpression(tree));
|
---|
61 | }
|
---|
62 |
|
---|
63 | [TestMethod()]
|
---|
64 | public void SubroutineCreaterSizeDistributionTest() {
|
---|
65 | Assert.Inconclusive("SubroutineCreater: " + Util.GetSizeDistributionString(subroutineTrees, 105, 5));
|
---|
66 | }
|
---|
67 |
|
---|
68 | [TestMethod()]
|
---|
69 | public void SubroutineCreaterFunctionDistributionTest() {
|
---|
70 | Assert.Inconclusive("SubroutineCreater: " + Util.GetFunctionDistributionString(subroutineTrees));
|
---|
71 | }
|
---|
72 |
|
---|
73 | [TestMethod()]
|
---|
74 | public void SubroutineCreaterNumberOfSubTreesDistributionTest() {
|
---|
75 | Assert.Inconclusive("SubroutineCreater: " + Util.GetNumberOfSubTreesDistributionString(subroutineTrees));
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | [TestMethod()]
|
---|
80 | public void SubroutineCreaterTerminalDistributionTest() {
|
---|
81 | Assert.Inconclusive("SubroutineCreater: " + Util.GetTerminalDistributionString(subroutineTrees));
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|