[9843] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 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.IO;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
[9846] | 26 | using System.Threading;
|
---|
| 27 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
[9843] | 28 | using HeuristicLab.Problems.GPDL;
|
---|
| 29 | using HeuristicLab.Problems.GPDL.Views;
|
---|
[9846] | 30 | using HeuristicLab.SequentialEngine;
|
---|
[9843] | 31 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 32 |
|
---|
| 33 | namespace Test {
|
---|
| 34 | [TestClass]
|
---|
| 35 | public class TestGpdlExamples {
|
---|
| 36 | [TestMethod]
|
---|
| 37 | public void TestExamples() {
|
---|
| 38 | var prov = new GpdlExampleProvider();
|
---|
| 39 | foreach (GpdlExampleDataDescriptor dd in prov.GetDataDescriptors()) {
|
---|
| 40 | Scanner scanner = new Scanner(new MemoryStream(Encoding.UTF8.GetBytes(dd.Source)));
|
---|
| 41 | Parser parser = new Parser(scanner);
|
---|
| 42 | parser.Parse();
|
---|
| 43 | Assert.IsNotNull(parser.problem);
|
---|
[9846] | 44 |
|
---|
| 45 | // test: run one generation
|
---|
| 46 | var ga = new GeneticAlgorithm();
|
---|
| 47 | ga.Engine = new SequentialEngine();
|
---|
| 48 | ga.PopulationSize.Value = 100;
|
---|
| 49 | ga.MaximumGenerations.Value = 1;
|
---|
| 50 | ga.Problem = parser.problem;
|
---|
| 51 |
|
---|
| 52 | var wh = new AutoResetEvent(false);
|
---|
| 53 | Exception e = null;
|
---|
| 54 | ga.ExceptionOccurred += (sender, args) => {
|
---|
| 55 | e = args.Value;
|
---|
| 56 | wh.Set();
|
---|
| 57 | };
|
---|
| 58 | ga.Stopped += (sender, args) => { wh.Set(); };
|
---|
| 59 | ga.Start();
|
---|
| 60 | wh.WaitOne();
|
---|
| 61 | if (e != null) Assert.Fail(e.Message, e);
|
---|
[9843] | 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | }
|
---|
| 66 | }
|
---|