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 |
|
---|
22 | using System;
|
---|
23 | using System.Threading;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Persistence.Default.Xml;
|
---|
27 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Algorithms.SGA_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(@"SGA.hl")]
|
---|
83 | public void SGAPerformanceTest() {
|
---|
84 | ex = null;
|
---|
85 | IAlgorithm sga = (IAlgorithm)XmlParser.Deserialize("SGA.hl");
|
---|
86 | sga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(sga_ExceptionOccurred);
|
---|
87 | sga.Stopped += new EventHandler(sga_Stopped);
|
---|
88 | sga.Prepare();
|
---|
89 | sga.Start();
|
---|
90 | trigger.WaitOne();
|
---|
91 | TestContext.WriteLine("Runtime: {0}", sga.ExecutionTime.ToString());
|
---|
92 | if (ex != null) throw ex;
|
---|
93 | }
|
---|
94 |
|
---|
95 | private void sga_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
96 | ex = e.Value;
|
---|
97 | }
|
---|
98 |
|
---|
99 | private void sga_Stopped(object sender, EventArgs e) {
|
---|
100 | trigger.Set();
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|