Changeset 15065 for branches/Async/HeuristicLab.Tests
- Timestamp:
- 06/26/17 09:45:36 (7 years ago)
- Location:
- branches/Async/HeuristicLab.Tests
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/CollectObjectGraphTest.cs
r12012 r15065 24 24 using System.Diagnostics; 25 25 using System.Linq; 26 using System.Threading;27 26 using System.Threading.Tasks; 28 27 using HeuristicLab.Algorithms.GeneticAlgorithm; … … 112 111 algs.Add(ga); 113 112 114 var cancellationTokenSource = new CancellationTokenSource(); 115 ga.StartSync(cancellationTokenSource.Token); 113 ga.Start(); 116 114 sw.Stop(); 117 115 TestContext.WriteLine("{0}: {1} ", i, sw.Elapsed); … … 144 142 var sw = new Stopwatch(); 145 143 sw.Start(); 146 ga.Start Sync(new CancellationToken());144 ga.Start(); 147 145 sw.Stop(); 148 146 Console.WriteLine("{0}; Objects after execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count()); -
branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/GeneticAlgorithmTest.cs
r12012 r15065 21 21 22 22 using System; 23 using System.Threading;24 23 using HeuristicLab.Algorithms.GeneticAlgorithm; 25 24 using HeuristicLab.Common; … … 39 38 } 40 39 41 private EventWaitHandle trigger = new AutoResetEvent(false);42 40 private Exception ex; 43 41 … … 49 47 GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize(@"Test Resources\GA_TSP.hl"); 50 48 ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred); 51 ga.Stopped += new EventHandler(ga_Stopped);52 49 ga.SetSeedRandomly.Value = false; 53 50 ga.Seed.Value = 0; … … 55 52 ga.Prepare(); 56 53 ga.Start(); 57 trigger.WaitOne();58 54 if (ex != null) throw ex; 59 55 … … 80 76 ex = e.Value; 81 77 } 82 83 private void ga_Stopped(object sender, EventArgs e) {84 trigger.Set();85 }86 78 } 87 79 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs
r12012 r15065 22 22 using System; 23 23 using System.Linq; 24 using System.Threading;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Problems.DataAnalysis; … … 39 38 } 40 39 41 private EventWaitHandle trigger = new AutoResetEvent(false);42 40 private Exception ex; 43 41 … … 65 63 66 64 alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred); 67 alg.Stopped += new EventHandler(cv_Stopped);68 65 69 66 alg.Prepare(); 70 67 alg.Start(); 71 trigger.WaitOne();72 68 if (ex != null) throw ex; 73 69 … … 78 74 ex = e.Value; 79 75 } 80 81 private void cv_Stopped(object sender, EventArgs e) {82 trigger.Set();83 }84 76 } 85 77 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GradientBoostingTest.cs
r13157 r15065 1 1 using System; 2 2 using System.Linq; 3 using System.Threading;4 3 using HeuristicLab.Data; 5 using HeuristicLab.Optimization;6 4 using HeuristicLab.Problems.DataAnalysis; 7 5 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 182 180 #endregion 183 181 184 RunAlgorithm(gbt);182 gbt.Start(); 185 183 186 184 Console.WriteLine(gbt.ExecutionTime); … … 210 208 #endregion 211 209 212 RunAlgorithm(gbt);210 gbt.Start(); 213 211 214 212 Console.WriteLine(gbt.ExecutionTime); … … 238 236 #endregion 239 237 240 RunAlgorithm(gbt);238 gbt.Start(); 241 239 242 240 Console.WriteLine(gbt.ExecutionTime); 243 241 Assert.AreEqual(0.061954221604374943, ((DoubleValue)gbt.Results["Loss (train)"].Value).Value, 1E-6); 244 242 Assert.AreEqual(0.06316303473499961, ((DoubleValue)gbt.Results["Loss (test)"].Value).Value, 1E-6); 245 }246 247 // same as in SamplesUtil248 private void RunAlgorithm(IAlgorithm a) {249 var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);250 Exception ex = null;251 a.Stopped += (src, e) => { trigger.Set(); };252 a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };253 a.Prepare();254 a.Start();255 trigger.WaitOne();256 257 Assert.AreEqual(ex, null);258 243 } 259 244 -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/SupportVectorMachineTest.cs
r12012 r15065 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading;26 25 using HeuristicLab.Algorithms.DataAnalysis; 27 26 using HeuristicLab.Common; … … 50 49 } 51 50 52 private EventWaitHandle trigger = new AutoResetEvent(false);53 51 private Exception ex; 54 52 … … 71 69 72 70 cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred); 73 cv.Stopped += new EventHandler(cv_Stopped);74 71 75 72 cv.Prepare(); 76 73 cv.Start(); 77 trigger.WaitOne();78 74 if (ex != null) throw ex; 79 75 … … 102 98 ex = e.Value; 103 99 } 104 105 private void cv_Stopped(object sender, EventArgs e) {106 trigger.Set();107 }108 100 } 109 101 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Script Sources/GUIAutomationScriptSource.cs
r11789 r15065 1 using System; 2 using System.Linq; 3 using System.Threading; 1 using System.Linq; 4 2 using System.Windows.Forms; 5 3 6 4 using HeuristicLab.Algorithms.GeneticAlgorithm; 7 using HeuristicLab.Core;8 5 using HeuristicLab.MainForm; 9 6 using HeuristicLab.MainForm.WindowsForms; … … 13 10 14 11 public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase { 15 readonly ManualResetEvent mutex = new ManualResetEvent(false);16 17 12 public override void Main() { 18 13 var ga = new GeneticAlgorithm { … … 27 22 ga.PopulationSize.Value *= 2; 28 23 } 29 30 experiment.ExecutionStateChanged += OnExecutionStateChanged;31 24 experiment.Start(); 32 mutex.WaitOne();33 25 34 26 vars.experiment = experiment; … … 39 31 bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize"; 40 32 } 41 42 private void OnExecutionStateChanged(object sender, EventArgs e) {43 if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)44 mutex.Set();45 }46 33 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r13266 r15065 428 428 <ItemGroup> 429 429 <Compile Include="AssemblyInitializer.cs" /> 430 <Compile Include="HeuristicLab-3.3\AlgorithmExtensions.cs" />431 430 <Compile Include="HeuristicLab-3.3\CloningConstructorTest.cs" /> 432 431 <Compile Include="HeuristicLab-3.3\CollectObjectGraphTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.