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