Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/09 14:41:05 (16 years ago)
Author:
cbahner
Message:

#519 test cases + code review

File:
1 edited

Legend:

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

    r1530 r1607  
    3737      row2.Style = DrawingStyle.Solid;
    3838      row3.Style = DrawingStyle.Dashed;
    39      
     39
    4040
    4141      model.AddDataRow(row1);
     
    6363
    6464      for (int i = 0; i < 10000; i++) {
    65         row1.AddValue(rand.NextDouble()*10);
    66         row2.AddValue(rand.NextDouble()*10);
    67         row3.AddValue(rand.NextDouble()*10);
    68       }
    69 
    70       f.ShowDialog();
    71     }
    72      
     65        row1.AddValue(rand.NextDouble() * 10);
     66        row2.AddValue(rand.NextDouble() * 10);
     67        row3.AddValue(rand.NextDouble() * 10);
     68      }
     69
     70      f.ShowDialog();
     71    }
     72
    7373    [Test]
    7474    public void TestAxes() {
     
    119119
    120120      for (int i = 0; i < 10; i++) {
    121         row1.AddValue(rand.NextDouble()*10);
    122         row2.AddValue(rand.NextDouble()*10);
    123         row3.AddValue(rand.NextDouble()*1);
     121        row1.AddValue(rand.NextDouble() * 10);
     122        row2.AddValue(rand.NextDouble() * 10);
     123        row3.AddValue(rand.NextDouble() * 1);
    124124      }
    125125
    126126      f.AddValue += delegate {
    127         row1.AddValue(rand.NextDouble()*10);
    128         row2.AddValue(rand.NextDouble()*10);
    129         row3.AddValue(rand.NextDouble()*1);
     127        row1.AddValue(rand.NextDouble() * 10);
     128        row2.AddValue(rand.NextDouble() * 10);
     129        row3.AddValue(rand.NextDouble() * 1);
    130130      };
    131131
     
    134134
    135135    [Test]
    136     public void TestAggregator() {
    137       LineChartTestForm f = new LineChartTestForm(model);
    138 
    139       IDataRow row1 = new DataRow();
    140       row1.Label = "row";
    141       row1.Color = Color.Red;
    142       row1.Thickness = 3;
    143       row1.Style = DrawingStyle.Solid;
     136    public void SimpleTestAggregator() {
     137      LineChartTestForm f = new LineChartTestForm(model);
     138
     139      IDataRow row1 = new DataRow { Label = "row", Color = Color.Red, Thickness = 3, Style = DrawingStyle.Solid };
    144140
    145141      model.AddDataRow(row1);
    146142
    147143
    148       MinAggregator aggregator = new MinAggregator();
    149       aggregator.Label = "MinAggregator";
    150       aggregator.Color = Color.Pink;
    151       aggregator.Thickness = 5;
    152       aggregator.Style = DrawingStyle.Solid;
    153       aggregator.AddValue(2);
    154       aggregator.LineType = DataRowType.SingleValue;
    155 
    156       IDataRow lineTest = new DataRow("testline");
    157       lineTest.Color = Color.DarkSalmon;
    158       lineTest.Thickness = 2;
    159       lineTest.Style = DrawingStyle.Dashed;
    160       lineTest.LineType = DataRowType.SingleValue;
    161       model.AddDataRow(lineTest);
    162       lineTest.AddValue(9);
    163       lineTest.AddValue(2);
    164       lineTest.AddValue(3);
    165       lineTest.AddValue(4);
    166 
     144      MaxAggregator aggregator = new MaxAggregator {
     145        Label = "MinAggregator",
     146        Color = Color.Pink,
     147        Thickness = 5,
     148        Style = DrawingStyle.Solid,
     149        LineType = DataRowType.SingleValue
     150      };
    167151      aggregator.AddWatch(row1);
    168152
    169153      model.AddDataRow(aggregator);
    170 
    171154
    172155      row1.AddValue(10);
     
    183166    public class Worker {
    184167      // This method will be called when the thread is started.
    185       private ChartDataRowsModel model;
     168      private readonly ChartDataRowsModel model;
     169
    186170      public Worker(ChartDataRowsModel model) {
    187171        this.model = model;
    188172      }
    189      
     173
    190174      public void DoWorkMultiLine() {
    191 
    192         IDataRow row1 = new DataRow();
    193         row1.Color = Color.Red;
    194         row1.Thickness = 2;
    195         row1.Label = "Sinus";
    196         row1.Style = DrawingStyle.Solid;
     175        IDataRow row1 = new DataRow { Color = Color.Red, Thickness = 2, Label = "Sinus", Style = DrawingStyle.Solid, ShowMarkers = false };
    197176        model.AddDataRow(row1);
    198177
    199         IDataRow row2 = new DataRow();
    200         row2.Color = Color.Red;
    201         row2.Thickness = 3;
    202         row2.Label = "Growing";
    203         row2.Style = DrawingStyle.Solid;
     178        IDataRow row2 = new DataRow { Color = Color.Red, Thickness = 3, Label = "Growing", Style = DrawingStyle.Solid, ShowMarkers = false };
    204179        model.AddDataRow(row2);
    205180
    206         AvgAggregator multiAvgAggregator = new AvgAggregator();
    207         multiAvgAggregator.Label = "MultiAvgAggregator";
    208         multiAvgAggregator.Color = Color.DarkOliveGreen;
    209         multiAvgAggregator.Thickness = 3;
    210         multiAvgAggregator.Style = DrawingStyle.Solid;
    211         multiAvgAggregator.LineType = DataRowType.SingleValue;
     181        AvgAggregator multiAvgAggregator = new AvgAggregator {
     182          Label = "MultiAvgAggregator",
     183          Color = Color.DarkOliveGreen,
     184          Thickness = 3,
     185          Style = DrawingStyle.Solid,
     186          LineType = DataRowType.SingleValue,
     187          ShowMarkers = false
     188        };
    212189        multiAvgAggregator.AddWatch(row1);
    213190        multiAvgAggregator.AddWatch(row2);
    214191        model.AddDataRow(multiAvgAggregator);
    215192
    216         MaxAggregator multiMaxAggregator = new MaxAggregator();
    217         multiMaxAggregator.Label = "MultiMaxAggregator";
    218         multiMaxAggregator.Color = Color.DarkKhaki;
    219         multiMaxAggregator.Thickness = 3;
    220         multiMaxAggregator.Style = DrawingStyle.Solid;
    221         multiMaxAggregator.LineType = DataRowType.SingleValue;
     193        MaxAggregator multiMaxAggregator = new MaxAggregator {
     194          Label = "MultiMaxAggregator",
     195          Color = Color.DarkKhaki,
     196          Thickness = 3,
     197          Style = DrawingStyle.Solid,
     198          LineType = DataRowType.SingleValue,
     199          ShowMarkers = false
     200        };
    222201        multiMaxAggregator.AddWatch(row1);
    223202        multiMaxAggregator.AddWatch(row2);
    224203        model.AddDataRow(multiMaxAggregator);
    225204
    226         MinAggregator multiMinAggregator = new MinAggregator();
    227         multiMinAggregator.Label = "MultiMinAggregator";
    228         multiMinAggregator.Color = Color.DarkRed;
    229         multiMinAggregator.Thickness = 3;
    230         multiMinAggregator.Style = DrawingStyle.Solid;
    231         multiMinAggregator.LineType = DataRowType.SingleValue;
     205        MinAggregator multiMinAggregator = new MinAggregator {
     206          Label = "MultiMinAggregator",
     207          Color = Color.DarkRed,
     208          Thickness = 3,
     209          Style = DrawingStyle.Solid,
     210          LineType = DataRowType.SingleValue,
     211          ShowMarkers = false
     212        };
    232213        multiMinAggregator.AddWatch(row1);
    233214        multiMinAggregator.AddWatch(row2);
    234215        model.AddDataRow(multiMinAggregator);
    235216
    236         AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator();
    237         multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
    238         multiLineAvgAggregator.Color = Color.Red;
    239         multiLineAvgAggregator.Thickness = 4;
    240         multiLineAvgAggregator.Style = DrawingStyle.Solid;
    241         multiLineAvgAggregator.LineType = DataRowType.Normal;
    242         multiLineAvgAggregator.AddWatch(row1);
    243         multiLineAvgAggregator.AddWatch(row2);
    244         multiLineAvgAggregator.AddValue(0);
    245         model.AddDataRow(multiLineAvgAggregator);
     217        //        AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator {
     218        //                                                                           Label = "MultiLineAvgAggregator",
     219        //                                                                           Color = Color.Red,
     220        //                                                                           Thickness = 4,
     221        //                                                                           Style = DrawingStyle.Solid,
     222        //                                                                           LineType = DataRowType.Normal,
     223        //                                                                           ShowMarkers = false
     224        //                                                                         };
     225        //        multiLineAvgAggregator.AddWatch(row1);
     226        //        multiLineAvgAggregator.AddWatch(row2);
     227        //        multiLineAvgAggregator.AddValue(0);
     228        //        model.AddDataRow(multiLineAvgAggregator);
    246229
    247230        double i = 0;
    248         double newY;
    249 
    250         Random rand = new Random();
     231
     232
    251233        while (!_shouldStop && i <= 24) {
    252234          i += 0.2;
    253           newY = Math.Sin(i);
    254           System.Console.WriteLine("working");
    255           //row1.AddValue(rand.NextDouble() * 10);
    256           row1.AddValue(newY * 10);
    257           row2.AddValue(i*2-15);
    258           System.Threading.Thread.Sleep(100);
    259         }
    260         Console.WriteLine("worker thread: terminating gracefully.");
    261       }
    262       public void DoWorkSingleLine() {
    263 
    264         IDataRow row1 = new DataRow();
    265         row1.Color = Color.Red;
    266         row1.Thickness = 2;
    267         row1.Label = "Sinus";
    268         row1.Style = DrawingStyle.Solid;
    269         model.AddDataRow(row1);
    270 
    271         IDataRow row2 = new DataRow();
    272         row2.Color = Color.Red;
    273         row2.Thickness = 3;
    274         row2.Label = "Growing";
    275         row2.Style = DrawingStyle.Solid;
    276         model.AddDataRow(row2);
    277 
    278         MinAggregator aggregator = new MinAggregator();
    279         aggregator.Label = "MinAggregator";
    280         aggregator.Color = Color.Pink;
    281         aggregator.Thickness = 3;
    282         aggregator.Style = DrawingStyle.Solid;
    283         aggregator.LineType = DataRowType.SingleValue;
    284         aggregator.AddWatch(row1);
    285         model.AddDataRow(aggregator);
    286 
    287         MaxAggregator maxAggregator = new MaxAggregator();
    288         maxAggregator.Label = "MaxAggregator";
    289         maxAggregator.Color = Color.DeepSkyBlue;
    290         maxAggregator.Thickness = 3;
    291         maxAggregator.Style = DrawingStyle.Solid;
    292         maxAggregator.LineType = DataRowType.SingleValue;
    293         maxAggregator.AddWatch(row1);
    294         model.AddDataRow(maxAggregator);
    295 
    296         AvgAggregator avgAggregator = new AvgAggregator();
    297         avgAggregator.Label = "AvgAggregator";
    298         avgAggregator.Color = Color.Violet;
    299         avgAggregator.Thickness = 3;
    300         avgAggregator.Style = DrawingStyle.Solid;
    301         avgAggregator.LineType = DataRowType.SingleValue;
    302         avgAggregator.AddWatch(row1);
    303         model.AddDataRow(avgAggregator);
    304 
    305         double i = 0;
    306         double newY;
    307 
    308         Random rand = new Random();
    309         while (!_shouldStop && i <= 24) {
    310           i += 0.2;
    311           newY = Math.Sin(i);
    312           System.Console.WriteLine("working");
     235          double newY = Math.Sin(i);
     236          Console.WriteLine("working");
    313237          //row1.AddValue(rand.NextDouble() * 10);
    314238          row1.AddValue(newY * 10);
    315239          row2.AddValue(i * 2 - 15);
    316           System.Threading.Thread.Sleep(100);
     240          Thread.Sleep(100);
    317241        }
    318242        Console.WriteLine("worker thread: terminating gracefully.");
    319243      }
     244
     245      public void DoWorkSingleLine() {
     246        IDataRow row1 = new DataRow {
     247          Color = Color.Red,
     248          Thickness = 2,
     249          Label = "Sinus",
     250          Style = DrawingStyle.Solid,
     251          ShowMarkers = false
     252        };
     253        model.AddDataRow(row1);
     254
     255        IDataRow row2 = new DataRow {
     256          Color = Color.Red,
     257          Thickness = 3,
     258          Label = "Growing",
     259          Style = DrawingStyle.Solid,
     260          ShowMarkers = false
     261        };
     262        model.AddDataRow(row2);
     263
     264        MinAggregator aggregator = new MinAggregator {
     265          Label = "MinAggregator",
     266          Color = Color.Pink,
     267          Thickness = 3,
     268          Style = DrawingStyle.Solid,
     269          LineType = DataRowType.SingleValue
     270        };
     271        aggregator.AddWatch(row1);
     272        model.AddDataRow(aggregator);
     273
     274        MaxAggregator maxAggregator = new MaxAggregator {
     275          Label = "MaxAggregator",
     276          Color = Color.DeepSkyBlue,
     277          Thickness = 3,
     278          Style = DrawingStyle.Solid,
     279          LineType = DataRowType.SingleValue
     280        };
     281        maxAggregator.AddWatch(row1);
     282        model.AddDataRow(maxAggregator);
     283
     284        AvgAggregator avgAggregator = new AvgAggregator {
     285          Label = "AvgAggregator",
     286          Color = Color.Violet,
     287          Thickness = 3,
     288          Style = DrawingStyle.Solid,
     289          LineType = DataRowType.SingleValue
     290        };
     291        avgAggregator.AddWatch(row1);
     292        model.AddDataRow(avgAggregator);
     293
     294        double i = 0;
     295
     296
     297        while (!_shouldStop && i <= 240) {
     298          i += 0.2;
     299          double newY = Math.Sin(i);
     300          Console.WriteLine("working");
     301          //row1.AddValue(rand.NextDouble() * 10);
     302          row1.AddValue(newY * 10);
     303          row2.AddValue(i * 2 - 15);
     304          //System.Threading.Thread.Sleep(100);
     305        }
     306        Console.WriteLine("worker thread: terminating gracefully.");
     307      }
     308
    320309      public void DoWorkAvgLine() {
    321 
    322         IDataRow row1 = new DataRow();
    323         row1.Color = Color.Red;
    324         row1.Thickness = 2;
    325         row1.Label = "Sinus";
    326         row1.Style = DrawingStyle.Solid;
     310        IDataRow row1 = new DataRow {
     311          Color = Color.Red,
     312          Thickness = 2,
     313          Label = "Sinus",
     314          Style = DrawingStyle.Solid,
     315          ShowMarkers = false
     316        };
    327317        model.AddDataRow(row1);
    328318
    329         IDataRow row2 = new DataRow();
    330         row2.Color = Color.Red;
    331         row2.Thickness = 3;
    332         row2.Label = "Growing";
    333         row2.Style = DrawingStyle.Solid;
     319        IDataRow row2 = new DataRow {
     320          Color = Color.Red,
     321          Thickness = 3,
     322          Label = "Growing",
     323          Style = DrawingStyle.Solid,
     324          ShowMarkers = false
     325        };
    334326        model.AddDataRow(row2);
    335327
    336         AvgLineAggregator avgLineAggregator = new AvgLineAggregator();
    337         avgLineAggregator.Label = "AvgLineAggregator";
    338         avgLineAggregator.Color = Color.Violet;
    339         avgLineAggregator.Thickness = 3;
    340         avgLineAggregator.Style = DrawingStyle.Solid;
    341         avgLineAggregator.LineType = DataRowType.Normal;
     328        AvgLineAggregator avgLineAggregator = new AvgLineAggregator {
     329          Label = "AvgLineAggregator",
     330          Color = Color.Violet,
     331          Thickness = 3,
     332          Style = DrawingStyle.Solid,
     333          LineType = DataRowType.Normal,
     334          ShowMarkers = false
     335        };
    342336        avgLineAggregator.AddWatch(row1);
    343337        avgLineAggregator.AddWatch(row2);
     
    345339
    346340        double i = 0;
    347         double newY;
    348 
    349         Random rand = new Random();
    350         while (!_shouldStop && i <= 24) {
     341
     342        while (!_shouldStop && i <= 240) {
    351343          i += 0.2;
    352           newY = Math.Sin(i);
    353           System.Console.WriteLine("working");
     344          double newY = Math.Sin(i);
     345          Console.WriteLine("working");
    354346          //row1.AddValue(rand.NextDouble() * 10);
    355347          row1.AddValue(newY * 10);
    356348          row2.AddValue(i * 2 - 15);
    357           System.Threading.Thread.Sleep(100);
     349          //Thread.Sleep(100);
    358350        }
    359351        Console.WriteLine("worker thread: terminating gracefully.");
    360352      }
     353
     354      public void DoWorkFloatingAvg() {
     355        IDataRow row1 = new DataRow {
     356          Color = Color.Red,
     357          Thickness = 2,
     358          Label = "SinusHacked",
     359          Style = DrawingStyle.Solid,
     360          ShowMarkers = false
     361        };
     362        model.AddDataRow(row1);
     363
     364        IDataRow row2 = new DataRow {
     365          Color = Color.Red,
     366          Thickness = 3,
     367          Label = "GrowingHacked",
     368          Style = DrawingStyle.Solid,
     369          ShowMarkers = false
     370        };
     371        model.AddDataRow(row2);
     372
     373        // insert 2 floating avg line aggregators (for each hacked line)
     374
     375        // test floating avg aggregator without visible watcher line
     376
     377        double i = 0;
     378        Random rnd = new Random();
     379
     380        while (!_shouldStop && i <= 240) {
     381          i += 0.2;
     382          double newY = Math.Sin(i);
     383
     384          double hack = rnd.NextDouble() * i / 10;
     385          row1.AddValue(newY * 10 + hack);
     386
     387          hack = rnd.NextDouble() * i / 10;
     388          row2.AddValue(i * 2 - 15 + hack);
     389          //Thread.Sleep(100);
     390        }
     391        Console.WriteLine("worker thread: terminating gracefully.");
     392      }
     393
    361394      public void RequestStop() {
    362395        _shouldStop = true;
    363396      }
     397
    364398      // Volatile is used as hint to the compiler that this data
    365399      // member will be accessed by multiple threads.
     
    386420    public void TestAggregatorSingleLine() {
    387421      LineChartTestForm f = new LineChartTestForm(model);
    388    
     422      model.Title = "SingleLineAggregator Tests";
     423
    389424      // Create the thread object. This does not start the thread.
    390425      Worker workerObject = new Worker(model);
     
    397432      workerObject.RequestStop();
    398433    }
     434
    399435    [Test]
    400436    public void TestAggregatorAvgLine() {
    401437      LineChartTestForm f = new LineChartTestForm(model);
     438      model.Title = "AvgLineTest";
    402439
    403440      // Create the thread object. This does not start the thread.
     
    412449    }
    413450
    414    
     451    [Test]
     452    public void TestFloatingAvg() {
     453      LineChartTestForm f = new LineChartTestForm(model);
     454      model.Title = "FloatingAvg Test";
     455      model.ViewSettings.LegendPosition = Legend.LegendPosition.Top;
     456
     457      // Create the thread object. This does not start the thread.
     458      Worker workerObject = new Worker(model);
     459      Thread workerThread = new Thread(workerObject.DoWorkFloatingAvg);
     460
     461      // Start the worker thread.
     462      workerThread.Start();
     463
     464      f.ShowDialog();
     465      workerObject.RequestStop();
     466    }
     467
    415468
    416469    [Test]
    417470    public void TestAutoZoomInConstructor() {
    418       IDataRow row1 = new DataRow();
    419 
    420       row1.Color = Color.Red;
    421       row1.Thickness = 3;
    422       row1.Style = DrawingStyle.Solid;
     471      IDataRow row1 = new DataRow { Color = Color.Red, Thickness = 3, Style = DrawingStyle.Solid };
    423472
    424473      model.AddDataRow(row1);
     
    485534
    486535      row2.AddValue(5);
    487      
     536
    488537
    489538      row3.AddValue(2);
Note: See TracChangeset for help on using the changeset viewer.