Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1326


Ignore:
Timestamp:
03/11/09 17:46:49 (15 years ago)
Author:
cbahner
Message:

#519 tests for aggregators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs

    r1285 r1326  
    11using System;
    22using System.Drawing;
     3using System.Threading;
    34using NUnit.Framework;
    45
     
    99100
    100101    [Test]
     102    public void TestAggregator() {
     103      LineChartTestForm f = new LineChartTestForm(model);
     104
     105      IDataRow row1 = new DataRow();
     106      row1.Label = "row";
     107      row1.Color = Color.Red;
     108      row1.Thickness = 3;
     109      row1.Style = DrawingStyle.Solid;
     110
     111      model.AddDataRow(row1);
     112
     113
     114      IAggregator aggregator = new MinAggregator();
     115      aggregator.Label = "MinAggregator";
     116      aggregator.Color = Color.Pink;
     117      aggregator.Thickness = 5;
     118      aggregator.Style = DrawingStyle.Solid;
     119      aggregator.AddValue(2);
     120      aggregator.LineType = DataRowType.SingleValue;
     121
     122      IDataRow lineTest = new DataRow("testline");
     123      lineTest.Color = Color.DarkSalmon;
     124      lineTest.Thickness = 2;
     125      lineTest.Style = DrawingStyle.Dashed;
     126      lineTest.LineType = DataRowType.SingleValue;
     127      model.AddDataRow(lineTest);
     128      lineTest.AddValue(9);
     129      lineTest.AddValue(2);
     130      lineTest.AddValue(3);
     131      lineTest.AddValue(4);
     132
     133      aggregator.AddWatch(row1);
     134
     135      model.AddDataRow(aggregator);
     136
     137
     138      row1.AddValue(10);
     139      row1.AddValue(5);
     140      row1.AddValue(7);
     141      row1.AddValue(3);
     142      row1.AddValue(10);
     143      row1.AddValue(2);
     144
     145      f.ShowDialog();
     146    }
     147
     148
     149    public class Worker {
     150      // This method will be called when the thread is started.
     151      private ChartDataRowsModel model;
     152      public Worker(ChartDataRowsModel model) {
     153        this.model = model;
     154      }
     155     
     156      public void DoWork() {
     157
     158        IDataRow row1 = new DataRow();
     159        row1.Color = Color.Red;
     160        row1.Thickness = 2;
     161        row1.Label = "Simon";
     162        row1.Style = DrawingStyle.Solid;
     163        model.AddDataRow(row1);
     164
     165        IDataRow row2 = new DataRow();
     166        row2.Color = Color.Red;
     167        row2.Thickness = 3;
     168        row2.Label = "Simon";
     169        row2.Style = DrawingStyle.Solid;
     170        model.AddDataRow(row2);
     171
     172
     173        IAggregator aggregator = new MinAggregator();
     174        aggregator.Label = "MinAggregator";
     175        aggregator.Color = Color.Pink;
     176        aggregator.Thickness = 3;
     177        aggregator.Style = DrawingStyle.Solid;
     178        aggregator.LineType = DataRowType.SingleValue;
     179        aggregator.AddWatch(row1);
     180        model.AddDataRow(aggregator);
     181
     182        IAggregator maxAggregator = new MaxAggregator();
     183        maxAggregator.Label = "MaxAggregator";
     184        maxAggregator.Color = Color.DeepSkyBlue;
     185        maxAggregator.Thickness = 3;
     186        maxAggregator.Style = DrawingStyle.Solid;
     187        maxAggregator.LineType = DataRowType.SingleValue;
     188        maxAggregator.AddWatch(row1);
     189        model.AddDataRow(maxAggregator);
     190       
     191       
     192        IAggregator avgAggregator = new AvgAggregator();
     193        avgAggregator.Label = "AvgAggregator";
     194        avgAggregator.Color = Color.Violet;
     195        avgAggregator.Thickness = 3;
     196        avgAggregator.Style = DrawingStyle.Solid;
     197        avgAggregator.LineType = DataRowType.SingleValue;
     198        avgAggregator.AddWatch(row1);
     199        model.AddDataRow(avgAggregator);
     200
     201        IAggregator multiAvgAggregator = new AvgAggregator();
     202        multiAvgAggregator.Label = "MultiAvgAggregator";
     203        multiAvgAggregator.Color = Color.DarkOliveGreen;
     204        multiAvgAggregator.Thickness = 3;
     205        multiAvgAggregator.Style = DrawingStyle.Solid;
     206        multiAvgAggregator.LineType = DataRowType.SingleValue;
     207        multiAvgAggregator.AddWatch(row1);
     208        multiAvgAggregator.AddWatch(row2);
     209        model.AddDataRow(multiAvgAggregator);
     210
     211        IAggregator multiMaxAggregator = new MaxAggregator();
     212        multiMaxAggregator.Label = "MultiMaxAggregator";
     213        multiMaxAggregator.Color = Color.DarkKhaki;
     214        multiMaxAggregator.Thickness = 3;
     215        multiMaxAggregator.Style = DrawingStyle.Solid;
     216        multiMaxAggregator.LineType = DataRowType.SingleValue;
     217        multiMaxAggregator.AddWatch(row1);
     218        multiMaxAggregator.AddWatch(row2);
     219        model.AddDataRow(multiMaxAggregator);
     220
     221        IAggregator multiMinAggregator = new MinAggregator();
     222        multiMinAggregator.Label = "MultiMinAggregator";
     223        multiMinAggregator.Color = Color.DarkRed;
     224        multiMinAggregator.Thickness = 3;
     225        multiMinAggregator.Style = DrawingStyle.Solid;
     226        multiMinAggregator.LineType = DataRowType.SingleValue;
     227        multiMinAggregator.AddWatch(row1);
     228        multiMinAggregator.AddWatch(row2);
     229        model.AddDataRow(multiMinAggregator);
     230
     231        IAggregator multiLineAvgAggregator = new AvgLineAggregator();
     232        multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
     233        multiLineAvgAggregator.Color = Color.Red;
     234        multiLineAvgAggregator.Thickness = 4;
     235        multiLineAvgAggregator.Style = DrawingStyle.Solid;
     236        multiLineAvgAggregator.LineType = DataRowType.Normal;
     237        multiLineAvgAggregator.AddWatch(row1);
     238        multiLineAvgAggregator.AddWatch(row2);
     239        multiLineAvgAggregator.AddValue(0);
     240        model.AddDataRow(multiLineAvgAggregator);
     241
     242        double i = 0;
     243        double newY;
     244
     245        Random rand = new Random();
     246        while (!_shouldStop && i <= 24) {
     247          i += 0.2;
     248          newY = Math.Sin(i);
     249          System.Console.WriteLine("working");
     250          //row1.AddValue(rand.NextDouble() * 10);
     251          row1.AddValue(newY * 10);
     252          row2.AddValue(i*2-15);
     253          System.Threading.Thread.Sleep(100);
     254        }
     255        Console.WriteLine("worker thread: terminating gracefully.");
     256      }
     257      public void RequestStop() {
     258        _shouldStop = true;
     259      }
     260      // Volatile is used as hint to the compiler that this data
     261      // member will be accessed by multiple threads.
     262      private volatile bool _shouldStop;
     263    }
     264
     265
     266    [Test]
     267    public void TestAggregator2() {
     268      LineChartTestForm f = new LineChartTestForm(model);
     269   
     270      // Create the thread object. This does not start the thread.
     271      Worker workerObject = new Worker(model);
     272      Thread workerThread = new Thread(workerObject.DoWork);
     273
     274      // Start the worker thread.
     275      workerThread.Start();
     276
     277      f.ShowDialog();
     278      workerObject.RequestStop();
     279    }
     280
     281   
     282
     283    [Test]
    101284    public void TestAutoZoomInConstructor() {
    102285      IDataRow row1 = new DataRow();
Note: See TracChangeset for help on using the changeset viewer.