Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.GP.Tests/FunctionTreeTest.cs @ 5182

Last change on this file since 5182 was 3873, checked in by gkronber, 14 years ago

Removed fields for tree size and tree height in GeneticProgrammingModel instead iterate through the tree to determine the size/height whenever it is needed. #1025 (Incorrect size/height values for trees)

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.GP.StructureIdentification;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24using HeuristicLab.GP.Interfaces;
25using System.IO;
26using HeuristicLab.DataAnalysis;
27using System;
28using HeuristicLab.Random;
29using System.Collections.Generic;
30using HeuristicLab.GP.Operators;
31using System.Diagnostics;
32namespace HeuristicLab.GP.Test {
33
34
35  [TestClass()]
36  public class FunctionTreeTest {
37    private TestContext testContextInstance;
38
39    /// <summary>
40    ///Gets or sets the test context which provides
41    ///information about and functionality for the current test run.
42    ///</summary>
43    public TestContext TestContext {
44      get {
45        return testContextInstance;
46      }
47      set {
48        testContextInstance = value;
49      }
50    }
51
52    [TestMethod()]
53    public void SizeTest() {
54      var importer = new SymbolicExpressionImporter();
55      IFunctionTree tree = importer.Import("(variable 2.0 a 0)");
56      Assert.AreEqual(1, tree.GetSize());
57
58      tree = importer.Import("2.0");
59      Assert.AreEqual(1, tree.GetSize());
60
61      tree = importer.Import("(+ 2.0)");
62      Assert.AreEqual(2, tree.GetSize());
63
64      tree = importer.Import("(+ 2.0 2.0)");
65      Assert.AreEqual(3, tree.GetSize());
66
67      tree = importer.Import("(+ 2.0 (+ 2.0 2.0))");
68      Assert.AreEqual(5, tree.GetSize());
69    }
70
71    [TestMethod()]
72    public void HeightTest() {
73      var importer = new SymbolicExpressionImporter();
74      IFunctionTree tree = importer.Import("(variable 2.0 a 0)");
75      Assert.AreEqual(1, tree.GetHeight());
76
77      tree = importer.Import("2.0");
78      Assert.AreEqual(1, tree.GetHeight());
79
80      tree = importer.Import("(+ 2.0)");
81      Assert.AreEqual(2, tree.GetHeight());
82
83      tree = importer.Import("(+ 2.0 2.0)");
84      Assert.AreEqual(2, tree.GetHeight());
85
86      tree = importer.Import("(+ 2.0 (+ 2.0 2.0))");
87      Assert.AreEqual(3, tree.GetHeight());
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.