#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 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 System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using HeuristicLab.Algorithms.GeneticAlgorithm;
using HeuristicLab.Common;
using HeuristicLab.Optimization;
using HeuristicLab.Persistence.Default.Xml;
using HeuristicLab.Problems.TestFunctions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace HeuristicLab.Tests {
[TestClass]
public class CollectObjectGraphTest {
private TestContext testContextInstance;
public TestContext TestContext {
get { return testContextInstance; }
set { testContextInstance = value; }
}
[TestMethod]
[Description("Verify that the object graph traversal is working by checking the number of objects after traversal.")]
[TestCategory("General")]
[TestCategory("Essential")]
[TestProperty("Time", "medium")]
public void TestObjectGraphTraversal() {
GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize(@"Test Resources\GA_SymbReg.hl");
var objects = ga.GetObjectGraphObjects().ToList();
// Should be 3982, but count may change slightly as members are added or removed
Assert.IsTrue(objects.Count > 1, "Number of objects in the object graph seems to small.");
}
[TestMethod]
[TestCategory("General")]
[TestCategory("Essential")]
[TestProperty("Time", "medium")]
public void CollectGASample() {
GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize(@"Test Resources\GA_SymbReg.hl");
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 1; i++)
ga.GetObjectGraphObjects().Count();
watch.Stop();
var objects = ga.GetObjectGraphObjects().ToList();
TestContext.WriteLine("Time elapsed {0}", watch.Elapsed);
TestContext.WriteLine("Objects discovered: {0}", objects.Count());
TestContext.WriteLine("HL objects discovered: {0}", objects.Count(o => o.GetType().Namespace.StartsWith("HeuristicLab")));
TestContext.WriteLine("");
Dictionary> objs = new Dictionary>();
foreach (object o in objects) {
if (!objs.ContainsKey(o.GetType()))
objs.Add(o.GetType(), new List