#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.GP.StructureIdentification; using Microsoft.VisualStudio.TestTools.UnitTesting; using HeuristicLab.GP.Interfaces; using System.IO; using HeuristicLab.DataAnalysis; using System; using HeuristicLab.Random; using System.Collections.Generic; using HeuristicLab.GP.Operators; using System.Diagnostics; namespace HeuristicLab.GP.Test { [TestClass()] public class FunctionTreeTest { private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } [TestMethod()] public void SizeTest() { var importer = new SymbolicExpressionImporter(); IFunctionTree tree = importer.Import("(variable 2.0 a 0)"); Assert.AreEqual(1, tree.GetSize()); tree = importer.Import("2.0"); Assert.AreEqual(1, tree.GetSize()); tree = importer.Import("(+ 2.0)"); Assert.AreEqual(2, tree.GetSize()); tree = importer.Import("(+ 2.0 2.0)"); Assert.AreEqual(3, tree.GetSize()); tree = importer.Import("(+ 2.0 (+ 2.0 2.0))"); Assert.AreEqual(5, tree.GetSize()); } [TestMethod()] public void HeightTest() { var importer = new SymbolicExpressionImporter(); IFunctionTree tree = importer.Import("(variable 2.0 a 0)"); Assert.AreEqual(1, tree.GetHeight()); tree = importer.Import("2.0"); Assert.AreEqual(1, tree.GetHeight()); tree = importer.Import("(+ 2.0)"); Assert.AreEqual(2, tree.GetHeight()); tree = importer.Import("(+ 2.0 2.0)"); Assert.AreEqual(2, tree.GetHeight()); tree = importer.Import("(+ 2.0 (+ 2.0 2.0))"); Assert.AreEqual(3, tree.GetHeight()); } } }