Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL.Backend/Test/TestGpdlExamples.cs @ 10159

Last change on this file since 10159 was 10057, checked in by gkronber, 11 years ago

#2026 moved a test class into the HL specific GPDL branch

File size: 2.3 KB
Line 
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
22using System;
23using System.IO;
24using System.Linq;
25using System.Text;
26using System.Threading;
27using HeuristicLab.Algorithms.GeneticAlgorithm;
28using HeuristicLab.Problems.GPDL;
29using HeuristicLab.Problems.GPDL.CodeGen;
30using HeuristicLab.Problems.GPDL.Views;
31using HeuristicLab.SequentialEngine;
32using Microsoft.VisualStudio.TestTools.UnitTesting;
33
34namespace 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}
Note: See TracBrowser for help on using the repository browser.