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, 13 years ago

Continued work on algorithm batch processing (#947).

File size: 3.2 KB
Line 
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;
23using System.Threading;
24using HeuristicLab.Common;
25using HeuristicLab.Optimization;
26using HeuristicLab.Persistence.Default.Xml;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
29namespace HeuristicLab.Algorithms.GeneticAlgorithm_33.Tests {
30  /// <summary>
31  /// Summary description for UnitTest
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);
79    private Exception ex;
80
81    [TestMethod]
82    [DeploymentItem(@"GA_TSP.hl")]
83    public void GeneticAlgorithmPerformanceTest() {
84      ex = null;
85      IAlgorithm ga = (IAlgorithm)XmlParser.Deserialize("GA_TSP.hl");
86      ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
87      ga.Stopped += new EventHandler(ga_Stopped);
88      ga.Prepare();
89      ga.Start();
90      trigger.WaitOne();
91      TestContext.WriteLine("Runtime: {0}", ga.ExecutionTime.ToString());
92      if (ex != null) throw ex;
93    }
94
95    private void ga_ExceptionOccurred(object sender, EventArgs<Exception> e) {
96      ex = e.Value;
97    }
98
99    private void ga_Stopped(object sender, EventArgs e) {
100      trigger.Set();
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.