Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs @ 3265

Last change on this file since 3265 was 3265, checked in by swagner, 14 years ago

Continued work on algorithm batch processing (#947).

File size: 3.2 KB
RevLine 
[2916]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System;
[2830]23using System.Threading;
[2917]24using HeuristicLab.Common;
[2916]25using HeuristicLab.Optimization;
[2830]26using HeuristicLab.Persistence.Default.Xml;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
[3196]29namespace HeuristicLab.Algorithms.GeneticAlgorithm_33.Tests {
[2830]30  /// <summary>
[2884]31  /// Summary description for UnitTest
[2830]32  /// </summary>
33  [TestClass]
34  public class UnitTest {
35    public UnitTest() {
36      //
37      // TODO: Add constructor logic here
38      //
39    }
40
41    private TestContext testContextInstance;
42
43    /// <summary>
44    ///Gets or sets the test context which provides
45    ///information about and functionality for the current test run.
46    ///</summary>
47    public TestContext TestContext {
48      get {
49        return testContextInstance;
50      }
51      set {
52        testContextInstance = value;
53      }
54    }
55
56    #region Additional test attributes
57    //
58    // You can use the following additional attributes as you write your tests:
59    //
60    // Use ClassInitialize to run code before running the first test in the class
61    // [ClassInitialize()]
62    // public static void MyClassInitialize(TestContext testContext) { }
63    //
64    // Use ClassCleanup to run code after all tests in a class have run
65    // [ClassCleanup()]
66    // public static void MyClassCleanup() { }
67    //
68    // Use TestInitialize to run code before running each test
69    // [TestInitialize()]
70    // public void MyTestInitialize() { }
71    //
72    // Use TestCleanup to run code after each test has run
73    // [TestCleanup()]
74    // public void MyTestCleanup() { }
75    //
76    #endregion
77
78    private EventWaitHandle trigger = new AutoResetEvent(false);
[2917]79    private Exception ex;
[2830]80
81    [TestMethod]
[3265]82    [DeploymentItem(@"GA_TSP.hl")]
[3198]83    public void GeneticAlgorithmPerformanceTest() {
[2917]84      ex = null;
[3265]85      IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GA_TSP.hl");
[3198]86      ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
87      ga.Stopped += new EventHandler(ga_Stopped);
88      ga.Prepare();
89      ga.Start();
[2830]90      trigger.WaitOne();
[3198]91      TestContext.WriteLine("Runtime: {0}", ga.ExecutionTime.ToString());
[2917]92      if (ex != null) throw ex;
[2830]93    }
94
[3198]95    private void ga_ExceptionOccurred(object sender, EventArgs<Exception> e) {
[2917]96      ex = e.Value;
97    }
98
[3198]99    private void ga_Stopped(object sender, EventArgs e) {
[2830]100      trigger.Set();
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.