Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GUI_Automation_Script.cs @ 11545

Last change on this file since 11545 was 11514, checked in by jkarder, 9 years ago

#2211:

  • updated/added unit tests
    • added AssemblyInitialize method to load all plugins, create output directories for (script) samples and initialize the MainForm
    • script code is now stored in test resource files
    • refactored unit tests
  • updated (script) samples
  • added Test.cmd
File size: 1.7 KB
Line 
1using System;
2using System.Linq;
3using System.Threading;
4using System.Windows.Forms;
5
6using HeuristicLab.Algorithms.GeneticAlgorithm;
7using HeuristicLab.Core;
8using HeuristicLab.MainForm;
9using HeuristicLab.MainForm.WindowsForms;
10using HeuristicLab.Optimization;
11using HeuristicLab.Optimization.Views;
12using HeuristicLab.Problems.TravelingSalesman;
13
14public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase {
15  readonly ManualResetEvent mutex = new ManualResetEvent(false);
16
17  public override void Main() {
18    var ga = new GeneticAlgorithm {
19      MaximumGenerations = { Value = 50 },
20      PopulationSize = { Value = 10 },
21      Problem = new TravelingSalesmanProblem()
22    };
23
24    var experiment = new Experiment();
25    for (int i = 0; i < 5; i++) {
26      experiment.Optimizers.Add(new BatchRun() { Optimizer = (IOptimizer)ga.Clone(), Repetitions = 10 });
27      ga.PopulationSize.Value *= 2;
28    }
29
30    experiment.ExecutionStateChanged += OnExecutionStateChanged;
31    experiment.Start();
32    mutex.WaitOne();
33
34    vars.experiment = experiment;
35    MainFormManager.MainForm.ShowContent(experiment);
36    var viewHost = (ViewHost)MainFormManager.MainForm.ShowContent(experiment.Runs, typeof(RunCollectionBubbleChartView));
37    var bubbleChart = (UserControl)(viewHost.ActiveView);
38    bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "yAxisComboBox").SelectedItem = "BestQuality";
39    bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize";
40  }
41
42  private void OnExecutionStateChanged(object sender, EventArgs e) {
43    if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)
44      mutex.Set();
45  }
46}
Note: See TracBrowser for help on using the repository browser.